Ejemplo n.º 1
0
 protected string CauseToString(string prefix = "Cause: ")
 {
     if (_causedByFailure == null)
     {
         return("");
     }
     return(ExceptionFormatter.DebugFormat(_causedByFailure, prefix));
 }
Ejemplo n.º 2
0
        private Actor CreateActorInstance(Exception recreateCause = null)
        {
            try
            {
                _messageHandlerStack = ImmutableStack <MessageHandler> .Empty;
                var actor = NewActorInstance();
                actor.Init(this);                 //Init is idempotent so even if NewActorInstance() returns the same instance again this call is safe to make.
                _actorStatus = ActorStatus.Normal;

                //if _messageHandlers, still is empty, it means we had no Becomes in the constructor, use default-handling, i.e. HandleMessage
                if (_messageHandlerStack.IsEmpty)
                {
                    _messageHandlerStack = _messageHandlerStack.Push((m, s) => actor.HandleMessage(m, s));
                }

                actor.PreStart();
                var isFirstStart = recreateCause == null;
                if (_system.Settings.DebugLifecycle)
                {
                    Publish(new DebugLogEvent(_path.ToString(), SafeGetTypeForLogging(actor), isFirstStart ? "Started (" + actor + ")" : "Restarted (" + actor + ") due to " + ExceptionFormatter.DebugFormat(recreateCause)));
                }
                if (isFirstStart)
                {
                    actor.PreFirstStart();
                }
                else
                {
                    actor.PostRestart(recreateCause);
                }
                return(actor);
            }
            catch (Exception ex)
            {
                throw new CreateActorFailedException(this, "An error occured while creating the actor. See inner exception", ex);
            }
        }