internal static RemoteMessageDTO CreateMessage(object message, ProcessId to, ProcessId sender, Message.Type type, Message.TagSpec tag, Option <SessionId> sessionId) =>
 new RemoteMessageDTO
 {
     Type        = (int)type,
     Tag         = (int)tag,
     To          = to.ToString(),
     RequestId   = -1,
     MessageId   = Guid.NewGuid(),
     Sender      = sender.ToString(),
     ReplyTo     = sender.ToString(),
     ContentType = message?.GetType()?.AssemblyQualifiedName,
     Content     = message == null
                         ? null
                         : JsonConvert.SerializeObject(message, ActorSystemConfig.Default.JsonSerializerSettings),
     SessionId = sessionId.Map(s => s.Value).IfNoneUnsafe(() => null)
 };
 internal static RemoteMessageDTO CreateRequest(ActorRequest req, ProcessId to, ProcessId sender, Option <SessionId> sessionId) =>
 new RemoteMessageDTO
 {
     Type        = (int)Message.Type.User,
     Tag         = (int)Message.TagSpec.UserAsk,
     Child       = null,
     Exception   = null,
     To          = to.ToString(),
     RequestId   = req.RequestId,
     MessageId   = Guid.NewGuid(),
     Sender      = sender.ToString(),
     ReplyTo     = req.ReplyTo.ToString(),
     ContentType = req.Message.GetType().AssemblyQualifiedName,
     Content     = JsonConvert.SerializeObject(req.Message, ActorSystemConfig.Default.JsonSerializerSettings),
     SessionId   = sessionId.Map(s => s.Value).IfNoneUnsafe(() => null)
 };
Esempio n. 3
0
        public IObservable <bool> DoPing(ProcessId pid, TimeSpan span = default(TimeSpan))
        {
            var req = new Req
            {
                PID        = pid.ToString(),
                RID        = Interlocked.Increment(ref Id),
                SenderNode = System.Name.Value
            };

            return((from r in Responses
                    where r.PID == req.PID && r.RID == req.RID && r.ReceiverNode == req.SenderNode
                    select r.Alive)
                   .Take(1)
                   .Timeout(span.Seconds == 0
                        ? TimeSpan.FromSeconds(1)
                        : span)
                   .Catch(Observable.Return(false))
                   .ObserveOn(TaskPoolScheduler.Default)
                   .PostSubscribe(() =>
            {
                System.Cluster.Match(
                    Some: c =>
                {
                    if (c.PublishToChannel("ping-requests", req) == 0)
                    {
                        // The message didn't reach any endpoints, so let's early out
                        EarlyResponses.OnNext(new Resp()
                        {
                            PID = req.PID,
                            RID = req.RID,
                            ReceiverNode = req.SenderNode
                        });
                    }
                },
                    None: () => EarlyResponses.OnNext(new Resp()
                {
                    PID = req.PID,
                    RID = req.RID,
                    ReceiverNode = req.SenderNode
                })
                    );
            }));
        }
Esempio n. 4
0
 private static string ProcessFmt(ProcessId pid) =>
 pid.IsValid
         ? pid.ToString()
         : "no-sender";