All Downloads are FREE. Search and download functionalities are using the official Maven repository.

akka.japi.pf.DeciderBuilder Maven / Gradle / Ivy

/*
 * Copyright (C) 2009-2020 Lightbend Inc. 
 */

package akka.japi.pf;

import static akka.actor.SupervisorStrategy.Directive;

/**
 * Used for building a partial function for {@link akka.actor.Actor#supervisorStrategy()
 * 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;
 * }
 * 
*/ public class DeciderBuilder { private DeciderBuilder() {} /** * Return a new {@link PFBuilder} with a case statement added. * * @param type a type to match the argument against * @param apply an action to apply to the argument if the type matches * @return a builder with the case statement added */ public static

PFBuilder match( final Class

type, FI.Apply apply) { return Match.match(type, apply); } /** * Return a new {@link PFBuilder} with a case statement added. * * @param type a type to match the argument against * @param predicate a predicate that will be evaluated on the argument if the type matches * @param apply an action to apply to the argument if the type matches and the predicate returns * true * @return a builder with the case statement added */ public static

PFBuilder match( final Class

type, FI.TypedPredicate

predicate, FI.Apply apply) { return Match.match(type, predicate, apply); } /** * Return a new {@link PFBuilder} with a case statement added. * * @param apply an action to apply to the argument * @return a builder with the case statement added */ public static PFBuilder matchAny(FI.Apply apply) { return Match.matchAny(apply); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy