예제 #1
0
        public DisquuunInput Qscan(params object[] args)
        {
            var bytes = DisquuunAPI.Qscan(args);

            var socket = ChooseAvailableSocket();

            return(new DisquuunInput(DisqueCommand.QSCAN, bytes, socket));
        }
예제 #2
0
        public DisquuunInput Jscan(int cursor = 0, params object[] args)
        {
            var bytes = DisquuunAPI.Jscan(cursor, args);

            var socket = ChooseAvailableSocket();

            return(new DisquuunInput(DisqueCommand.JSCAN, bytes, socket));
        }
예제 #3
0
        public DisquuunInput DelJob(params string[] jobIds)
        {
            var bytes = DisquuunAPI.DelJob(jobIds);

            var socket = ChooseAvailableSocket();

            return(new DisquuunInput(DisqueCommand.DELJOB, bytes, socket));
        }
예제 #4
0
        public DisquuunInput Show(string jobId)
        {
            var bytes = DisquuunAPI.Show(jobId);

            var socket = ChooseAvailableSocket();

            return(new DisquuunInput(DisqueCommand.SHOW, bytes, socket));
        }
예제 #5
0
        public DisquuunInput Qpeek(string queueId, int count)
        {
            var bytes = DisquuunAPI.Qpeek(queueId, count);

            var socket = ChooseAvailableSocket();

            return(new DisquuunInput(DisqueCommand.QPEEK, bytes, socket));
        }
예제 #6
0
        public DisquuunInput Enqueue(params string[] jobIds)
        {
            var bytes = DisquuunAPI.Enqueue(jobIds);

            var socket = ChooseAvailableSocket();

            return(new DisquuunInput(DisqueCommand.ENQUEUE, bytes, socket));
        }
예제 #7
0
        public DisquuunInput Hello()
        {
            var bytes = DisquuunAPI.Hello();

            var socket = ChooseAvailableSocket();

            return(new DisquuunInput(DisqueCommand.HELLO, bytes, socket));
        }
예제 #8
0
        public DisquuunInput Qstat(string queueId)
        {
            var bytes = DisquuunAPI.Qstat(queueId);

            var socket = ChooseAvailableSocket();

            return(new DisquuunInput(DisqueCommand.QSTAT, bytes, socket));
        }
예제 #9
0
        public DisquuunInput Nack(string[] jobIds)
        {
            var bytes = DisquuunAPI.Nack(jobIds);

            var socket = ChooseAvailableSocket();

            return(new DisquuunInput(DisqueCommand.NACK, bytes, socket));
        }
예제 #10
0
        public DisquuunInput Info()
        {
            var data = DisquuunAPI.Info();

            var socket = ChooseAvailableSocket();

            return(new DisquuunInput(DisqueCommand.INFO, data, socket));
        }
예제 #11
0
        public DisquuunInput Working(string jobId)
        {
            var bytes = DisquuunAPI.Working(jobId);

            var socket = ChooseAvailableSocket();

            return(new DisquuunInput(DisqueCommand.WORKING, bytes, socket));
        }
예제 #12
0
        public DisquuunInput AckJob(string[] jobIds)
        {
            var bytes = DisquuunAPI.AckJob(jobIds);

            var socket = ChooseAvailableSocket();

            return(new DisquuunInput(DisqueCommand.ACKJOB, bytes, socket));
        }
예제 #13
0
        public DisquuunInput GetJob(string[] queueIds, params object[] args)
        {
            var bytes = DisquuunAPI.GetJob(queueIds, args);

            var socket = ChooseAvailableSocket();

            return(new DisquuunInput(DisqueCommand.GETJOB, bytes, socket));
        }
예제 #14
0
        /*
         *      Disque API gateway
         */
        public DisquuunInput AddJob(string queueName, byte[] data, int timeout = 0, params object[] args)
        {
            var bytes = DisquuunAPI.AddJob(queueName, data, timeout, args);

            var socket = ChooseAvailableSocket();

            return(new DisquuunInput(DisqueCommand.ADDJOB, bytes, socket));
        }
예제 #15
0
        public DisquuunInput Pause(string queueId, string option1, params string[] options)
        {
            var bytes = DisquuunAPI.Pause(queueId, option1, options);

            var socket = ChooseAvailableSocket();

            return(new DisquuunInput(DisqueCommand.PAUSE, bytes, socket));
        }
