Beispiel #1
0
 public static Unit DeregisterCluster()
 {
     cluster.IfSome(c =>
     {
         c.Disconnect();
         c.Dispose();
     });
     started = false;
     return(Startup(None));
 }
Beispiel #2
0
        private void SetupClusterStatePersist(Option <ICluster> cluster, ProcessFlags flags)
        {
            cluster.IfSome(c =>
            {
                if ((flags & ProcessFlags.PersistState) == ProcessFlags.PersistState)
                {
                    try
                    {
                        stateSubject.Subscribe(state => c.SetValue(StateKey, state));
                    }
                    catch (Exception e)
                    {
                        logSysErr(e);
                    }
                }

                if ((flags & ProcessFlags.RemoteStatePublish) == ProcessFlags.RemoteStatePublish)
                {
                    try
                    {
                        stateSubject.Subscribe(state => c.PublishToChannel(ActorInboxCommon.ClusterPubSubKey(Id), state));
                    }
                    catch (Exception e)
                    {
                        logSysErr(e);
                    }
                }
            });
        }
Beispiel #3
0
        /// <summary>
        /// Shutdown everything from this node down
        /// </summary>
        public Unit Shutdown(bool maintainState)
        {
            lock (sync)
            {
                if (maintainState == false)
                {
                    cluster.IfSome(c =>
                    {
                        // TODO: Make this transactional
                        // {
                        c.Delete(StateKey);
                        c.Delete(ActorInboxCommon.ClusterUserInboxKey(Id));
                        c.Delete(ActorInboxCommon.ClusterSystemInboxKey(Id));
                        c.Delete(ActorInboxCommon.ClusterMetaDataKey(Id));
                        ActorContext.DeregisterById(Id);
                        // }
                    });
                }

                RemoveAllSubscriptions();
                publishSubject.OnCompleted();
                stateSubject.OnCompleted();
                remoteSubsAcquired = false;
                strategyState      = StrategyState.Empty;
                DisposeState();

                ActorContext.DispatchTerminate(Id);

                return(unit);
            }
        }
Beispiel #4
0
        private static void ClusterWatch(Option <ICluster> cluster)
        {
            var monitor = System[ActorSystemConfig.Default.MonitorProcessName];

            cluster.IfSome(c =>
            {
                Process.observe <NodeOnline>(monitor).Subscribe(x =>
                {
                    Process.logInfo("Online: " + x.Name);
                });

                Process.observe <NodeOffline>(monitor).Subscribe(x =>
                {
                    Process.logInfo("Offline: " + x.Name);
                    RemoveWatchingOfRemote(x.Name);
                });

                Process.observeState <ClusterMonitor.State>(monitor).Subscribe(x =>
                {
                    clusterState = x;
                });
            });

            Process.tell(monitor, new ClusterMonitor.Msg(ClusterMonitor.MsgTag.Heartbeat));
        }
Beispiel #5
0
 public static void Shutdown(Option <ICluster> cluster)
 {
     lock (sync)
     {
         updated?.Dispose();
         updated = null;
         cluster.IfSome(c => c.UnsubscribeChannel(SessionManagerProcess.SessionsNotify));
     }
 }
Beispiel #6
0
        void SetupRemoteSubscriptions(Option <ICluster> cluster, ProcessFlags flags)
        {
            if (remoteSubsAcquired)
            {
                return;
            }

            cluster.IfSome(c =>
            {
                // Watches for local state-changes and persists them
                if ((flags & ProcessFlags.PersistState) == ProcessFlags.PersistState)
                {
                    try
                    {
                        stateSubject.Subscribe(state => c.SetValue(StateKey, state));
                    }
                    catch (Exception e)
                    {
                        logSysErr(e);
                    }
                }

                // Watches for local state-changes and publishes them remotely
                if ((flags & ProcessFlags.RemoteStatePublish) == ProcessFlags.RemoteStatePublish)
                {
                    try
                    {
                        stateSubject.Subscribe(state => c.PublishToChannel(ActorInboxCommon.ClusterStatePubSubKey(Id), state));
                    }
                    catch (Exception e)
                    {
                        logSysErr(e);
                    }
                }

                // Watches for publish events and remotely publishes them
                if ((flags & ProcessFlags.RemotePublish) == ProcessFlags.RemotePublish)
                {
                    try
                    {
                        publishSubject.Subscribe(msg => c.PublishToChannel(ActorInboxCommon.ClusterPubSubKey(Id), msg));
                    }
                    catch (Exception e)
                    {
                        logSysErr(e);
                    }
                }
            });

            remoteSubsAcquired = true;
        }
Beispiel #7
0
 private void DisposeState()
 {
     state.IfSome(s =>
     {
         if (s is IDisposable)
         {
             var sd = state as IDisposable;
             if (sd != null)
             {
                 sd.Dispose();
             }
         }
     });
     state = None;
 }
Beispiel #8
0
 public void Dispose()
 {
     lock (sync)
     {
         var ri = rootItem;
         rootItem = null;
         if (ri != null)
         {
             startupSubscription?.Dispose();
             startupSubscription = null;
             var item = ri;
             ri.Actor.Children.Iter(c => c.Actor.ShutdownProcess(true));
             cluster.IfSome(c => c?.Dispose());
         }
     }
 }
Beispiel #9
0
        public static void Init(Option <ICluster> cluster)
        {
            lock (sync)
            {
                Shutdown(cluster);
                updated = observeState <SessionManagerProcess.State>(pid).Subscribe(SessionsUpdated);
                CheckExpired();

                // Forward remote messages on
                cluster.IfSome(c =>
                {
                    c.UnsubscribeChannel(SessionManagerProcess.SessionsNotify);
                    c.SubscribeToChannel <SessionManagerProcess.Msg>(SessionManagerProcess.SessionsNotify)
                    .Subscribe(msg => tell(pid, msg.MakeRemote()));
                });
            }
        }
Beispiel #10
0
        /// <summary>
        /// Shutdown everything from this node down
        /// </summary>
        public Unit Shutdown(bool maintainState)
        {
            lock (sync)
            {
                if (maintainState == false && Flags != ProcessFlags.Default)
                {
                    cluster.IfSome(c =>
                    {
                        // TODO: Make this transactional
                        // {
                        c.DeleteMany(
                            StateKey,
                            ActorInboxCommon.ClusterUserInboxKey(Id),
                            ActorInboxCommon.ClusterSystemInboxKey(Id),
                            ActorInboxCommon.ClusterMetaDataKey(Id),
                            ActorInboxCommon.ClusterSettingsKey(Id));

                        ActorContext.DeregisterById(Id);
                        // }

                        ProcessConfig.Settings.ClearInMemorySettingsOverride(ActorInboxCommon.ClusterSettingsKey(Id));
                    });
                }

                RemoveAllSubscriptions();
                publishSubject.OnCompleted();
                stateSubject.OnCompleted();
                remoteSubsAcquired = false;
                strategyState      = StrategyState.Empty;
                DisposeState();

                ActorContext.DispatchTerminate(Id);

                return(unit);
            }
        }
Beispiel #11
0
 public static Unit ifSome <T>(Option <T> option, Action <T> Some) =>
 option.IfSome(Some);
Beispiel #12
0
 void DisposeState()
 {
     state.IfSome(s => (s as IDisposable)?.Dispose());
     state = None;
 }