예제 #1
0
        //
        // Recreate
        //
        private byte[] RecreateToProto(Recreate recreate)
        {
            var message = new Proto.Msg.RecreateData();

            message.Cause = _exceptionSupport.ExceptionToProto(recreate.Cause);
            return(message.ToByteArray());
        }
        public void Can_serialize_Recreate_WithInnerException()
        {
            var message = new Recreate(new ArgumentException("test1", new ArgumentNullException()));
            var actual  = AssertAndReturn(message);

            actual.Cause.Should().BeOfType <ArgumentException>();
            actual.Cause.Message.Should().Be(message.Cause.Message);
        }
 public void Can_serialize_Recreate_WithStackTrace()
 {
     try
     {
         throw new ArgumentException("test1");
     }
     catch (Exception e)
     {
         var message = new Recreate(e);
         var actual  = AssertAndReturn(message);
         actual.Cause.Should().BeOfType <ArgumentException>();
         actual.Cause.Message.Should().Be(message.Cause.Message);
     }
 }
        /// <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 + ")"));
            }
        }