/// <summary>Re-create the actor in response to a failure.</summary> private void FaultRecreate(Exception cause) { if (_actor == null) { _systemImpl.EventStream.Publish(new Error(null, _self.Path.ToString(), GetType(), "Changing Recreate into Create after " + cause)); FaultCreate(); return; } if (IsNormal) { var failedActor = _actor; if (System.Settings.DebugLifecycle) { Publish(new Debug(_self.Path.ToString(), failedActor.GetType(), "Restarting")); } if (failedActor != null) { var optionalMessage = CurrentMessage; try { // if the actor fails in preRestart, we can do nothing but log it: it’s best-effort failedActor.AroundPreRestart(cause, optionalMessage); // run actor pre-incarnation plugin pipeline var pipeline = _systemImpl.ActorPipelineResolver.ResolvePipeline(failedActor.GetType()); pipeline.BeforeActorIncarnated(failedActor, this); } catch (Exception e) { HandleNonFatalOrInterruptedException(() => { var ex = new PreRestartException(_self, e, cause, optionalMessage); Publish(new Error(ex, _self.Path.ToString(), failedActor.GetType(), e.Message)); }); } finally { ClearActor(_actor); } } global::System.Diagnostics.Debug.Assert(Mailbox.IsSuspended(), "Mailbox must be suspended during restart, status=" + Mailbox.CurrentStatus()); if (!SetChildrenTerminationReason(new SuspendReason.Recreation(cause))) { FinishRecreate(cause, failedActor); } } else { // need to keep that suspend counter balanced FaultResume(null); } }
/* SystemMessage handling */ private int CalculateState() { if (IsWaitingForChildren) { return(SuspendedWaitForChildrenState); } if (Mailbox.IsSuspended()) { return(SuspendedState); } return(DefaultState); }
/// <summary> /// Create the actor in response to a failure /// </summary> private void FaultCreate() { global::System.Diagnostics.Debug.Assert(Mailbox.IsSuspended(), "Mailbox must be suspended during failed creation, status=" + Mailbox.CurrentStatus()); global::System.Diagnostics.Debug.Assert(_self.Equals(Perpetrator), "Perpetrator should be self"); SetReceiveTimeout(null); CancelReceiveTimeout(); // stop all children, which will turn childrenRefs into TerminatingChildrenContainer (if there are children) StopChildren(); if (!SetChildrenTerminationReason(new SuspendReason.Creation())) { FinishCreate(); } }