/// <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(); } }
/// <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()); } }
public FailingChildInnerActor(ActorBase fail) : base(fail) { Fail = new InnerActor(); }
public FailingInnerActor(ActorBase fail) { Fail = fail; }
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>(); } }); }
protected void SetActorFields(ActorBase actor) { if (actor != null) { actor.Unclear(); } }
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(); }
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); } }
/// <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); }
/// <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(); } }
/// <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) { }
/// <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) { }
/// <summary> /// TBD /// </summary> /// <param name="actor">TBD</param> protected void SetActorFields(ActorBase actor) { actor?.Unclear(); }
private void ReleaseActor(ActorBase a) { _props.Release(a); }
public FailingOuterActor(ActorRef inner) { _inner = inner; Fail = new InnerActor(); }
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(); } }); }
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; }