public abstract class SupervisorStrategy
extends java.lang.Object
IMPORTANT:
You should not normally need to create new subclasses, instead use the
existing OneForOneStrategy
or AllForOneStrategy
,
but if you do, please read the docs of the methods below carefully, as
incorrect implementations may lead to “blocked” actor systems (i.e.
permanently suspended actors).
Modifier and Type | Class and Description |
---|---|
static interface |
SupervisorStrategy.Directive |
static class |
SupervisorStrategy.Escalate$
Escalates the failure to the supervisor of the supervisor,
by rethrowing the cause of the failure, i.e.
|
static class |
SupervisorStrategy.Restart$
Discards the old Actor instance and replaces it with a new,
then resumes message processing.
|
static class |
SupervisorStrategy.Resume$
Resumes message processing for the failed Actor
|
static class |
SupervisorStrategy.Stop$
Stops the Actor
|
Constructor and Description |
---|
SupervisorStrategy() |
Modifier and Type | Method and Description |
---|---|
abstract scala.PartialFunction<java.lang.Throwable,SupervisorStrategy.Directive> |
decider()
Returns the Decider that is associated with this SupervisorStrategy.
|
static 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. |
static SupervisorStrategy |
defaultStrategy()
When supervisorStrategy is not specified for an actor this
is used by default.
|
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.
|
static scala.Function1<java.lang.Object,SupervisorStrategy.Escalate$> |
escalateDefault() |
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.
|
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’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. |
void |
logFailure(ActorContext context,
ActorRef child,
java.lang.Throwable cause,
SupervisorStrategy.Directive decision)
Default logging of actor failures when
loggingEnabled() is true . |
protected boolean |
loggingEnabled()
Logging of actor failures is done when this is
true . |
static scala.PartialFunction<java.lang.Throwable,SupervisorStrategy.Directive> |
makeDecider(Function<java.lang.Throwable,SupervisorStrategy.Directive> func)
Converts a Java Decider into a Scala Decider
|
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.
|
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.
|
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.
|
static scala.Option<java.lang.Object> |
maxNrOfRetriesOption(int maxNrOfRetries) |
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.
|
static SupervisorStrategy.Restart$ |
restart()
Java API: Returning this directive discards the old Actor instance and replaces it with a new,
then resumes message processing.
|
void |
restartChild(ActorRef child,
java.lang.Throwable cause,
boolean suspendFirst)
Restart the given child, possibly suspending it first.
|
static SupervisorStrategy.Resume$ |
resume()
Java API: Returning this directive resumes message processing for the failed Actor
|
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.
|
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 . |
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).
|
static SupervisorStrategy.Stop$ |
stop()
Java API: Returning this directive stops the Actor
|
static SupervisorStrategy |
stoppingStrategy()
This strategy resembles Erlang in that failing children are always
terminated (one-for-one).
|
static scala.Option<scala.concurrent.duration.Duration> |
withinTimeRangeOption(scala.concurrent.duration.Duration withinTimeRange) |
public static SupervisorStrategy.Resume$ resume()
public static SupervisorStrategy.Restart$ restart()
public static SupervisorStrategy.Stop$ stop()
public static SupervisorStrategy.Escalate$ escalate()
public static final scala.PartialFunction<java.lang.Throwable,SupervisorStrategy.Directive> defaultDecider()
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
.public static final SupervisorStrategy defaultStrategy()
defaultDecider()
.public static final SupervisorStrategy stoppingStrategy()
public static scala.PartialFunction<java.lang.Throwable,SupervisorStrategy.Directive> seqThrowable2Decider(scala.collection.immutable.Seq<java.lang.Class<? extends java.lang.Throwable>> trapExit)
Seq
of Throwables to a Decider
.
This maps the given Throwables to restarts, otherwise escalates.trapExit
- (undocumented)public static scala.PartialFunction<java.lang.Throwable,SupervisorStrategy.Directive> makeDecider(scala.collection.immutable.Seq<java.lang.Class<? extends java.lang.Throwable>> trapExit)
trapExit
- (undocumented)public static scala.PartialFunction<java.lang.Throwable,SupervisorStrategy.Directive> makeDecider(java.lang.Iterable<java.lang.Class<? extends java.lang.Throwable>> trapExit)
trapExit
- (undocumented)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)
flat
- (undocumented)public static scala.PartialFunction<java.lang.Throwable,SupervisorStrategy.Directive> makeDecider(Function<java.lang.Throwable,SupervisorStrategy.Directive> func)
func
- (undocumented)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)
INTERNAL API
in
- (undocumented)public static scala.Option<scala.concurrent.duration.Duration> withinTimeRangeOption(scala.concurrent.duration.Duration withinTimeRange)
public static scala.Option<java.lang.Object> maxNrOfRetriesOption(int maxNrOfRetries)
public static scala.Function1<java.lang.Object,SupervisorStrategy.Escalate$> escalateDefault()
public abstract scala.PartialFunction<java.lang.Throwable,SupervisorStrategy.Directive> decider()
handleFailure
to obtain the Directive to be applied.public abstract void handleChildTerminated(ActorContext context, ActorRef child, scala.collection.Iterable<ActorRef> children)
context
- (undocumented)child
- (undocumented)children
- (undocumented)public abstract void processFailure(ActorContext context, boolean restart, ActorRef child, java.lang.Throwable cause, ChildRestartStats stats, scala.collection.Iterable<ChildRestartStats> children)
context
- (undocumented)restart
- (undocumented)child
- (undocumented)cause
- (undocumented)stats
- (undocumented)children
- (undocumented)public boolean handleFailure(ActorContext context, ActorRef child, java.lang.Throwable cause, ChildRestartStats stats, scala.collection.Iterable<ChildRestartStats> children)
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.
children
- is a lazy collection (a view)context
- (undocumented)cause
- (undocumented)stats
- (undocumented)protected boolean loggingEnabled()
true
.public void logFailure(ActorContext context, ActorRef child, java.lang.Throwable cause, SupervisorStrategy.Directive decision)
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.context
- (undocumented)child
- (undocumented)cause
- (undocumented)decision
- (undocumented)public final void resumeChild(ActorRef child, java.lang.Throwable cause)
child
- (undocumented)cause
- (undocumented)public final void restartChild(ActorRef child, java.lang.Throwable cause, boolean suspendFirst)
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.
child
- (undocumented)cause
- (undocumented)suspendFirst
- (undocumented)