/// <summary> /// Initializes the newly created <c>Actor</c>. /// </summary> protected Actor() { var maybeEnvironment = ActorFactory.ThreadLocalEnvironment.Value; LifeCycle = new LifeCycle(maybeEnvironment ?? new TestEnvironment()); ActorFactory.ThreadLocalEnvironment.Value = null; completes = new ResultCompletes <object>(); }
/// <summary> /// Answers the <typeparamref name="T"/> protocol for the child <c>Actor</c> to be created by this parent <c>Actor</c>. /// </summary> /// <typeparam name="T">The protocol type</typeparam> /// <param name="definition">The <c>Definition</c> of the child <c>Actor</c> to be created by this parent <c>Actor</c></param> /// <returns>A child <c>Actor</c> of type <typeparamref name="T"/> created by this parent <c>Actor</c>.</returns> protected internal virtual T ChildActorFor <T>(Definition definition) { if (definition.Supervisor != null) { return(LifeCycle.Environment.Stage.ActorFor <T>( definition, this, definition.Supervisor, Logger)); } if (this is ISupervisor) { return(LifeCycle.Environment.Stage.ActorFor <T>( definition, this, LifeCycle.LookUpProxy <ISupervisor>(), Logger)); } return(LifeCycle.Environment.Stage.ActorFor <T>(definition, this, null, Logger)); }
internal protected virtual void AfterRestart(Exception reason) { // override LifeCycle.BeforeStart(this); }
internal protected virtual void BeforeRestart(Exception reason) { // override LifeCycle.AfterStop(this); }
protected void Secure() { LifeCycle.Secure(); }
/// <summary> /// Secures this <c>Actor</c>. /// </summary> protected virtual void Secure() { LifeCycle.Secure(); }
/// <summary> /// Answers the <code>Protocols</code> for the child <code>Actor</code> to be created by this parent <code>Actor</code>. /// </summary> /// <param name="protocols">The protocols for the child <code>Actor</code>.</param> /// <param name="definition">The <code>Definition</code> of the child <code>Actor</code> to be created by this parent <code>Actor</code>.</param> /// <returns><code>Protocols</code></returns> protected internal Protocols ChildActorFor(Type[] protocols, Definition definition) { if (definition.Supervisor != null) { return(LifeCycle.Environment.Stage.ActorFor(protocols, definition, this, definition.Supervisor, Logger)); } else { if (this is ISupervisor) { return(LifeCycle.Environment.Stage.ActorFor(protocols, definition, this, LifeCycle.LookUpProxy <ISupervisor>(), Logger)); } else { return(LifeCycle.Environment.Stage.ActorFor(protocols, definition, this, null, Logger)); } } }
/// <summary> /// The message delivered after the <c>Actor</c> has been restarted by its supervisor due to an exception. /// Override to implement. /// </summary> /// <param name="reason">The <c>Exception</c> cause of the supervision restart.</param> protected internal virtual void AfterRestart(Exception reason) { // override for specific recovery Logger.Error($"Default after restart recovery after: {reason.Message}", reason); LifeCycle.BeforeStart(this); }
/// <summary> /// Starts the process of stowing messages for this <c>Actor</c>, and registers <paramref name="stowageOverrides"/> as /// the protocol that will trigger dispersal. /// </summary> /// <param name="stowageOverrides">The protocol <c>Type</c>(s) that will trigger dispersal</param> protected internal virtual void StowMessages(params Type[] stowageOverrides) { LifeCycle.StowMessages(); LifeCycle.Environment.StowageOverrides(stowageOverrides); }
/// <summary> /// Starts the process of dispersing any messages stowed for this <c>Actor</c>. /// </summary> protected internal virtual void DisperseStowedMessages() { LifeCycle.DisperseStowedMessages(); }