#19246 Auto and manual reset and BackoffOptions.

Also moved `TransparantExponentialBackoffSupervisor` to `akka.pattern` (renamed to `BackoffOnRestartSupervisor`)
This commit is contained in:
Raymond Roestenburg 2015-12-23 20:18:19 +02:00
parent 2bade93c31
commit 2404a9da01
12 changed files with 808 additions and 441 deletions

View file

@ -4,6 +4,7 @@
package docs.pattern;
import akka.actor.*;
import akka.pattern.Backoff;
import akka.pattern.BackoffSupervisor;
import akka.testkit.TestActors.EchoActor;
//#backoff-imports
@ -14,19 +15,35 @@ import java.util.concurrent.TimeUnit;
public class BackoffSupervisorDocTest {
void example (ActorSystem system) {
//#backoff
void exampleStop (ActorSystem system) {
//#backoff-stop
final Props childProps = Props.create(EchoActor.class);
final Props supervisorProps = BackoffSupervisor.props(
childProps,
"myEcho",
Duration.create(3, TimeUnit.SECONDS),
Duration.create(30, TimeUnit.SECONDS),
0.2); // adds 20% "noise" to vary the intervals slightly
Backoff.onStop(
childProps,
"myEcho",
Duration.create(3, TimeUnit.SECONDS),
Duration.create(30, TimeUnit.SECONDS),
0.2)); // adds 20% "noise" to vary the intervals slightly
system.actorOf(supervisorProps, "echoSupervisor");
//#backoff
//#backoff-stop
}
void exampleFailure (ActorSystem system) {
//#backoff-fail
final Props childProps = Props.create(EchoActor.class);
final Props supervisorProps = BackoffSupervisor.props(
Backoff.onFailure(
childProps,
"myEcho",
Duration.create(3, TimeUnit.SECONDS),
Duration.create(30, TimeUnit.SECONDS),
0.2)); // adds 20% "noise" to vary the intervals slightly
system.actorOf(supervisorProps, "echoSupervisor");
//#backoff-fail
}
}