Ejemplo n.º 1
0
        private S InitState()
        {
            S state;

            if (cluster.IsSome && ((flags & ProcessFlags.PersistState) == ProcessFlags.PersistState))
            {
                try
                {
                    logInfo("Restoring state: " + StateKey);

                    state = cluster.LiftUnsafe().Exists(StateKey)
                        ? cluster.LiftUnsafe().GetValue <S>(StateKey)
                        : setupFn(this);
                }
                catch (Exception e)
                {
                    logSysErr(e);
                    state = setupFn(this);
                }
            }
            else
            {
                state = setupFn(this);
            }

            stateSubject.OnNext(state);
            return(state);
        }
        public Unit Startup(IActor process, ActorItem parent, Option <ICluster> cluster, int maxMailboxSize)
        {
            if (cluster.IsNone)
            {
                throw new Exception("Remote inboxes not supported when there's no cluster");
            }
            this.tokenSource = new CancellationTokenSource();
            this.actor       = (Actor <S, T>)process;
            this.cluster     = cluster.LiftUnsafe();

            this.maxMailboxSize = maxMailboxSize;
            this.parent         = parent;

            userNotify = ActorInboxCommon.StartNotifyMailbox(tokenSource.Token, msgId => CheckRemoteInbox(ActorInboxCommon.ClusterUserInboxKey(actor.Id), true));
            sysNotify  = ActorInboxCommon.StartNotifyMailbox(tokenSource.Token, msgId => CheckRemoteInbox(ActorInboxCommon.ClusterSystemInboxKey(actor.Id), false));

            SubscribeToSysInboxChannel();
            SubscribeToUserInboxChannel();

            this.cluster.SetValue(ActorInboxCommon.ClusterMetaDataKey(actor.Id), new ProcessMetaData(
                                      new[] { typeof(T).AssemblyQualifiedName },
                                      typeof(S).AssemblyQualifiedName,
                                      typeof(S).GetTypeInfo().ImplementedInterfaces.Map(x => x.AssemblyQualifiedName).ToArray()
                                      ));

            return(unit);
        }
Ejemplo n.º 3
0
        public Unit Startup(IActor process, ActorItem parent, Option <ICluster> cluster, int version = 0)
        {
            if (cluster.IsNone)
            {
                throw new Exception("Remote inboxes not supported when there's no cluster");
            }
            this.tokenSource = new CancellationTokenSource();
            this.actor       = (Actor <S, T>)process;
            this.cluster     = cluster.LiftUnsafe();
            this.version     = version;
            this.parent      = parent;

            // Registered process remote address hack
            actorPath = actor.Id.Path.StartsWith(Registered.Path)
                ? actor.Id.Skip(1).ToString()
                : actor.Id.ToString();

            // Preparing for message versioning support
            //actorPath += "-" + version;

            userNotify = ActorInboxCommon.StartNotifyMailbox(tokenSource.Token, msgId => CheckRemoteInbox(ClusterUserInboxKey));
            sysNotify  = ActorInboxCommon.StartNotifyMailbox(tokenSource.Token, msgId => CheckRemoteInbox(ClusterSystemInboxKey));

            this.cluster.SubscribeToChannel <string>(ClusterUserInboxNotifyKey, msg => userNotify.Post(msg));
            this.cluster.SubscribeToChannel <string>(ClusterSystemInboxNotifyKey, msg => sysNotify.Post(msg));

            // We want the check done asyncronously, in case the setup function creates child processes that
            // won't exist if we invoke directly.
            this.cluster.PublishToChannel(ClusterUserInboxNotifyKey, Guid.NewGuid().ToString());
            this.cluster.PublishToChannel(ClusterSystemInboxNotifyKey, Guid.NewGuid().ToString());

            return(unit);
        }
        public Unit Startup(IActor process, ActorItem parent, Option <ICluster> cluster, int maxMailboxSize)
        {
            if (cluster.IsNone)
            {
                throw new Exception("Remote inboxes not supported when there's no cluster");
            }
            this.tokenSource    = new CancellationTokenSource();
            this.actor          = (Actor <S, T>)process;
            this.cluster        = cluster.LiftUnsafe();
            this.maxMailboxSize = maxMailboxSize < 0
                ? ActorConfig.Default.MaxMailboxSize
                : maxMailboxSize;
            this.parent = parent;

            actorPath = actor.Id.ToString();

            userNotify = ActorInboxCommon.StartNotifyMailbox(tokenSource.Token, msgId => CheckRemoteInbox(ClusterUserInboxKey, true));
            sysNotify  = ActorInboxCommon.StartNotifyMailbox(tokenSource.Token, msgId => CheckRemoteInbox(ClusterSystemInboxKey, false));

            SubscribeToSysInboxChannel();
            SubscribeToUserInboxChannel();

            this.cluster.SetValue(ActorInboxCommon.ClusterMetaDataKey(actor.Id), new ProcessMetaData(
                                      new[] { typeof(T).FullName },
                                      typeof(S).FullName
                                      ));

            return(unit);
        }
