Class ActorBase.
예제 #1
0
 /// <summary>
 /// Ensures, that all stashed messages inside <paramref name="actor"/> stash have been unstashed.
 /// </summary>
 public override void BeforeIncarnated(ActorBase actor, IActorContext context)
 {
     var actorStash = actor as IActorStash;
     if (actorStash != null)
     {
         actorStash.Stash.UnstashAll();
     }
 }
예제 #2
0
 /// <summary>
 /// Creates a new stash for specified <paramref name="actor"/> if it has not been initialized already.
 /// </summary>
 public override void AfterIncarnated(ActorBase actor, IActorContext context)
 {
     var stashed = actor as IActorStash;
     if (stashed != null && stashed.Stash == null)
     {
         stashed.Stash = context.CreateStash(actor.GetType());
     }
 }
예제 #3
0
 public FailingChildInnerActor(ActorBase fail)
     : base(fail)
 {
     Fail = new InnerActor();
 }
예제 #4
0
 public FailingInnerActor(ActorBase fail)
 {
     Fail = fail;
 }
예제 #5
0
 protected void UnwatchWatchedActors(ActorBase actor)
 {
     if (!_watchedBy.Any()) return;
     MaintainAddressTerminatedSubscription(() =>
     {
         try
         {
             foreach ( // ➡➡➡ NEVER SEND THE SAME SYSTEM MESSAGE OBJECT TO TWO ACTORS
                 var watchee in _watching.OfType<InternalActorRef>())
                 watchee.Tell(new Unwatch(watchee, Self));
         }
         finally
         {
             _watching = new HashSet<ActorRef>();
             _terminatedQueue = new HashSet<ActorRef>();
         }
     });
 }
예제 #6
0
 protected void SetActorFields(ActorBase actor)
 {
     if (actor != null)
     {
         actor.Unclear();
     }
 }
예제 #7
0
        protected void ClearActor(ActorBase actor)
        {
            if (actor != null)
            {
                var disposable = actor as IDisposable;
                if (disposable != null)
                {
                    try
                    {
                        disposable.Dispose();
                    }
                    catch (Exception e)
                    {
                        if (_systemImpl.Log != null)
                        {
                            _systemImpl.Log.Error(e, "An error occurred while disposing {0} actor. Reason: {1}", 
                                actor.GetType(), e.Message);
                        }
                    }
                }

                actor.Clear(_systemImpl.DeadLetters);
            }
            _actorHasBeenCleared = true;
            CurrentMessage = null;

            //TODO: semantics here? should all "_state" be cleared? or just behavior?
            _state = _state.ClearBehaviorStack();
        }
예제 #8
0
 public void Release(ActorBase actor)
 {
     actor = null;
 }
        private void FinishRecreate(Exception cause, ActorBase failedActor)
        {
            // need to keep a snapshot of the surviving children before the new actor instance creates new ones
            var survivors = ChildrenContainer.Children;
            try
            {
                try { ResumeNonRecursive(); }
                finally { ClearFailed(); }  // must happen in any case, so that failure is propagated

                var freshActor = NewActor();
                _actor = freshActor; // this must happen before postRestart has a chance to fail
                if (ReferenceEquals(freshActor, failedActor))
                    SetActorFields(freshActor); // If the creator returns the same instance, we need to restore our nulled out fields.

                UseThreadContext(() => freshActor.AroundPostRestart(cause, null));

                if (System.Settings.DebugLifecycle)
                    Publish(new Debug(_self.Path.ToString(), freshActor.GetType(), "Restarted (" + freshActor + ")"));

                // only after parent is up and running again do restart the children which were not stopped
                foreach (var survivingChild in survivors)
                {
                    try
                    {
                        survivingChild.Restart(cause);
                    }
                    catch (Exception e)
                    {
                        var child = survivingChild;    //Needed since otherwise it would be access to foreach variable in closure
                        HandleNonFatalOrInterruptedException(() => Publish(new Error(e, _self.Path.ToString(), freshActor.GetType(), "restarting (" + child + ")")));
                    }
                }
            }
            catch (Exception e)
            {
                ClearActor(_actor); // in order to prevent preRestart() from happening again
                HandleInvokeFailure(new PostRestartException(_self, e, cause), survivors);
            }

        }
예제 #10
0
 /// <summary>
 /// Signals the container that it can release its reference to the actor.
 /// </summary>
 /// <param name="actor">The actor to remove from the container.</param>
 public void Release(ActorBase actor)
 {
     dependencyResolver.Release(actor);
 }
예제 #11
0
 /// <summary>
 ///     Unwatches the watched actors.
 /// </summary>
 /// <param name="actorBase">The actor base.</param>
 private void UnwatchWatchedActors(ActorBase actorBase)
 {
     try
     {
         foreach (ActorRef watchee in watchees)
         {
             watchee.Tell(new Unwatch(watchee, Self));
         }
     }
     finally
     {
         watchees.Clear();
         terminatedQueue.Clear();
     }
 }
예제 #12
0
 /// <summary>
 /// Plugin behavior applied to <paramref name="actor"/> instance before the actor is being recycled.
 /// </summary>
 /// <param name="actor">TBD</param>
 /// <param name="context">TBD</param>
 public virtual void BeforeIncarnated(ActorBase actor, IActorContext context)
 {
 }
예제 #13
0
 /// <summary>
 /// Plugin behavior applied to <paramref name="actor"/> instance when the new one is being created.
 /// </summary>
 /// <param name="actor">TBD</param>
 /// <param name="context">TBD</param>
 public virtual void AfterIncarnated(ActorBase actor, IActorContext context)
 {
 }
예제 #14
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="actor">TBD</param>
 protected void SetActorFields(ActorBase actor)
 {
     actor?.Unclear();
 }
예제 #15
0
 private void ReleaseActor(ActorBase a)
 {
     _props.Release(a);
 }
예제 #16
0
 public FailingOuterActor(ActorRef inner)
 {
     _inner = inner;
     Fail = new InnerActor();
 }
 private void ReleaseActor(ActorBase a)
 {
     _props.Release(a);
 }
예제 #18
0
 public void Release(ActorBase actor)
 {
     actor = null;
 }
        protected void UnwatchWatchedActors(ActorBase actor)
        {
            var watching = _state
                .GetWatching()
                .ToList();

            if (!watching.Any()) return;

            MaintainAddressTerminatedSubscription(() =>
            {
                try
                {
                    // ➡➡➡ NEVER SEND THE SAME SYSTEM MESSAGE OBJECT TO TWO ACTORS
                    foreach (var watchee in watching.OfType<IInternalActorRef>())
                        watchee.Tell(new Unwatch(watchee, Self));
                }
                finally
                {
                    _state = _state.ClearWatching();
                    _state = _state.ClearTerminated();
                }
            });
        }
예제 #20
0
        protected void ClearActor(ActorBase actor)
        {
            if (actor != null)
            {
                var disposable = actor as IDisposable;
                if (disposable != null)
                {
                    try
                    {
                        disposable.Dispose();
                    }
                    catch (Exception e)
                    {
                        if (_systemImpl.Log != null)
                        {
                            _systemImpl.Log.Error(e, "An error occurred while disposing {0} actor. Reason: {1}", 
                                actor.GetType(), e.Message);
                        }
                    }
                }

                actor.Clear(_systemImpl.DeadLetters);
            }
            _actorHasBeenCleared = true;
            CurrentMessage = null;
            behaviorStack = null;
        }