Ejemplo n.º 1
0
 public void ExecuteOneWayOperation(Message msg)
 {
     if (_actorHeader != null)
     {
         msg.AttachHeader(_actorHeader);
     }
     _target.ExecuteOneWayOperation(new OperationContext(msg, null));
 }
Ejemplo n.º 2
0
 public Task <Message> ExecuteOperation(Message msg)
 {
     if (_actorHeader != null)
     {
         msg.AttachHeader(_actorHeader);
     }
     return(_target.ExecuteOperation(new OperationContext(msg, null)));
 }
 public void Reply(IOperationContext context, Message replyMsg)
 {
     if (context.ReplyRequired)
     {
         replyMsg.AttachHeader(new OperationHeader(context.RequestId.Value, OperationType.Reply, context.ActivityId));
         Logger.NetChannelSentReplyMessage(Node, this, replyMsg, context);
         Send(replyMsg);
     }
     else
     {
         Logger.CantReplyToOneWayMessage(Node, context);
     }
 }
        public Task <Message> SendRequestAsync(Message request)
        {
            _requestsMeter.Mark();

            //if operation header is already defined just use it eitherwise attach new one
            var  opHeader  = request.GetHeader <OperationHeader>();
            Guid requestId = Guid.NewGuid();

            if (opHeader == null)
            {
                request.AttachHeader(new OperationHeader(requestId, OperationType.Request, requestId));
            }
            else
            {
                requestId = opHeader.RequestId;
            }

            Logger.NetChannelRequestStarted(Node, this, request, requestId);

            var continuation = new PendingOperation(requestId);

            if (!PendingOperationsByRequestId.TryAdd(requestId, continuation))
            {
                throw new Exception("RequestId GUID is not unique");
            }

            var expiration = Task.Delay(TimeSpan.FromSeconds(_config.SendTimeoutSec), continuation.Expiration.Token);

            expiration.ContinueWith((_) =>
            {
                try
                {
                    PendingOperation dummy;
                    if (PendingOperationsByRequestId.TryRemove(continuation.RequestId, out dummy))
                    {
                        _requestsFailedMeter.Mark();
                        Logger.NetChannelRequestTimedOut(Node, this, request, requestId, _config.SendTimeoutSec * 1000);
                        if (!continuation.TCS.Task.IsCompleted)
                        {
                            continuation.TCS.SetException(new TimeoutException($"SendRequestAsync<{requestId}, {request}> has Expired after {_config.SendTimeoutSec} sec"));
                        }
                    }
                }
                catch {}
            });


            Send(request);

            return(continuation.TCS.Task);
        }
        public void Reply(Message requestMsg, Message replyMsg)
        {
            var opHeader = requestMsg.GetHeader <OperationHeader>();

            if (opHeader != null)
            {
                int requestId = opHeader.RequestId;
                replyMsg.AttachHeader(new OperationHeader(requestId, OperationType.Reply));
                Channel.Send(replyMsg);
            }
            else
            {
                Log.Warn("Can't reply to {0} with {1} as source operation is one way", requestMsg, replyMsg);
            }

            Node.MessageFactory.Free(replyMsg);
        }
 public void Send(Message msg)
 {
     msg.AttachHeader(new CallbackHeader(_callbackRef.CallbackChannelId));
     _remoteNodeChannel.Send(msg);
 }