/// <inheritdoc /> /// <summary> /// Registers the <paramref name="actor"/> to actor system. /// Name of the actor should be unique, but this is not checked. Each actor must register first to be able to receive the messages within the actor system. /// </summary> /// <param name="actor">Actor to be registered</param> /// <param name="name">Name of the actor. Name of the actor should be unique, but this is not checked. Name is mandatory and can't be empty</param> /// <returns>Actor reference to the registered actor</returns> public IActorRef RegisterActor(IActor actor, string name) { Logger.Info($"Registering actor {name}..."); var actorRef = new ActorRefInternal(actor, name, this); ActorsByRef.TryAdd(actorRef, actor); Logger.Info($"Registered actor {name}"); return(actorRef); }
/// <inheritdoc /> /// <summary> /// De-register actor identified by <paramref name="actorRef" /> from the actor system /// If <paramref name="actorRef" /> is not found within the actor system, WARN message is logged, but raises no error/exception /// </summary> /// <param name="actorRef">Reference to actor to be de-registered</param> public void DeRegisterActor(IActorRef actorRef) { Logger.Info($"DeRegistering actor {actorRef.Name}"); if (!ActorsByRef.ContainsKey(actorRef)) { Logger.Warn($"DeRegistering actor {actorRef.Name} - actor not found"); return; } if (actorRef is ActorRefInternal actorRefInternal) { actorRefInternal.Queue.CleanUp(DeadLetters); } ActorsByRef.TryRemove(actorRef, out _); Logger.Info($"DeRegistered actor {actorRef.Name}"); }