Class PreRestartException.
Inheritance: AkkaException
        /// <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);

                        //if the actor uses a stash Unstash all messages.
                        //If the user do not want this behavior, the stash should be cleared in PreRestart
                        //either by calling ClearStash or by calling UnstashAll.
                        UnstashAllActorMessages(failedActor);
                    }
                    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.Status);
                if (!SetChildrenTerminationReason(new SuspendReason.Recreation(cause)))
                {
                    FinishRecreate(cause, failedActor);
                }
            }
            else
            {
                // need to keep that suspend counter balanced
                FaultResume(null);
            }
        }
Example #2
0
        /// <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);
            }
        }
        /// <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.Status);
                if (!SetChildrenTerminationReason(new SuspendReason.Recreation(cause)))
                {
                    FinishRecreate(cause, failedActor);
                }
            }
            else
            {
                // need to keep that suspend counter balanced
                FaultResume(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));
                });
            }

            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 + ")"));
            }
        }
        /// <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 + ")"));
        }
        /// <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);
            });
        }