Пример #1
0
        public static Unit Startup(Option <ICluster> cluster)
        {
            if (started)
            {
                return(unit);
            }

            ActorContext.cluster = cluster;
            var name = GetRootProcessName();

            if (name.Value == "root" && cluster.IsSome)
            {
                throw new ArgumentException("Cluster node name cannot be 'root', it's reserved for local use only.");
            }
            if (name.Value == "disp" && cluster.IsSome)
            {
                throw new ArgumentException("Cluster node name cannot be 'disp', it's reserved for internal use.");
            }
            if (name.Value == "js")
            {
                throw new ArgumentException("Node name cannot be 'js', it's reserved for ProcessJS.");
            }

            lock (sync)
            {
                if (started)
                {
                    return(unit);
                }

                startupTimestamp = DateTime.UtcNow.Ticks;
                startupSubscription?.Dispose();
                startupSubscription = NotifyCluster(cluster, startupTimestamp);

                Dispatch.init();
                Role.init();
                Reg.init();

                watchers  = Map.empty <ProcessId, Set <ProcessId> >();
                watchings = Map.empty <ProcessId, Set <ProcessId> >();
                var root      = ProcessId.Top.Child(name);
                var rootInbox = new ActorInboxLocal <ActorSystemState, Unit>();
                var parent    = new ActorItem(new NullProcess(), new NullInbox(), ProcessFlags.Default);

                var go          = new AutoResetEvent(false);
                var state       = new ActorSystemState(cluster, root, null, rootInbox, cluster.Map(x => x.NodeName).IfNone(ActorConfig.Default.RootProcessName), ActorConfig.Default);
                var rootProcess = state.RootProcess;
                state.Startup();
                userContext = new ActorRequestContext(rootProcess.Children["user"], ProcessId.NoSender, rootItem, null, null, ProcessFlags.Default);
                rootInbox.Startup(rootProcess, parent, cluster, ProcessSetting.DefaultMailboxSize);
                rootItem = new ActorItem(rootProcess, rootInbox, ProcessFlags.Default);
                started  = true;

                SessionManager.Init(cluster);
                ClusterWatch(cluster);
            }
            return(unit);
        }
Пример #2
0
        public static Unit Startup(Option <ICluster> cluster, int version = 0)
        {
            if (started)
            {
                return(unit);
            }

            ActorContext.cluster = cluster;
            var name = GetRootProcessName();

            if (name.Value == "root" && cluster.IsSome)
            {
                throw new ArgumentException("Cluster node name cannot be 'root', it's reserved for local use only.");
            }
            if (name.Value == "registered")
            {
                throw new ArgumentException("Node name cannot be 'registered', it's reserved for registered processes.");
            }
            if (name.Value == "js")
            {
                throw new ArgumentException("Node name cannot be 'js', it's reserved for ProcessJS.");
            }

            lock (sync)
            {
                if (started)
                {
                    return(unit);
                }
                var root      = ProcessId.Top.Child(name);
                var rootInbox = new ActorInboxLocal <ActorSystemState, Unit>();
                var parent    = new ActorItem(new NullProcess(), new NullInbox(), ProcessFlags.Default);

                var go          = new AutoResetEvent(false);
                var state       = new ActorSystemState(cluster, root, null, rootInbox, cluster.Map(x => x.NodeName).IfNone(ActorConfig.Default.RootProcessName), ActorConfig.Default);
                var rootProcess = state.RootProcess;
                state.Startup();
                userContext = new ActorRequestContext(rootProcess.Children["user"], ProcessId.NoSender, rootItem, null, null, ProcessFlags.Default);
                rootInbox.Startup(rootProcess, parent, cluster, version);
                rootProcess.Startup();
                rootItem = new ActorItem(rootProcess, rootInbox, ProcessFlags.Default);
                started  = true;
            }
            return(unit);
        }
Пример #3
0
 public static ActorSystemState Inbox(ActorSystemState state, Unit msg)
 {
     return(state);
 }