public static void LoadLibrary(LuaInstance lua)
        {
            LuaTable table = new LuaTable();
            table["log"] = new Action<int, string>(log);

            lua.Register("aero", table);
        }
 public static void PutInstance(LuaInstance instance)
 {
     if (!InstanceQueue.TryAdd(instance))
     {
         instance.Close();
     }
 }
        public void Run(object obj)
        {
#if NETFRAMEWORK
            LuaInstance lua = null;

            try
            {
                lua = LuaCache.GetInstance();

                // Start thread queries to each node.
                StartThreads();

                lua.LoadPackage(statement);

                object[] args = new object[4 + statement.functionArgs.Length];
                args[0] = lua.GetFunction(statement.functionName);
                args[1] = 2;
                args[2] = new LuaInputStream(inputQueue, cancel.Token);
                args[3] = new LuaOutputStream(resultSet);
                int count = 4;

                foreach (Value value in statement.functionArgs)
                {
                    args[count++] = value.Object;
                }
                lua.Call("apply_stream", args);
            }
            catch (Neo.IronLua.LuaRuntimeException lre)
            {
                // Try to get that elusive lua stack trace.
                HandleException(new Exception(lre.Message + lre.StackTrace));
            }
            catch (Exception e)
            {
                if (e.InnerException is Neo.IronLua.LuaRuntimeException)
                {
                    // Try to get that elusive lua stack trace.
                    Neo.IronLua.LuaRuntimeException lre = e.InnerException as Neo.IronLua.LuaRuntimeException;
                    HandleException(new Exception(lre.Message + lre.StackTrace));
                }
                else
                {
                    HandleException(e);
                }
            }
            finally
            {
                // Send end command to user's result set.
                // If query was already cancelled, this put will be ignored.
                resultSet.Put(ResultSet.END);

                if (lua != null)
                {
                    LuaCache.PutInstance(lua);
                }
            }
#else
            HandleException(new AerospikeException("Lua not supported in .NET core"));
#endif
        }
 public static void PutInstance(LuaInstance instance)
 {
     if (!InstanceQueue.TryAdd(instance))
     {
         instance.Close();
     }
 }
Example #5
0
        public static void LoadLibrary(LuaInstance lua)
        {
            LuaTable table = new LuaTable();

            table["log"] = new Action <int, string>(log);

            lua.Register("aero", table);
        }
        public object LuaToObject()
        {
            List <object> target = new List <object>(list.Count);

            foreach (object value in list)
            {
                object obj = LuaInstance.LuaToObject(value);
                target.Add(obj);
            }
            return(target);
        }
Example #7
0
        public static void LoadLibrary(LuaInstance lua)
        {
            LuaTable table = new LuaTable();

            table["read"]      = new Func <LuaStream, object>(read);
            table["write"]     = new Action <LuaStream, object>(write);
            table["readable"]  = new Func <LuaStream, bool>(readable);
            table["writeable"] = new Func <LuaStream, bool>(writeable);

            lua.Register("stream", table);
        }
        public object LuaToObject()
        {
            Dictionary <object, object> target = new Dictionary <object, object>(map.Count);

            foreach (KeyValuePair <object, object> entry in map)
            {
                object key   = LuaInstance.LuaToObject(entry.Key);
                object value = LuaInstance.LuaToObject(entry.Value);
                target[key] = value;
            }
            return(target);
        }
Example #9
0
        protected internal override void ParseRow(Key key)
        {
#if NETFRAMEWORK
            if (opCount != 1)
            {
                throw new AerospikeException("Query aggregate expected exactly one bin.  Received " + opCount);
            }

            // Parse aggregateValue.
            int opSize = ByteUtil.BytesToInt(dataBuffer, dataOffset);
            dataOffset += 5;
            byte particleType = dataBuffer[dataOffset];
            dataOffset += 2;
            byte   nameSize = dataBuffer[dataOffset++];
            string name     = ByteUtil.Utf8ToString(dataBuffer, dataOffset, nameSize);
            dataOffset += nameSize;

            int particleBytesSize = (int)(opSize - (4 + nameSize));

            if (!name.Equals("SUCCESS"))
            {
                if (name.Equals("FAILURE"))
                {
                    object value = ByteUtil.BytesToParticle(particleType, dataBuffer, dataOffset, particleBytesSize);
                    throw new AerospikeException(ResultCode.QUERY_GENERIC, value.ToString());
                }
                else
                {
                    throw new AerospikeException(ResultCode.PARSE_ERROR, "Query aggregate expected bin name SUCCESS.  Received " + name);
                }
            }

            object aggregateValue = LuaInstance.BytesToLua(particleType, dataBuffer, dataOffset, particleBytesSize);
            dataOffset += particleBytesSize;

            if (!valid)
            {
                throw new AerospikeException.QueryTerminated();
            }

            if (aggregateValue != null)
            {
                try
                {
                    inputQueue.Add(aggregateValue, cancelToken);
                }
                catch (OperationCanceledException)
                {
                }
            }
#endif
        }