Ejemplo n.º 5
0
        S InitState()
        {
            S state;

            try
            {
                SetupRemoteSubscriptions(cluster, flags);

                if (cluster.IsSome && ((flags & ProcessFlags.PersistState) == ProcessFlags.PersistState))
                {
                    try
                    {
                        logInfo($"Restoring state: {StateKey}");

                        state = cluster.LiftUnsafe().Exists(StateKey)
                            ? cluster.LiftUnsafe().GetValue <S>(StateKey)
                            : setupFn(this);
                    }
                    catch (Exception e)
                    {
                        logSysErr(e);
                        state = setupFn(this);
                    }
                }
                else
                {
                    state = setupFn(this);
                }

                ActorContext.RunContextOps();
            }
            catch (Exception e)
            {
                throw new ProcessSetupException(Id.Path, e);
            }

            try
            {
                stateSubject.OnNext(state);
            }
            catch (Exception ue)
            {
                // Not our errors, so just log and move on
                logErr(ue);
            }
            return(state);
        }
Ejemplo n.º 6
0
        public Unit Startup(IActor process, ActorItem parent, Option <ICluster> cluster, int version = 0)
        {
            if (cluster.IsNone)
            {
                throw new Exception("Remote inboxes not supported when there's no cluster");
            }
            this.tokenSource = new CancellationTokenSource();
            this.actor       = (Actor <S, T>)process;
            this.parent      = parent;
            this.cluster     = cluster.LiftUnsafe();
            this.version     = version;

            // Registered process remote address hack
            actorPath = actor.Id.Path.StartsWith(Registered.Path)
                ? actor.Id.Skip(1).ToString()
                : actor.Id.ToString();

            // Preparing for message versioning support
            //actorPath += "-" + version;

            userInbox = StartMailbox <UserControlMessage>(actor, ClusterUserInboxKey, tokenSource.Token, ActorInboxCommon.UserMessageInbox);
            sysInbox  = StartMailbox <SystemMessage>(actor, ClusterSystemInboxKey, tokenSource.Token, ActorInboxCommon.SystemMessageInbox);

            this.cluster.SubscribeToChannel <string>(ClusterUserInboxNotifyKey,
                                                     msg =>
            {
                if (userInbox.CurrentQueueLength == 0)
                {
                    CheckRemoteInbox(ClusterUserInboxKey, this.cluster, actor.Id, sysInbox, userInbox);
                }
            });

            this.cluster.SubscribeToChannel <string>(ClusterSystemInboxNotifyKey,
                                                     msg =>
            {
                if (sysInbox.CurrentQueueLength == 0)
                {
                    CheckRemoteInbox(ClusterSystemInboxKey, this.cluster, actor.Id, sysInbox, userInbox);
                }
            });

            this.cluster.PublishToChannel(ClusterUserInboxNotifyKey, Guid.NewGuid().ToString());
            this.cluster.PublishToChannel(ClusterSystemInboxNotifyKey, Guid.NewGuid().ToString());

            return(unit);
        }
Ejemplo n.º 7
0
        public Unit Startup(IActor process, ActorItem parent, Option <ICluster> cluster, int maxMailboxSize)
        {
            if (cluster.IsNone)
            {
                throw new Exception("Remote inboxes not supported when there's no cluster");
            }
            this.tokenSource = new CancellationTokenSource();
            this.actor       = (Actor <S, T>)process;
            this.parent      = parent;
            this.cluster     = cluster.LiftUnsafe();

            this.maxMailboxSize = maxMailboxSize;

            userInbox = StartMailbox <UserControlMessage>(actor, ActorInboxCommon.ClusterUserInboxKey(actor.Id), tokenSource.Token, StatefulUserInbox, true);
            sysInbox  = StartMailbox <SystemMessage>(actor, ActorInboxCommon.ClusterSystemInboxKey(actor.Id), tokenSource.Token, ActorInboxCommon.SystemMessageInbox, false);

            SubscribeToSysInboxChannel();
            SubscribeToUserInboxChannel();

            return(unit);
        }