Esempio n. 1
0
        public ActorDispatchJS(ProcessId pid, Option <SessionId> sessionId, bool transactionalIO)
        {
            Id = ClientConnectionId.New(pid.Skip(2).Take(1).Name.Value);
            ProcessHub.Connections.Find(Id).IfNone(() => { throw new ClientDisconnectedException(Id); });

            ProcessId            = pid;
            SessionId            = sessionId;
            this.transactionalIO = transactionalIO;
        }
Esempio n. 2
0
        public static ProcessId ConnectionInbox(ProcessId hub, RelayMsg rmsg)
        {
            switch (rmsg.Tag)
            {
            case RelayMsg.MsgTag.Inbound:
                var inmsg = rmsg as InboundRelayMsg;
                if (rmsg.IsAsk)
                {
                    // Ask not supported
                    tell(Errors(hub.System), "'ask' not supported from JS to server.");
                }
                else
                {
                    tell(rmsg.To, inmsg.Message, rmsg.Sender.IsValid ? Self.Append(rmsg.Sender) : ProcessId.NoSender);
                }
                break;

            case RelayMsg.MsgTag.Outbound:
                fwd(hub, rmsg);
                break;

            case RelayMsg.MsgTag.Subscribe:
                var pid          = rmsg.To;
                var subscriber   = rmsg.Sender;
                var connectionId = rmsg.ConnectionId;

                ActorContext.Request.Self.Actor.AddSubscription(
                    rmsg.To,
                    ActorContext.System(pid).Observe <object>(pid).Subscribe(x =>
                                                                             tell(hub,
                                                                                  new OutboundRelayMsg(
                                                                                      ClientConnectionId.New(connectionId),
                                                                                      new RemoteMessageDTO {
                    MessageId   = Guid.NewGuid(),
                    Content     = JsonConvert.SerializeObject(x),
                    Sender      = pid.ToString(),
                    To          = subscriber.ToString(),
                    ContentType = x.GetType().AssemblyQualifiedName,
                    ReplyTo     = pid.ToString(),
                    Tag         = (int)Message.TagSpec.User,
                    Type        = (int)Message.Type.User
                },
                                                                                      subscriber,
                                                                                      pid,
                                                                                      false),
                                                                                  pid)));
                break;

            case RelayMsg.MsgTag.Unsubscribe:
                ActorContext.Request.Self.Actor.RemoveSubscription(rmsg.To);
                break;
            }
            return(hub);
        }