Example #1
0
        /// <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>();
        }
Example #2
0
        /// <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));
        }
Example #3
0
 internal protected virtual void AfterRestart(Exception reason)
 {
     // override
     LifeCycle.BeforeStart(this);
 }
Example #4
0
 internal protected virtual void BeforeRestart(Exception reason)
 {
     // override
     LifeCycle.AfterStop(this);
 }
Example #5
0
 protected void Secure()
 {
     LifeCycle.Secure();
 }
Example #6
0
 /// <summary>
 /// Secures this <c>Actor</c>.
 /// </summary>
 protected virtual void Secure()
 {
     LifeCycle.Secure();
 }
Example #7
0
 /// <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));
         }
     }
 }
Example #8
0
 /// <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);
 }
Example #9
0
 /// <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);
 }
Example #10
0
 /// <summary>
 /// Starts the process of dispersing any messages stowed for this <c>Actor</c>.
 /// </summary>
 protected internal virtual void DisperseStowedMessages()
 {
     LifeCycle.DisperseStowedMessages();
 }