Ejemplo n.º 1
0
        private async void DispatchRequest(InMemFrame payload,
                                           InMemFrameQueue queue)
        {
            var requestMetrics = Metrics.StartRequestMetrics(connection.ConnectionMetrics);
            var receiveContext = new SimpleInMemReceiveContext(connection, connection.ConnectionMetrics, requestMetrics);
            var headers        = payload.headers;
            var layerData      = payload.layerData;
            var message        = payload.message;
            var taskSource     = payload.outstandingRequest;

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

            if (layerError == null)
            {
                layerError = LayerStackUtils.ProcessOnReceive(layerStack, MessageType.REQUEST, receiveContext, layerData, logger);
            }

            IMessage response;

            if (layerError == null)
            {
                response = await serviceHost.DispatchRequest(headers.service_name, headers.method_name, receiveContext, message);
            }
            else
            {
                logger.Site().Error("Receiving request {0}/{1}.{2} failed due to layer error (Code: {3}, Message: {4}).",
                                    headers.conversation_id, headers.service_name, headers.method_name, layerError.error_code, layerError.message);

                // Set layer error as result of this Bond method call and do not dispatch to method.
                // Since this error will be returned to client, cleanse out internal server error details, if any.
                response = Message.FromError(Errors.CleanseInternalServerError(layerError));
            }
            SendReply(headers.conversation_id, response, taskSource, layerStack, queue);
        }
Ejemplo n.º 2
0
        private async void DispatchRequest(InMemFrame payload,
                                           InMemFrameQueue queue)
        {
            var receiveContext = new SimpleInMemReceiveContext(connection);
            var headers = payload.headers;
            var layerData = payload.layerData;
            var message = payload.message;
            var taskSource = payload.outstandingRequest;

            ILayerStack layerStack;
            Error layerError = this.serviceHost.ParentTransport.GetLayerStack(out layerStack);

            if (layerError == null)
            {
                layerError = LayerStackUtils.ProcessOnReceive(layerStack, MessageType.Request, receiveContext, layerData, logger);
            }

            IMessage response;

            if (layerError == null)
            {
                response = await serviceHost.DispatchRequest(headers.method_name, receiveContext, message, connection.ConnectionMetrics);
            }
            else
            {
                logger.Site().Error("Receiving request {0}/{1} failed due to layer error (Code: {2}, Message: {3}).",
                                 headers.conversation_id, headers.method_name, layerError.error_code, layerError.message);

                // Set layer error as result of this Bond method call and do not dispatch to method.
                // Since this error will be returned to client, cleanse out internal server error details, if any.
                response = Message.FromError(Errors.CleanseInternalServerError(layerError));
            }
            SendReply(headers.conversation_id, response, taskSource, layerStack, queue);
        }
Ejemplo n.º 3
0
        private async void DispatchEvent(InMemFrame payload)
        {
            var requestMetrics = Metrics.StartRequestMetrics(connection.ConnectionMetrics);
            var receiveContext = new SimpleInMemReceiveContext(connection, connection.ConnectionMetrics, requestMetrics);
            var headers        = payload.headers;
            var layerData      = payload.layerData;
            var message        = payload.message;

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

            if (layerError == null)
            {
                layerError = LayerStackUtils.ProcessOnReceive(layerStack, MessageType.EVENT, receiveContext, layerData, logger);
            }

            if (layerError != null)
            {
                logger.Site().Error("Receiving event {0}/{1}.{2} failed due to layer error (Code: {3}, Message: {4}).",
                                    headers.conversation_id, headers.service_name, headers.method_name, layerError.error_code, layerError.message);
                return;
            }

            await serviceHost.DispatchEvent(headers.service_name, headers.method_name, receiveContext, message);
        }
Ejemplo n.º 4
0
        internal void Enqueue(InMemFrame frame)
        {
            Util.Validate(frame);

            lock (qLock)
            {
                queue.Enqueue(frame);
            }
        }
Ejemplo n.º 5
0
        internal void Enqueue(InMemFrame frame)
        {
            Util.Validate(frame);

            lock (qLock)
            {
                queue.Enqueue(frame);
            }
        }
Ejemplo n.º 6
0
        internal InMemFrame Dequeue()
        {
            InMemFrame frame = null;

            lock (qLock)
            {
                if (queue.Count > 0)
                {
                    frame = queue.Dequeue();
                }
            }

            return(frame);
        }
