Package akka.japi.pf

Class DeciderBuilder


  • public class DeciderBuilder
    extends java.lang.Object
    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 Detail

      • match

        public static <P extends java.lang.Throwable> PFBuilder<java.lang.Throwable,​SupervisorStrategy.Directive> match​(java.lang.Class<P> type,
                                                                                                                              FI.Apply<P,​SupervisorStrategy.Directive> apply)
        Return a new PFBuilder with a case statement added.
        Parameters:
        type - a type to match the argument against
        apply - an action to apply to the argument if the type matches
        Returns:
        a builder with the case statement added
      • match

        public static <P extends java.lang.Throwable> PFBuilder<java.lang.Throwable,​SupervisorStrategy.Directive> match​(java.lang.Class<P> type,
                                                                                                                              FI.TypedPredicate<P> predicate,
                                                                                                                              FI.Apply<P,​SupervisorStrategy.Directive> apply)
        Return a new PFBuilder with a case statement added.
        Parameters:
        type - a type to match the argument against
        predicate - a predicate that will be evaluated on the argument if the type matches
        apply - an action to apply to the argument if the type matches and the predicate returns true
        Returns:
        a builder with the case statement added