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; }
/// <summary> /// TBD /// </summary> /// <param name="actor">TBD</param> protected void ClearActor(ActorBase actor) { if (actor != null) { if (actor is IDisposable disposable) { try { disposable.Dispose(); } catch (Exception e) { _systemImpl.Log?.Error(e, "An error occurred while disposing {0} actor. Reason: {1}", actor.GetType(), e.Message); } } ReleaseActor(actor); actor.Clear(_systemImpl.DeadLetters); } _actorHasBeenCleared = true; CurrentMessage = null; //TODO: semantics here? should all "_state" be cleared? or just behavior? _state = _state.ClearBehaviorStack(); }
/// <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()); } }
/// <summary> /// Creates a new stash for specified <paramref name="actor"/> if it has not been initialized already. /// </summary> /// <param name="actor">TBD</param> /// <param name="context">TBD</param> 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()); } }
private void LogException(ActorBase actor, Exception e, string errorMessageFormat, IActorProducerPlugin plugin) { var internalActor = (actor as IInternalActor); var actorPath = internalActor != null && internalActor.ActorContext != null ? internalActor.ActorContext.Self.Path.ToString() : string.Empty; _log.Value.Error(e, errorMessageFormat, plugin.GetType(), actor.GetType(), actorPath); }
/// <summary> /// Faults the recreate. /// </summary> /// <param name="m">The m.</param> private void FaultRecreate(Recreate m) { isTerminating = false; ActorBase failedActor = Actor; object optionalMessage = CurrentMessage; if (System.Settings.DebugLifecycle) { Publish(new Debug(Self.Path.ToString(), failedActor.GetType(), "restarting")); } try { failedActor.AroundPreRestart(m.Cause, optionalMessage); } catch (Exception e) { HandleNonFatalOrInterruptedException(() => { var ex = new PreRestartException(Self, e, m.Cause, optionalMessage); Publish(new Error(ex, Self.Path.ToString(), failedActor.GetType(), e.Message)); }); } UseThreadContext(() => { behaviorStack.Clear(); //clear earlier behaviors ActorBase created = Props.NewActor(); //ActorBase will register itself as the actor of this context if (System.Settings.DebugLifecycle) { Publish(new Debug(Self.Path.ToString(), created.GetType(), "started (" + created + ")")); } created.AroundPostRestart(m.Cause, null); }); }
/// <summary> /// Faults the recreate. /// </summary> /// <param name="m">The m.</param> private void FaultRecreate(Recreate m) { isTerminating = false; ActorBase failedActor = _actor; object optionalMessage = CurrentMessage; if (System.Settings.DebugLifecycle) { Publish(new Debug(Self.Path.ToString(), failedActor.GetType(), "restarting")); } try { failedActor.AroundPreRestart(m.Cause, optionalMessage); } catch (Exception e) { HandleNonFatalOrInterruptedException(() => { var ex = new PreRestartException(_self, e, m.Cause, optionalMessage); Publish(new Error(ex, Self.Path.ToString(), failedActor.GetType(), e.Message)); }); } var freshActor = NewActor(); _actor = freshActor; UseThreadContext(() => { Mailbox.Resume(); freshActor.AroundPostRestart(m.Cause, null); }); if (System.Settings.DebugLifecycle) { Publish(new Debug(Self.Path.ToString(), freshActor.GetType(), "restarted (" + freshActor + ")")); } }
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(); }