Example #10
0
        public static void PutInstance(LuaInstance instance)
        {
            int count = Interlocked.CompareExchange(ref InstanceCount, 0, 0);

            if (count <= LuaConfig.InstancePoolSize)
            {
                InstanceQueue.Enqueue(instance);
            }
            else
            {
                Interlocked.Decrement(ref InstanceCount);
                instance.Close();
            }
        }
        public static void LoadLibrary(LuaInstance lua)
        {
            LuaTable table = new LuaTable();
            table["read"] = new Func<LuaStream, object>(read);
            table["write"] = new Action<LuaStream, object>(write);
            table["readable"] = new Func<LuaStream, bool>(readable);
            table["writeable"] = new Func<LuaStream, bool>(writeable);

            lua.Register("stream", table);
        }
Example #12
0
        public override void Write(object obj)
        {
            object target = LuaInstance.LuaToObject(obj);

            resultSet.Put(target);
        }
        protected internal override bool ParseRecordResults(int receiveSize)
        {
            // Read/parse remaining message bytes one record at a time.
            dataOffset = 0;

            while (dataOffset < receiveSize)
            {
                ReadBytes(MSG_REMAINING_HEADER_SIZE);
                int resultCode = dataBuffer[5];

                if (resultCode != 0)
                {
                    if (resultCode == ResultCode.KEY_NOT_FOUND_ERROR)
                    {
                        return(false);
                    }
                    throw new AerospikeException(resultCode);
                }

                byte info3 = dataBuffer[3];

                // If this is the end marker of the response, do not proceed further
                if ((info3 & Command.INFO3_LAST) == Command.INFO3_LAST)
                {
                    return(false);
                }

                int fieldCount = ByteUtil.BytesToShort(dataBuffer, 18);
                int opCount    = ByteUtil.BytesToShort(dataBuffer, 20);

                ParseKey(fieldCount);

                if (opCount != 1)
                {
                    throw new AerospikeException("Query aggregate expected exactly one bin.  Received " + opCount);
                }

                // Parse aggregateValue.
                ReadBytes(8);
                int  opSize       = ByteUtil.BytesToInt(dataBuffer, 0);
                byte particleType = dataBuffer[5];
                byte nameSize     = dataBuffer[7];

                ReadBytes(nameSize);
                string name = ByteUtil.Utf8ToString(dataBuffer, 0, nameSize);

                int particleBytesSize = (int)(opSize - (4 + nameSize));
                ReadBytes(particleBytesSize);

                if (!name.Equals("SUCCESS"))
                {
                    if (name.Equals("FAILURE"))
                    {
                        object value = ByteUtil.BytesToParticle(particleType, dataBuffer, 0, particleBytesSize);
                        throw new AerospikeException(ResultCode.QUERY_GENERIC, value.ToString());
                    }
                    else
                    {
                        throw new AerospikeException(ResultCode.QUERY_GENERIC, "Query aggregate expected bin name SUCCESS.  Received " + name);
                    }
                }

                object aggregateValue = LuaInstance.BytesToLua(particleType, dataBuffer, 0, particleBytesSize);

                if (!valid)
                {
                    throw new AerospikeException.QueryTerminated();
                }

                if (aggregateValue != null)
                {
                    try
                    {
                        inputQueue.Add(aggregateValue, cancelToken);
                    }
                    catch (OperationCanceledException)
                    {
                    }
                }
            }
            return(true);
        }