Example #1
0
        public override FutureResponse AsyncRequest(Command command)
        {
            if (command.IsCONNECT)
            {
                command.CommandId = (short)1;
            }
            else
            {
                command.CommandId = GetNextCommandId();
            }
            command.ResponseRequired = true;
            FutureResponse future     = new FutureResponse();
            Exception      priorError = null;

            lock (requestMap.SyncRoot)
            {
                priorError = this.error;
                if (priorError == null)
                {
                    requestMap[command.CommandId] = future;
                }
            }

            if (priorError != null)
            {
                ErrorResponse response = new ErrorResponse();
                response.Error  = priorError;
                future.Response = response;
                return(future);
            }

            next.Oneway(command);

            return(future);
        }
Example #2
0
        public override Response Request(Command command, TimeSpan timeout)
        {
            FutureResponse future = AsyncRequest(command);

            future.ResponseTimeout = timeout;
            Response response = future.Response;

            return(response);
        }
Example #3
0
        protected override void OnCommand(ITransport sender, Command command)
        {
            if (command.IsResponse)
            {
                Response       response      = (Response)command;
                short          correlationId = response.CorrelationId;
                FutureResponse future        = (FutureResponse)requestMap[correlationId];

                if (future != null)
                {
                    requestMap.Remove(correlationId);
                    future.Response = response;
                }
                else
                {
                    Tracer.DebugFormat("Unknown response ID: {0} for response: {1}",
                                       response.CorrelationId, response);
                }
            }
            else
            {
                this.commandHandler(sender, command);
            }
        }