Exemplo n.º 1
0
 /// <summary>
 /// Clears the state (keeps the mailbox items)
 /// </summary>
 public Unit Restart(bool unpauseAfterRestart)
 {
     lock (sync)
     {
         RemoveAllSubscriptions();
         DisposeState();
         foreach (var kid in Children)
         {
             kill(kid.Value.Actor.Id);
         }
     }
     tellSystem(Id, SystemMessage.StartupProcess(unpauseAfterRestart));
     return(unit);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Send StartupProcess message to a process that isn't running (e.g. spawned with Lazy = true)
 /// </summary>
 public static Unit startup(ProcessId pid) =>
 ActorContext.System(pid).TellSystem(pid, SystemMessage.StartupProcess(false));
Exemplo n.º 3
0
        public ProcessId ActorCreate <S, T>(
            ActorItem parent,
            ProcessName name,
            Func <S, T, S> actorFn,
            Func <IActor, S> setupFn,
            Func <S, ProcessId, S> termFn,
            State <StrategyContext, Unit> strategy,
            ProcessFlags flags,
            int maxMailboxSize,
            bool lazy)
        {
            var actor = new Actor <S, T>(cluster, parent, name, actorFn, setupFn, termFn, strategy, flags, ActorContext.System(parent.Actor.Id).Settings, this);

            IActorInbox inbox = null;

            if ((actor.Flags & ProcessFlags.ListenRemoteAndLocal) == ProcessFlags.ListenRemoteAndLocal && cluster.IsSome)
            {
                inbox = new ActorInboxDual <S, T>();
            }
            else if ((actor.Flags & ProcessFlags.PersistInbox) == ProcessFlags.PersistInbox && cluster.IsSome)
            {
                inbox = new ActorInboxRemote <S, T>();
            }
            else
            {
                inbox = new ActorInboxLocal <S, T>();
            }

            var item = new ActorItem(actor, inbox, actor.Flags);

            parent.Actor.LinkChild(item);

            // Auto register if there are config settings and we
            // have the variable name it was assigned to.
            ActorContext.System(actor.Id).Settings.GetProcessRegisteredName(actor.Id).Iter(regName =>
            {
                // Also check if 'dispatch' is specified in the config, if so we will
                // register the Process as a role dispatcher PID instead of just its
                // PID.
                ActorContext.System(actor.Id).Settings.GetProcessDispatch(actor.Id)
                .Match(
                    Some: disp => Process.register(regName, Disp[$"role-{disp}"][Role.Current].Append(actor.Id.Skip(1))),
                    None: () => Process.register(regName, actor.Id)
                    );
            });

            try
            {
                inbox.Startup(actor, parent, cluster, maxMailboxSize);
                if (!lazy)
                {
                    TellSystem(actor.Id, SystemMessage.StartupProcess(false));
                }
            }
            catch
            {
                item?.Actor?.ShutdownProcess(false);
                throw;
            }
            return(item.Actor.Id);
        }