Class SupervisorStrategy
- java.lang.Object
-
- akka.actor.typed.SupervisorStrategy
-
- Direct Known Subclasses:
BackoffSupervisorStrategy
,RestartSupervisorStrategy
public abstract class SupervisorStrategy extends java.lang.Object
Not for user extension
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SupervisorStrategy.Backoff$
static class
SupervisorStrategy.Restart$
static interface
SupervisorStrategy.RestartOrBackoff
INTERNAL APIstatic class
SupervisorStrategy.Resume$
static class
SupervisorStrategy.Stop$
-
Constructor Summary
Constructors Constructor Description SupervisorStrategy()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract boolean
loggingEnabled()
abstract org.slf4j.event.Level
logLevel()
static RestartSupervisorStrategy
restart()
Restart immediately without any limit on number of restart retries.static BackoffSupervisorStrategy
restartWithBackoff(java.time.Duration minBackoff, java.time.Duration maxBackoff, double randomFactor)
Java API: It supports exponential back-off between the givenminBackoff
andmaxBackoff
durations.static BackoffSupervisorStrategy
restartWithBackoff(scala.concurrent.duration.FiniteDuration minBackoff, scala.concurrent.duration.FiniteDuration maxBackoff, double randomFactor)
Scala API: It supports exponential back-off between the givenminBackoff
andmaxBackoff
durations.static SupervisorStrategy
resume()
Resume means keeping the same state as before the exception was thrown and is thus less safe thanrestart
.static SupervisorStrategy
stop()
Stop the actorabstract SupervisorStrategy
withLoggingEnabled(boolean enabled)
abstract SupervisorStrategy
withLogLevel(org.slf4j.event.Level level)
-
-
-
Method Detail
-
resume
public static SupervisorStrategy resume()
Resume means keeping the same state as before the exception was thrown and is thus less safe thanrestart
.If the actor behavior is deferred and throws an exception on startup the actor is stopped (restarting would be dangerous as it could lead to an infinite restart-loop)
-
restart
public static RestartSupervisorStrategy restart()
Restart immediately without any limit on number of restart retries. A limit can be added withRestartSupervisorStrategy.withLimit
.If the actor behavior is deferred and throws an exception on startup the actor is stopped (restarting would be dangerous as it could lead to an infinite restart-loop)
-
stop
public static SupervisorStrategy stop()
Stop the actor
-
restartWithBackoff
public static BackoffSupervisorStrategy restartWithBackoff(scala.concurrent.duration.FiniteDuration minBackoff, scala.concurrent.duration.FiniteDuration maxBackoff, double randomFactor)
Scala API: It supports exponential back-off between the givenminBackoff
andmaxBackoff
durations. For example, ifminBackoff
is 3 seconds andmaxBackoff
30 seconds the start attempts will be delayed with 3, 6, 12, 24, 30, 30 seconds. The exponential back-off counter is reset if the actor is not terminated within theminBackoff
duration.In addition to the calculated exponential back-off an additional random delay based the given
randomFactor
is added, e.g. 0.2 adds up to 20% delay. The reason for adding a random delay is to avoid that all failing actors hit the backend resource at the same time.During the back-off incoming messages are dropped.
If no new exception occurs within
(minBackoff + maxBackoff) / 2
the exponentially increased back-off timeout is reset. This can be overridden by explicitly settingresetBackoffAfter
usingwithResetBackoffAfter
on the returned strategy.The strategy is applied also if the actor behavior is deferred and throws an exception during startup.
A maximum number of restarts can be specified with
BackoffSupervisorStrategy.withMaxRestarts(int)
- Parameters:
minBackoff
- minimum (initial) duration until the child actor will started again, if it is terminatedmaxBackoff
- the exponential back-off is capped to this durationrandomFactor
- after calculation of the exponential back-off an additional random delay based on this factor is added, e.g.0.2
adds up to20%
delay. In order to skip this additional delay pass in0
.
-
restartWithBackoff
public static BackoffSupervisorStrategy restartWithBackoff(java.time.Duration minBackoff, java.time.Duration maxBackoff, double randomFactor)
Java API: It supports exponential back-off between the givenminBackoff
andmaxBackoff
durations. For example, ifminBackoff
is 3 seconds andmaxBackoff
30 seconds the start attempts will be delayed with 3, 6, 12, 24, 30, 30 seconds. The exponential back-off counter is reset if the actor is not terminated within theminBackoff
duration.In addition to the calculated exponential back-off an additional random delay based the given
randomFactor
is added, e.g. 0.2 adds up to 20% delay. The reason for adding a random delay is to avoid that all failing actors hit the backend resource at the same time.During the back-off incoming messages are dropped.
If no new exception occurs within
(minBackoff + maxBackoff) / 2
the exponentially increased back-off timeout is reset. This can be overridden by explicitly settingresetBackoffAfter
usingwithResetBackoffAfter
on the returned strategy.The strategy is applied also if the actor behavior is deferred and throws an exception during startup.
- Parameters:
minBackoff
- minimum (initial) duration until the child actor will started again, if it is terminatedmaxBackoff
- the exponential back-off is capped to this durationrandomFactor
- after calculation of the exponential back-off an additional random delay based on this factor is added, e.g.0.2
adds up to20%
delay. In order to skip this additional delay pass in0
.
-
loggingEnabled
public abstract boolean loggingEnabled()
-
logLevel
public abstract org.slf4j.event.Level logLevel()
-
withLoggingEnabled
public abstract SupervisorStrategy withLoggingEnabled(boolean enabled)
-
withLogLevel
public abstract SupervisorStrategy withLogLevel(org.slf4j.event.Level level)
-
-