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.actor = (Actor <S, T>)process; this.cluster = cluster.IfNoneUnsafe(() => null); this.maxMailboxSize = maxMailboxSize == -1 ? ActorContext.System(actor.Id).Settings.GetProcessMailboxSize(actor.Id) : maxMailboxSize; this.parent = parent; userNotify = new PausableBlockingQueue <string>(this.maxMailboxSize); var obj = new ThreadObj { Actor = actor, Inbox = this, Parent = parent }; userNotify.ReceiveAsync(obj, (state, msg) => { CheckRemoteInbox(ActorInboxCommon.ClusterUserInboxKey(state.Actor.Id), true); return(InboxDirective.Default); }); 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); }
public Either <string, bool> CanAccept <T>() { if (Cluster.Exists(ActorInboxCommon.ClusterMetaDataKey(ProcessId))) { var meta = Cluster.GetValue <ProcessMetaData>(ActorInboxCommon.ClusterMetaDataKey(ProcessId)); return(meta == null ? true : TypeHelper.IsMessageValidForProcess(typeof(T), meta.MsgTypeNames).Map(_ => true)); } else { return(true); } }
void ValidateMessageType(object message, ProcessId sender) { if (Cluster.Exists(ActorInboxCommon.ClusterMetaDataKey(ProcessId))) { var meta = Cluster.GetValue <ProcessMetaData>(ActorInboxCommon.ClusterMetaDataKey(ProcessId)); if (meta == null) { return; } TypeHelper.IsMessageValidForProcess(message, meta.MsgTypeNames).IfLeft((string err) => { throw new ProcessException($"{err} for Process ({ProcessId}).", ProcessId.Path, sender.Path, null); }); } }
public Either <string, bool> HasStateTypeOf <T>() { if (Cluster.Exists(ActorInboxCommon.ClusterMetaDataKey(ProcessId))) { var meta = Cluster.GetValue <ProcessMetaData>(ActorInboxCommon.ClusterMetaDataKey(ProcessId)); if (meta == null) { return(true); } return(TypeHelper.HasStateTypeOf(typeof(T), meta.StateTypeInterfaces)); } else { return(true); } }
public IEnumerable <Type> GetValidMessageTypes() { if (Cluster.Exists(ActorInboxCommon.ClusterMetaDataKey(ProcessId))) { var meta = Cluster.GetValue <ProcessMetaData>(ActorInboxCommon.ClusterMetaDataKey(ProcessId)); if (meta == null) { return(new Type[0]); } return(meta.MsgTypeNames.Map(Type.GetType).ToArray()); } else { return(new Type[0]); } }
/// <summary> /// Shutdown everything from this node down /// </summary> public Unit Shutdown(bool maintainState) { cancellationTokenSource.Cancel(); // this will signal other operations not to start processing more messages (ProcessMessage) or startup again (Startup), even if they already received something from the queue 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)); sys.DeregisterById(Id); // } sys.Settings.ClearInMemorySettingsOverride(ActorInboxCommon.ClusterSettingsKey(Id)); }); } RemoveAllSubscriptions(); publishSubject.OnCompleted(); stateSubject.OnCompleted(); remoteSubsAcquired = false; strategyState = StrategyState.Empty; state.IfSome(shutdownFn); DisposeState(); sys.DispatchTerminate(Id); return(unit); } }
/// <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)); sys.DeregisterById(Id); // } sys.Settings.ClearInMemorySettingsOverride(ActorInboxCommon.ClusterSettingsKey(Id)); }); } RemoveAllSubscriptions(); publishSubject.OnCompleted(); stateSubject.OnCompleted(); remoteSubsAcquired = false; strategyState = StrategyState.Empty; DisposeState(); sys.DispatchTerminate(Id); return(unit); } }