Ejemplo n.º 1
0
        private void SendEventAsync(string methodName, IMessage message)
        {
            var requestMetrics = Metrics.StartRequestMetrics(ConnectionMetrics);
            var conversationId = AllocateNextConversationId();

            var         sendContext = new SimpleInMemSendContext(this, ConnectionMetrics, requestMetrics);
            IBonded     layerData   = null;
            ILayerStack layerStack;
            Error       layerError = transport.GetLayerStack(requestMetrics.request_id, out layerStack);

            if (layerError == null)
            {
                layerError = LayerStackUtils.ProcessOnSend(layerStack, MessageType.Event, sendContext, out layerData, logger);
            }

            if (layerError != null)
            {
                logger.Site().Error("{0}: Sending event {1}/{2} failed due to layer error (Code: {3}, Message: {4}).",
                                    this, conversationId, methodName, layerError.error_code, layerError.message);
                return;
            }

            var payload = Util.NewPayLoad(conversationId, PayloadType.Event, layerData, message, null);

            payload.headers.method_name = methodName;
            writeQueue.Enqueue(payload);
        }
Ejemplo n.º 2
0
        private Task <IMessage> SendRequestAsync(string methodName, IMessage request)
        {
            var requestMetrics = Metrics.StartRequestMetrics(ConnectionMetrics);
            var conversationId = AllocateNextConversationId();

            var sendContext = new SimpleInMemSendContext(this, ConnectionMetrics, requestMetrics);

            IBonded     layerData = null;
            ILayerStack layerStack;
            Error       layerError = transport.GetLayerStack(requestMetrics.request_id, out layerStack);

            if (layerError == null)
            {
                layerError = LayerStackUtils.ProcessOnSend(layerStack, MessageType.Request, sendContext, out layerData, logger);
            }

            if (layerError != null)
            {
                logger.Site().Error("{0}: Sending request {1}/{2} failed due to layer error (Code: {3}, Message: {4}).",
                                    this, conversationId, methodName, layerError.error_code, layerError.message);
                return(Task.FromResult <IMessage>(Message.FromError(layerError)));
            }

            // Pass the layer stack instance as state in response task completion source.
            var responseCompletionSource = new TaskCompletionSource <IMessage>(layerStack);
            var payload = Util.NewPayLoad(conversationId, PayloadType.Request, layerData, request, responseCompletionSource);

            payload.headers.method_name = methodName;
            writeQueue.Enqueue(payload);

            return(payload.outstandingRequest.Task);
        }