Package org.apache.pekko.japi.pf
Class DeciderBuilder
java.lang.Object
org.apache.pekko.japi.pf.DeciderBuilder
Used for building a partial function for
Actor.supervisorStrategy(). * Inside an actor you can use it like this with Java 8 to define
your supervisorStrategy.
Example:
@Override
private static SupervisorStrategy strategy =
new OneForOneStrategy(10, Duration.ofMinutes(1), DeciderBuilder.
match(ArithmeticException.class, e -> resume()).
match(NullPointerException.class, e -> restart()).
match(IllegalArgumentException.class, e -> stop()).
matchAny(o -> escalate()).build());
@Override
public SupervisorStrategy supervisorStrategy() {
return strategy;
}
-
Method Summary
Modifier and TypeMethodDescriptionstatic <P extends Throwable>
PFBuilder<Throwable,SupervisorStrategy.Directive> match(Class<P> type, Function<P, SupervisorStrategy.Directive> apply) Return a newPFBuilderwith a case statement added.static <P extends Throwable>
PFBuilder<Throwable,SupervisorStrategy.Directive> match(Class<P> type, Predicate<P> predicate, Function<P, SupervisorStrategy.Directive> apply) Return a newPFBuilderwith a case statement added.Return a newPFBuilderwith a case statement added.
-
Method Details
-
match
public static <P extends Throwable> PFBuilder<Throwable,SupervisorStrategy.Directive> match(Class<P> type, Function<P, SupervisorStrategy.Directive> apply) Return a newPFBuilderwith a case statement added.- Parameters:
type- a type to match the argument againstapply- an action to apply to the argument if the type matches- Returns:
- a builder with the case statement added
-
match
public static <P extends Throwable> PFBuilder<Throwable,SupervisorStrategy.Directive> match(Class<P> type, Predicate<P> predicate, Function<P, SupervisorStrategy.Directive> apply) Return a newPFBuilderwith a case statement added.- Parameters:
type- a type to match the argument againstpredicate- a predicate that will be evaluated on the argument if the type matchesapply- an action to apply to the argument if the type matches and the predicate returns true- Returns:
- a builder with the case statement added
-
matchAny
public static PFBuilder<Throwable,SupervisorStrategy.Directive> matchAny(Function<Throwable, SupervisorStrategy.Directive> apply) Return a newPFBuilderwith a case statement added.- Parameters:
apply- an action to apply to the argument- Returns:
- a builder with the case statement added
-