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; }
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)); }
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); }
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); } }
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)); } }
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); }
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); }
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 }); }
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); }
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); }
public FutureError(Exception e, Aid from = null, IDictionary <string, string> header = null) : base(e, from, header) { }
public FutureResponse(object data, Aid from = null, IDictionary <string, string> header = null, int timeoutMSec = 0) : base(data, from, header, timeoutMSec) { }
public virtual void RespondWithError(Exception e, Aid from = null, IDictionary <string, string> header = null) { Unregister(); _tcs.TrySetResult(new FutureError(e, from, header)); }
internal RemoteAddress(RemoteEndPoint endPoint, Aid actorId) { _endPoint = endPoint ?? throw new ArgumentNullException(nameof(endPoint)); _actor = actorId ?? throw new ArgumentNullException(nameof(actorId)); }
internal RemoteAddress(RemoteEndPoint endPoint, string actorSystem, string actor) { _endPoint = endPoint ?? throw new ArgumentNullException(nameof(endPoint)); _actor = new Aid(actorSystem, actor); }
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); }
internal RemoteRequest(IFutureMessage message, Aid to, Action <object, TaskCompletionStatus> onTimeout) : base(message, to, WireMessageId.Next()) { _onTimeout += onTimeout; }