Ejemplo n.º 7
0
        internal static InMemFrame Validate(InMemFrame frame)
        {
            if (frame == null)
            {
                throw new SimpleInMemProtocolErrorException($"null {nameof(frame)}");
            }
            else if (frame.headers == null)
            {
                throw new SimpleInMemProtocolErrorException($"null {nameof(frame.headers)} in frame");
            }
            else if (frame.message == null)
            {
                throw new SimpleInMemProtocolErrorException($"null {nameof(frame.message)} in frame");
            }

            return(frame);
        }
Ejemplo n.º 8
0
        internal static InMemFrame Validate(InMemFrame frame)
        {
            if (frame == null)
            {
                throw new SimpleInMemProtocolErrorException($"null {nameof(frame)}");
            }
            else if (frame.headers == null)
            {
                throw new SimpleInMemProtocolErrorException($"null {nameof(frame.headers)} in frame");
            }
            else if (frame.message == null)
            {
                throw new SimpleInMemProtocolErrorException($"null {nameof(frame.message)} in frame");
            }

            return frame;
        }
Ejemplo n.º 9
0
        internal static InMemFrame NewPayLoad(ulong conversationId, PayloadType payloadType, IBonded layerData,
                                              IMessage message, TaskCompletionSource <IMessage> taskSource)
        {
            var headers = new SimpleInMemHeaders
            {
                conversation_id = conversationId,
                payload_type    = payloadType
            };

            var payload = new InMemFrame
            {
                headers            = headers,
                layerData          = layerData,
                message            = message,
                outstandingRequest = taskSource
            };

            Validate(payload);
            return(payload);
        }
Ejemplo n.º 10
0
Archivo: Util.cs Proyecto: xornand/bond
        internal static InMemFrame NewPayLoad(ulong conversationId, PayloadType payloadType, IBonded layerData,
                                                IMessage message, TaskCompletionSource<IMessage> taskSource)
        {
            var headers = new SimpleInMemHeaders
            {
                conversation_id = conversationId,
                payload_type = payloadType
            };

            var payload = new InMemFrame
            {
                headers = headers,
                layerData = layerData,
                message = message,
                outstandingRequest = taskSource
            };

            Validate(payload);
            return payload;
        }
Ejemplo n.º 11
0
        private void DispatchResponse(InMemFrame payload)
        {
            var receiveContext = new SimpleInMemReceiveContext(connection);
            var headers        = payload.headers;
            var layerData      = payload.layerData;
            var message        = payload.message;
            var taskSource     = payload.outstandingRequest;

            ILayerStack layerStack = taskSource.Task.AsyncState as ILayerStack;

            Error layerError = LayerStackUtils.ProcessOnReceive(layerStack, MessageType.Response, receiveContext, layerData, logger);

            if (layerError != null)
            {
                logger.Site().Error("Receiving response {0}/{1} failed due to layer error (Code: {2}, Message: {3}).",
                                    headers.conversation_id, headers.method_name, layerError.error_code, layerError.message);
                message = Message.FromError(layerError);
            }

            payload.outstandingRequest.SetResult(message);
        }
Ejemplo n.º 12
0
        private async void DispatchEvent(InMemFrame payload)
        {
            var receiveContext = new SimpleInMemReceiveContext(connection);
            var headers = payload.headers;
            var layerData = payload.layerData;
            var message = payload.message;

            ILayerStack layerStack;
            Error layerError = serviceHost.ParentTransport.GetLayerStack(out layerStack);

            if (layerError == null)
            {
                layerError = LayerStackUtils.ProcessOnReceive(layerStack, MessageType.Event, receiveContext, layerData, logger);
            }

            if (layerError != null)
            {
                logger.Site().Error("Receiving event {0}/{1} failed due to layer error (Code: {2}, Message: {3}).",
                                 headers.conversation_id, headers.method_name, layerError.error_code, layerError.message);
                return;
            }

            await serviceHost.DispatchEvent(
                    headers.method_name, receiveContext, message, connection.ConnectionMetrics);
        }
Ejemplo n.º 13
0
        private void DispatchResponse(InMemFrame payload)
        {
            var receiveContext = new SimpleInMemReceiveContext(connection);
            var headers = payload.headers;
            var layerData = payload.layerData;
            var message = payload.message;
            var taskSource = payload.outstandingRequest;

            ILayerStack layerStack = taskSource.Task.AsyncState as ILayerStack;

            Error layerError = LayerStackUtils.ProcessOnReceive(layerStack, MessageType.Response, receiveContext, layerData, logger);

            if (layerError != null)
            {
                logger.Site().Error("Receiving response {0}/{1} failed due to layer error (Code: {2}, Message: {3}).",
                                 headers.conversation_id, headers.method_name, layerError.error_code, layerError.message);
                message = Message.FromError(layerError);
            }

            payload.outstandingRequest.SetResult(message);
        }