public static Unit DeregisterCluster() { cluster.IfSome(c => { c.Disconnect(); c.Dispose(); }); started = false; return(Startup(None)); }
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); } } }); }
/// <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); } }
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)); }
public static void Shutdown(Option <ICluster> cluster) { lock (sync) { updated?.Dispose(); updated = null; cluster.IfSome(c => c.UnsubscribeChannel(SessionManagerProcess.SessionsNotify)); } }
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; }
private void DisposeState() { state.IfSome(s => { if (s is IDisposable) { var sd = state as IDisposable; if (sd != null) { sd.Dispose(); } } }); state = None; }
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()); } } }
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())); }); } }
/// <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); } }
public static Unit ifSome <T>(Option <T> option, Action <T> Some) => option.IfSome(Some);
void DisposeState() { state.IfSome(s => (s as IDisposable)?.Dispose()); state = None; }