public void SendResponse(Response response, Exchange exchange)
        {
            MockQueueItem item = new MockQueueItem(MockQueueItem.QueueType.ServerSendResponse, response, exchange);

            Queue.Enqueue(item);
            response.Session = exchange.Request.Session;
        }
Example #2
0
        void IOutbox.SendResponse(Exchange exchange, Response response)
        {
            if (response.Type == MessageType.Unknown)
            {
                response.Type = MessageType.ACK;
            }

            if (response.Token == null)
            {
                response.Token = exchange.CurrentRequest.Token;
            }

            if (response.ID == -1)
            {
                response.ID = exchange.CurrentRequest.ID;
            }

            response.Source = MyAddress;

            Matcher.SendResponse(exchange, response);

            MockQueueItem item = new MockQueueItem(MockQueueItem.QueueType.ServerSendResponseNetwork, response);

            Pump.Queue.Enqueue(item);
        }
        public void SendRequest(Request request)
        {
            request.EndPoint = ClientEndpoint;
            MockQueueItem item = new MockQueueItem(MockQueueItem.QueueType.ClientSendRequest, request);

            Queue.Enqueue(item);
        }
Example #4
0
        public void ReceiveData(MockQueueItem item)
        {
            IMessageDecoder decoder = Spec.NewMessageDecoder(item.ItemData);

            if (decoder.IsRequest)
            {
                Request request = decoder.DecodeRequest();

                request.Source      = item.Source;
                request.Destination = item.Destination;

                Exchange exchange = Matcher.ReceiveRequest(request);
                exchange.EndPoint = this;

                request.Session = Session;

                Stack.ReceiveRequest(exchange, request);
            }
            else if (decoder.IsResponse)
            {
                Response response = decoder.DecodeResponse();

                response.Source  = item.Source;
                response.Session = Session;
                Exchange exchange = Matcher.ReceiveResponse(response);
                if (exchange != null)
                {
                    exchange.EndPoint = this;
                    Stack.ReceiveResponse(exchange, response);
                }
            }
        }
Example #5
0
        void IOutbox.SendRequest(Exchange exchange, Request request)
        {
            Matcher.SendRequest(exchange, request);
            request.Session = Session;

            MockQueueItem item = new MockQueueItem(MockQueueItem.QueueType.ClientSendRequestNetwork, request);

            Pump.Queue.Enqueue(item);
        }
Example #6
0
        public void SendResponse(Exchange exchange, Response response)
        {
            if (response.Type == MessageType.Unknown)
            {
                response.Type = MessageType.ACK;
            }

            response.Session     = exchange.Request.Session;
            response.Destination = exchange.Request.Source;
            response.Source      = MyAddress;
            MockQueueItem item = new MockQueueItem(MockQueueItem.QueueType.ServerSendResponse, response, exchange);

            item.Source = MyAddress;
            Pump.Queue.Enqueue(item);
        }
        public bool Pump()
        {
            List <MockStack> serverStacks;

            if (Queue.Count == 0)
            {
                return(false);
            }

            MockQueueItem item = Queue.Peek();

            switch (item.ItemType)
            {
            //  state #1 - client requested a send of a request
            case MockQueueItem.QueueType.ClientSendRequest:
                Queue.Dequeue();
                if (item.Request.Destination == null)
                {
                    item.Request.Destination = ServerAddress;
                }
                ClientStack.SendRequest(item.Request);
                break;

            //  state #2 - client ready for network send
            case MockQueueItem.QueueType.ClientSendRequestNetwork:
                Queue.Dequeue();
                MessageEncoder encoder        = new Spec.MessageEncoder18();
                byte[]         encodedRequest = encoder.Encode(item.Request);
                EndPoint       destination    = item.Request.Destination;

                item             = new MockQueueItem(MockQueueItem.QueueType.ServerSendRequestNetwork, encodedRequest);
                item.Source      = ClientAddress;
                item.Destination = destination;
                Queue.Enqueue(item);
                break;

            //  state #3 - server receives network send
            case MockQueueItem.QueueType.ServerSendRequestNetwork:
                Queue.Dequeue();
                serverStacks = ServerStacks[item.Destination];
                foreach (MockStack s in serverStacks)
                {
                    s.MyEndPoint.ReceiveData(item);
                }

                break;

            //  state #4 - server application receives request
            case MockQueueItem.QueueType.ServerSendRequest:
                break;


            // state #5 - server sends an response
            case MockQueueItem.QueueType.ServerSendResponse:
                Queue.Dequeue();
                serverStacks = ServerStacks[item.Source];
                Assert.AreEqual(1, serverStacks.Count);
                foreach (MockStack s in serverStacks)
                {
                    s.SendResponse(item.Exchange, item.Response);
                }
                break;

            // state #6 - server ready to send over network
            case MockQueueItem.QueueType.ServerSendResponseNetwork:
                Queue.Dequeue();
                encoder = new Spec.MessageEncoder18();
                byte[] encodedResponse = encoder.Encode(item.Response);

                MockQueueItem item2 = new MockQueueItem(MockQueueItem.QueueType.ClientSendResponseNetwork, encodedResponse);
                item2.Source      = item.Response.Source;
                item2.Destination = item.Destination;
                Queue.Enqueue(item2);
                break;

            // state #7 - client receives response over network
            case MockQueueItem.QueueType.ClientSendResponseNetwork:
                Queue.Dequeue();

                ClientEndpoint.ReceiveData(item);

                break;

            // state #8 - client application to process response
            case MockQueueItem.QueueType.ClientSendResponse:
                break;
            }

            return(Queue.Count > 0);
        }
Example #8
0
        /// <inheritdoc />
        public void DeliverResponse(Exchange exchange, Response response)
        {
            MockQueueItem item = new MockQueueItem(MockQueueItem.QueueType.ClientSendResponse, response, exchange);

            Pump.Queue.Enqueue(item);
        }
Example #9
0
        /// <inheritdoc />
        public void DeliverRequest(Exchange exchange)
        {
            MockQueueItem item = new MockQueueItem(MockQueueItem.QueueType.ServerSendRequest, exchange.Request, exchange);

            Pump.Queue.Enqueue(item);
        }