Exemplo n.º 1
0
 public RemoteMessage(IMessage message, Aid to, WireMessageId messageId)
 {
     _to        = to ?? Aid.Unknown;
     _message   = message ?? Actors.Message.Empty;
     _messageId = messageId ?? WireMessageId.Next();
     _isFuture  = _message is IFutureMessage;
 }
Exemplo n.º 2
0
        internal RemoteAddress(string host, int port, Aid actorId)
        {
            host = host?.Trim() ?? String.Empty;
            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }

            _endPoint = new RemoteEndPoint(host, port);
            _actor    = actorId ?? throw new ArgumentNullException(nameof(actorId));
        }
Exemplo n.º 3
0
        internal RemoteAddress(string host, int port, string actorSystem, string actor)
        {
            host = host?.Trim() ?? String.Empty;
            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }

            _endPoint = new RemoteEndPoint(host, port);
            _actor    = new Aid(actorSystem, actor);
        }
Exemplo n.º 4
0
        public FutureMessage(object data, Aid from,
                             IDictionary <string, string> header = null, int?timeoutMSec = null)
            : base(data, from, header, timeoutMSec)
        {
            _tcs = new TaskCompletionSource <IFutureResponse>();

            _timeoutMSec = Common.CheckMessageTimeout(timeoutMSec);
            if (_timeoutMSec.HasValue)
            {
                _registered = 1;
                TimeoutHandler.TryRegister(this, DoTimedOut, _timeoutMSec.Value);
            }
        }
Exemplo n.º 5
0
 public virtual void Respond(object response, Aid from = null, IDictionary <string, string> header = null)
 {
     try
     {
         Unregister();
         _tcs.TrySetResult(response == null ?
                           new FutureResponse(from, header) :
                           new FutureResponse(response, from, header));
     }
     catch (Exception e)
     {
         _tcs.TrySetResult(new FutureError(e, from, header));
     }
 }
Exemplo n.º 6
0
        public bool TryGetLocal(Aid localAid, out Pid pid)
        {
            pid = null;
            if (localAid != null)
            {
                pid = localAid as Pid;
                if (pid?.Process != null)
                {
                    return(true);
                }

                return(TryGetInternal(localAid.Actor, out pid));
            }
            return(false);
        }
Exemplo n.º 7
0
        public bool TryGetRemote(Aid remoteAid, out Pid pid)
        {
            pid = null;
            if (remoteAid != null)
            {
                pid = remoteAid as Pid;
                if (pid?.Process != null)
                {
                    return(true);
                }

                return(TryGetInternal($"remote://{remoteAid.ActorSystem}/{remoteAid.Actor}", out pid));
            }
            return(false);
        }
Exemplo n.º 8
0
        public static WireMessage ToWireMessage(this Exception exception, Aid from, Aid to, WireMessageId id = null)
        {
            var faulted = (exception != null);

            var state = WireMessageState.Empty;

            state |= faulted ? WireMessageState.Faulted : WireMessageState.Canceled;

            return(new WireMessage
            {
                From = from,
                To = to,
                Exception = exception,
                MessageType = faulted ? MessageType.FutureError : MessageType.FutureResponse,
                Id = id ?? WireMessageId.Next(),
                State = state
            });
        }
Exemplo n.º 9
0
        public static bool TryGet(Aid aid, out Pid pid)
        {
            pid = null;
            if (aid != null)
            {
                pid = aid as Pid;
                if (pid?.Process != null)
                {
                    return(true);
                }

                if (TryGet(aid.ActorSystem, out ActorSystem actorSystem))
                {
                    return(actorSystem.TryGetInternal(aid.Actor, out pid) ||
                           actorSystem.TryGetInternal($"remote://{aid.ActorSystem}/{aid.Actor}", out pid));
                }
            }
            return(false);
        }
Exemplo n.º 10
0
        public Message(object data, Aid from = null,
                       IDictionary <string, string> header = null, int?timeoutMSec = null)
        {
            _data = data;
            _from = from ?? Aid.Unknown;

            _isEmpty = (data == null);

            if (header != null)
            {
                if (header is IReadOnlyDictionary <string, string> roHeader)
                {
                    _header = roHeader;
                }
                else
                {
                    _header = new ReadOnlyDictionary <string, string>(header);
                }
            }

            _creationTime = Environment.TickCount;
            _timeoutMSec  = Common.CheckMessageTimeout(timeoutMSec);
        }
Exemplo n.º 11
0
 public FutureError(Exception e, Aid from = null, IDictionary <string, string> header = null)
     : base(e, from, header)
 {
 }
Exemplo n.º 12
0
 public FutureResponse(object data, Aid from = null, IDictionary <string, string> header = null,
                       int timeoutMSec       = 0)
     : base(data, from, header, timeoutMSec)
 {
 }
Exemplo n.º 13
0
 public virtual void RespondWithError(Exception e, Aid from = null, IDictionary <string, string> header = null)
 {
     Unregister();
     _tcs.TrySetResult(new FutureError(e, from, header));
 }
Exemplo n.º 14
0
 internal RemoteAddress(RemoteEndPoint endPoint, Aid actorId)
 {
     _endPoint = endPoint ?? throw new ArgumentNullException(nameof(endPoint));
     _actor    = actorId ?? throw new ArgumentNullException(nameof(actorId));
 }
Exemplo n.º 15
0
 internal RemoteAddress(RemoteEndPoint endPoint, string actorSystem, string actor)
 {
     _endPoint = endPoint ?? throw new ArgumentNullException(nameof(endPoint));
     _actor    = new Aid(actorSystem, actor);
 }
Exemplo n.º 16
0
        public static WireMessage ToWireMessage(this IMessage message, Aid to, WireMessageId id = null, Exception exception = null)
        {
            var result = new WireMessage {
                To = to, Id = id ?? WireMessageId.Next()
            };

            if (message != null)
            {
                result.MessageType = message.MessageType;
                result.From        = message.From;
                result.Data        = message.Data;
                result.TimeoutMSec = message.TimeoutMSec;

                var msgHeader   = message.Header;
                var headerCount = msgHeader?.Count ?? 0;

                if (headerCount > 0)
                {
                    var header = new Dictionary <string, string>(headerCount);
                    foreach (var kv in msgHeader)
                    {
                        header.Add(kv.Key, kv.Value);
                    }
                    result.Header = header;
                }

                var state = WireMessageState.Default;
                if (message.IsEmpty)
                {
                    state |= WireMessageState.Empty;
                }

                if (message is IFutureMessage future)
                {
                    if (future.IsCanceled)
                    {
                        state |= WireMessageState.Canceled;
                    }

                    if (future.IsCompleted)
                    {
                        state |= WireMessageState.Completed;
                    }

                    if (future.IsFaulted)
                    {
                        state |= WireMessageState.Faulted;
                    }
                }

                if (exception != null)
                {
                    result.Exception = exception;
                    state           |= WireMessageState.Faulted;
                }
                else if (message is IFutureError error)
                {
                    result.Exception = error.Exception;
                    state           |= WireMessageState.Faulted;
                }

                result.State = state;
            }
            return(result);
        }
Exemplo n.º 17
0
 internal RemoteRequest(IFutureMessage message, Aid to,
                        Action <object, TaskCompletionStatus> onTimeout)
     : base(message, to, WireMessageId.Next())
 {
     _onTimeout += onTimeout;
 }