Package akka.actor

Class SupervisorStrategy

    • Constructor Detail

      • SupervisorStrategy

        public SupervisorStrategy()
    • Method Detail

      • restart

        public static SupervisorStrategy.Restart$ restart()
        Java API: Returning this directive discards the old Actor instance and replaces it with a new, then resumes message processing.
        Returns:
        (undocumented)
      • stop

        public static SupervisorStrategy.Stop$ stop()
        Java API: Returning this directive stops the Actor
        Returns:
        (undocumented)
      • escalate

        public static SupervisorStrategy.Escalate$ escalate()
        Java API: Returning this directive escalates the failure to the supervisor of the supervisor, by rethrowing the cause of the failure, i.e. the supervisor fails with the same exception as the child.
        Returns:
        (undocumented)
      • defaultDecider

        public static final scala.PartialFunction<java.lang.Throwable,​SupervisorStrategy.Directive> defaultDecider()
        When supervisorStrategy is not specified for an actor this Decider is used by default in the supervisor strategy. The child will be stopped when ActorInitializationException, ActorKilledException, or DeathPactException is thrown. It will be restarted for other Exception types. The error is escalated if it's a Throwable, i.e. Error.
        Returns:
        (undocumented)
      • defaultStrategy

        public static final SupervisorStrategy defaultStrategy()
        When supervisorStrategy is not specified for an actor this is used by default. OneForOneStrategy with decider defined in defaultDecider().
        Returns:
        (undocumented)
      • stoppingStrategy

        public static final SupervisorStrategy stoppingStrategy()
        This strategy resembles Erlang in that failing children are always terminated (one-for-one).
        Returns:
        (undocumented)
      • seqThrowable2Decider

        public static scala.PartialFunction<java.lang.Throwable,​SupervisorStrategy.Directive> seqThrowable2Decider​(scala.collection.immutable.Seq<java.lang.Class<? extends java.lang.Throwable>> trapExit)
        Implicit conversion from Seq of Throwables to a Decider. This maps the given Throwables to restarts, otherwise escalates.
        Parameters:
        trapExit - (undocumented)
        Returns:
        (undocumented)
      • makeDecider

        public static scala.PartialFunction<java.lang.Throwable,​SupervisorStrategy.Directive> makeDecider​(scala.collection.immutable.Seq<java.lang.Class<? extends java.lang.Throwable>> trapExit)
        Decider builder which just checks whether one of the given Throwables matches the cause and restarts, otherwise escalates.
        Parameters:
        trapExit - (undocumented)
        Returns:
        (undocumented)
      • makeDecider

        public static scala.PartialFunction<java.lang.Throwable,​SupervisorStrategy.Directive> makeDecider​(java.lang.Iterable<java.lang.Class<? extends java.lang.Throwable>> trapExit)
        Decider builder which just checks whether one of the given Throwables matches the cause and restarts, otherwise escalates.
        Parameters:
        trapExit - (undocumented)
        Returns:
        (undocumented)
      • makeDecider

        public static scala.PartialFunction<java.lang.Throwable,​SupervisorStrategy.Directive> makeDecider​(scala.collection.Iterable<scala.Tuple2<java.lang.Class<? extends java.lang.Throwable>,​SupervisorStrategy.Directive>> flat)
        Decider builder for Iterables of cause-directive pairs, e.g. a map obtained from configuration; will sort the pairs so that the most specific type is checked before all its subtypes, allowing carving out subtrees of the Throwable hierarchy.
        Parameters:
        flat - (undocumented)
        Returns:
        (undocumented)
      • sort

        public static scala.collection.immutable.Seq<scala.Tuple2<java.lang.Class<? extends java.lang.Throwable>,​SupervisorStrategy.Directive>> sort​(scala.collection.Iterable<scala.Tuple2<java.lang.Class<? extends java.lang.Throwable>,​SupervisorStrategy.Directive>> in)
        Sort so that subtypes always precede their supertypes, but without obeying any order between unrelated subtypes (insert sort).

        INTERNAL API

        Parameters:
        in - (undocumented)
        Returns:
        (undocumented)
      • withinTimeRangeOption

        public static scala.Option<scala.concurrent.duration.Duration> withinTimeRangeOption​(scala.concurrent.duration.Duration withinTimeRange)
      • maxNrOfRetriesOption

        public static scala.Option<java.lang.Object> maxNrOfRetriesOption​(int maxNrOfRetries)
      • handleChildTerminated

        public abstract void handleChildTerminated​(ActorContext context,
                                                   ActorRef child,
                                                   scala.collection.Iterable<ActorRef> children)
        This method is called after the child has been removed from the set of children. It does not need to do anything special. Exceptions thrown from this method do NOT make the actor fail if this happens during termination.
        Parameters:
        context - (undocumented)
        child - (undocumented)
        children - (undocumented)
      • processFailure

        public abstract void processFailure​(ActorContext context,
                                            boolean restart,
                                            ActorRef child,
                                            java.lang.Throwable cause,
                                            ChildRestartStats stats,
                                            scala.collection.Iterable<ChildRestartStats> children)
        This method is called to act on the failure of a child: restart if the flag is true, stop otherwise.
        Parameters:
        context - (undocumented)
        restart - (undocumented)
        child - (undocumented)
        cause - (undocumented)
        stats - (undocumented)
        children - (undocumented)
      • handleFailure

        public boolean handleFailure​(ActorContext context,
                                     ActorRef child,
                                     java.lang.Throwable cause,
                                     ChildRestartStats stats,
                                     scala.collection.Iterable<ChildRestartStats> children)
        This is the main entry point: in case of a child&rsquo;s failure, this method must try to handle the failure by resuming, restarting or stopping the child (and returning true), or it returns false to escalate the failure, which will lead to this actor re-throwing the exception which caused the failure. The exception will not be wrapped.

        This method calls logFailure(akka.actor.ActorContext, akka.actor.ActorRef, java.lang.Throwable, akka.actor.SupervisorStrategy.Directive), which will log the failure unless it is escalated. You can customize the logging by setting loggingEnabled() to false and do the logging inside the decider or override the logFailure method.

        Parameters:
        children - is a lazy collection (a view)
        context - (undocumented)
        cause - (undocumented)
        stats - (undocumented)
        Returns:
        (undocumented)
      • loggingEnabled

        protected boolean loggingEnabled()
        Logging of actor failures is done when this is true.
        Returns:
        (undocumented)
      • logFailure

        public void logFailure​(ActorContext context,
                               ActorRef child,
                               java.lang.Throwable cause,
                               SupervisorStrategy.Directive decision)
        Default logging of actor failures when loggingEnabled() is true. Escalate failures are not logged here, since they are supposed to be handled at a level higher up in the hierarchy. Resume failures are logged at Warning level. Stop and Restart failures are logged at Error level.
        Parameters:
        context - (undocumented)
        child - (undocumented)
        cause - (undocumented)
        decision - (undocumented)
      • resumeChild

        public final void resumeChild​(ActorRef child,
                                      java.lang.Throwable cause)
        Resume the previously failed child: do never apply this to a child which is not the currently failing child. Suspend/resume needs to be done in matching pairs, otherwise actors will wake up too soon or never at all.
        Parameters:
        child - (undocumented)
        cause - (undocumented)
      • restartChild

        public final void restartChild​(ActorRef child,
                                       java.lang.Throwable cause,
                                       boolean suspendFirst)
        Restart the given child, possibly suspending it first.

        IMPORTANT:

        If the child is the currently failing one, it will already have been suspended, hence suspendFirst must be false. If the child is not the currently failing one, then it did not request this treatment and is therefore not prepared to be resumed without prior suspend.

        Parameters:
        child - (undocumented)
        cause - (undocumented)
        suspendFirst - (undocumented)