コード例 #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;
 }
コード例 #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));
        }
コード例 #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);
        }
コード例 #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);
            }
        }
コード例 #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));
     }
 }
コード例 #6
0
ファイル: ActorSystem.cs プロジェクト: ocdogan/Sweet.Actors
        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);
        }
コード例 #7
0
ファイル: ActorSystem.cs プロジェクト: ocdogan/Sweet.Actors
        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);
        }
コード例 #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
            });
        }
コード例 #9
0
ファイル: ActorSystem.cs プロジェクト: ocdogan/Sweet.Actors
        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);
        }
コード例 #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);
        }
コード例 #11
0
 public FutureError(Exception e, Aid from = null, IDictionary <string, string> header = null)
     : base(e, from, header)
 {
 }
コード例 #12
0
 public FutureResponse(object data, Aid from = null, IDictionary <string, string> header = null,
                       int timeoutMSec       = 0)
     : base(data, from, header, timeoutMSec)
 {
 }
コード例 #13
0
 public virtual void RespondWithError(Exception e, Aid from = null, IDictionary <string, string> header = null)
 {
     Unregister();
     _tcs.TrySetResult(new FutureError(e, from, header));
 }
コード例 #14
0
 internal RemoteAddress(RemoteEndPoint endPoint, Aid actorId)
 {
     _endPoint = endPoint ?? throw new ArgumentNullException(nameof(endPoint));
     _actor    = actorId ?? throw new ArgumentNullException(nameof(actorId));
 }
コード例 #15
0
 internal RemoteAddress(RemoteEndPoint endPoint, string actorSystem, string actor)
 {
     _endPoint = endPoint ?? throw new ArgumentNullException(nameof(endPoint));
     _actor    = new Aid(actorSystem, actor);
 }
コード例 #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);
        }
コード例 #17
0
 internal RemoteRequest(IFutureMessage message, Aid to,
                        Action <object, TaskCompletionStatus> onTimeout)
     : base(message, to, WireMessageId.Next())
 {
     _onTimeout += onTimeout;
 }