예제 #16
0
        /*
         *              Core methods of Disquuun.
         */

        /**
         *              method for Sync execution of specific Disque command.
         *              DEPRECATED. only use for testing.
         */
        public override DisquuunResult[] DEPRECATED_Sync(DisqueCommand command, byte[] data)
        {
#if LOGIC_BENCH
            {
                socketToken.socketState = SocketState.OPENED;
                return(new DisquuunResult[0]);
            }
#endif
            try
            {
                socketToken.socket.Send(data);

                var currentLength = 0;
                var scanResult    = new DisquuunAPI.ScanResult(false);

                while (true)
                {
                    // waiting for head of transferring data or rest of data.
                    socketToken.socket.Receive(socketToken.receiveBuffer, currentLength, 1, SocketFlags.None);
                    currentLength = currentLength + 1;

                    var available      = socketToken.socket.Available;
                    var readableLength = currentLength + available;
                    {
                        if (socketToken.receiveBuffer.Length < readableLength)
                        {
                            Array.Resize(ref socketToken.receiveBuffer, readableLength);
                        }
                    }

                    // read rest.
                    socketToken.socket.Receive(socketToken.receiveBuffer, currentLength, available, SocketFlags.None);
                    currentLength = currentLength + available;

                    scanResult = DisquuunAPI.ScanBuffer(command, socketToken.receiveBuffer, 0, currentLength, socketId);
                    if (scanResult.isDone)
                    {
                        break;
                    }

                    // continue reading data from socket.
                    // if need, prepare for next 1 byte.
                    if (socketToken.receiveBuffer.Length == readableLength)
                    {
                        Array.Resize(ref socketToken.receiveBuffer, socketToken.receiveBuffer.Length + 1);
                    }
                }

                socketToken.socketState = SocketState.OPENED;
                return(scanResult.data);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
예제 #17
0
        private void LoopOrAsyncReceive(SocketToken token)
        {
            var currentCommand = token.currentCommands.Peek();
            var result         = DisquuunAPI.ScanBuffer(currentCommand, token.receiveBuffer, 0, token.readableDataLength, socketId);

            if (result.isDone && result.cursor == token.readableDataLength)
            {
                // update continuation status.
                token.continuation = token.AsyncCallback(currentCommand, result.data);

                if (token.continuation)
                {
                    switch (token.socketState)
                    {
                    case SocketState.BUSY: {
                        token.socketState = SocketState.RECEIVED;
                        break;
                    }

                    case SocketState.SENDED: {
                        // ready for next loop receive.
                        token.readableDataLength = 0;
                        token.receiveArgs.SetBuffer(token.receiveBuffer, 0, token.receiveBuffer.Length);
                        if (!token.socket.ReceiveAsync(token.receiveArgs))
                        {
                            OnReceived(token.socket, token.receiveArgs);
                        }

                        try {
                            token.sendArgs.SetBuffer(token.currentSendingBytes, 0, token.currentSendingBytes.Length);
                        } catch {
                            // renew. potential error is exists and should avoid this error.
                            var sendArgs = new SocketAsyncEventArgs();
                            sendArgs.RemoteEndPoint = token.receiveArgs.RemoteEndPoint;
                            sendArgs.Completed     += new EventHandler <SocketAsyncEventArgs>(OnSend);
                            sendArgs.UserToken      = token;
                            token.sendArgs          = sendArgs;
                            token.sendArgs.SetBuffer(token.currentSendingBytes, 0, token.currentSendingBytes.Length);
                        }

                        if (!token.socket.SendAsync(token.sendArgs))
                        {
                            OnSend(token.socket, token.sendArgs);
                        }

                        break;
                    }

                    default: {
                        // closing or other state. should close.
                        break;
                    }
                    }
                    return;
                }

                // end of loop or end of async.

                switch (token.socketState)
                {
                case SocketState.BUSY: {
                    token.socketState = SocketState.RECEIVED;
                    break;
                }

                case SocketState.SENDED: {
                    token.socketState = SocketState.OPENED;
                    SocketReloaded(this);
                    break;
                }

                default: {
                    break;
                }
                }
                return;
            }

            // not yet received all data.
            // continue receiving.

            StartContinueReceiving(token, token.readableDataLength);
        }
예제 #18
0
        public DisquuunInput Pause(string queueId, string option1, params string[] options)
        {
            var bytes = DisquuunAPI.Pause(queueId, option1, options);

            return(new DisquuunInput(DisqueCommand.PAUSE, bytes, socketPool));
        }
예제 #19
0
        private void PipelineReceive(SocketToken token)
        {
            var fromCursor = 0;

            /*
             *      read data from receiveBuffer by moving fromCursor.
             */
            while (true)
            {
                var currentCommand = token.currentCommands.Peek();
                var result         = DisquuunAPI.ScanBuffer(currentCommand, token.receiveBuffer, fromCursor, token.readableDataLength, socketId);

                if (result.isDone)
                {
                    token.AsyncCallback(currentCommand, result.data);

                    // deque as read done.
                    token.currentCommands.Dequeue();

                    if (token.currentCommands.Count == 0)
                    {
                        // pipelining is over.
                        switch (token.socketState)
                        {
                        case SocketState.BUSY: {
                            token.socketState = SocketState.RECEIVED;
                            break;
                        }

                        case SocketState.SENDED: {
                            token.socketState = SocketState.OPENED;
                            SocketReloaded(this);
                            break;
                        }

                        default: {
                            break;
                        }
                        }
                        return;
                    }

                    // commands are still remained.

                    // got all data is just consumed. get rest from outside.
                    if (fromCursor == token.readableDataLength)
                    {
                        StartContinueReceiving(token, 0);
                        return;
                    }

                    // rest pipeline commands and received data is exists in buffer.
                    fromCursor = result.cursor;
                    continue;
                }

                /*
                 *      reading is not completed. the fragment of command exists.
                 */

                var fragmentDataLength = token.readableDataLength - fromCursor;

                // move fragment data to head of buffer.
                Buffer.BlockCopy(token.receiveBuffer, fromCursor, token.receiveBuffer, 0, fragmentDataLength);

                StartContinueReceiving(token, fragmentDataLength);
                break;
            }
        }
예제 #20
0
        public DisquuunInput Qscan(params object[] args)
        {
            var bytes = DisquuunAPI.Qscan(args);

            return(new DisquuunInput(DisqueCommand.QSCAN, bytes, socketPool));
        }
예제 #21
0
        public DisquuunInput Jscan(int cursor = 0, params object[] args)
        {
            var bytes = DisquuunAPI.Jscan(cursor, args);

            return(new DisquuunInput(DisqueCommand.JSCAN, bytes, socketPool));
        }
예제 #22
0
        public DisquuunInput DelJob(params string[] jobIds)
        {
            var bytes = DisquuunAPI.DelJob(jobIds);

            return(new DisquuunInput(DisqueCommand.DELJOB, bytes, socketPool));
        }
예제 #23
0
        public DisquuunInput Show(string jobId)
        {
            var bytes = DisquuunAPI.Show(jobId);

            return(new DisquuunInput(DisqueCommand.SHOW, bytes, socketPool));
        }
예제 #24
0
        public DisquuunInput Qpeek(string queueId, int count)
        {
            var bytes = DisquuunAPI.Qpeek(queueId, count);

            return(new DisquuunInput(DisqueCommand.QPEEK, bytes, socketPool));
        }
예제 #25
0
        public DisquuunInput Dequeue(params string[] jobIds)
        {
            var bytes = DisquuunAPI.Dequeue(jobIds);

            return(new DisquuunInput(DisqueCommand.DEQUEUE, bytes, socketPool));
        }
예제 #26
0
        public DisquuunInput Qstat(string queueId)
        {
            var bytes = DisquuunAPI.Qstat(queueId);

            return(new DisquuunInput(DisqueCommand.QSTAT, bytes, socketPool));
        }
예제 #27
0
        public DisquuunInput Qlen(string queueId)
        {
            var bytes = DisquuunAPI.Qlen(queueId);

            return(new DisquuunInput(DisqueCommand.QLEN, bytes, socketPool));
        }
예제 #28
0
        public DisquuunInput Hello()
        {
            var bytes = DisquuunAPI.Hello();

            return(new DisquuunInput(DisqueCommand.HELLO, bytes, socketPool));
        }
예제 #29
0
        public DisquuunInput Info()
        {
            var data = DisquuunAPI.Info();

            return(new DisquuunInput(DisqueCommand.INFO, data, socketPool));
        }
예제 #30
0
        public DisquuunInput Nack(string[] jobIds)
        {
            var bytes = DisquuunAPI.Nack(jobIds);

            return(new DisquuunInput(DisqueCommand.NACK, bytes, socketPool));
        }