Package io.github.resilience4j.core
Class CallableUtils
java.lang.Object
io.github.resilience4j.core.CallableUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,R> Callable<R> andThen(Callable<T> callable, BiFunction<T, Throwable, R> handler) Returns a composed function that first applies the Callable and then applies BiFunctionafterto the result.static <T,R> Callable<R> Returns a composed function that first applies the Callable and then applies the resultHandler.static <T,R> Callable<R> Returns a composed function that first applies the Callable and then applies either the resultHandler or exceptionHandler.Returns a composed function that first executes the Callable and optionally recovers from an exception.static <T> Callable<T>Returns a composed function that first executes the Callable and optionally recovers from an exception.static <T> Callable<T>recover(Callable<T> callable, Predicate<T> resultPredicate, UnaryOperator<T> resultHandler) Returns a composed Callable that first executes the Callable and optionally recovers from a specific result.static <T> Callable<T>recover(Callable<T> callable, List<Class<? extends Throwable>> exceptionTypes, Function<Throwable, T> exceptionHandler) Returns a composed function that first executes the Callable and optionally recovers from an exception.
-
Method Details
-
andThen
Returns a composed function that first applies the Callable and then applies the resultHandler.- Type Parameters:
T- return type of callableR- return type of handler- Parameters:
callable- the callableresultHandler- the function applied after callable- Returns:
- a function composed of supplier and resultHandler
-
andThen
Returns a composed function that first applies the Callable and then applies BiFunctionafterto the result.- Type Parameters:
T- return type of callableR- return type of handler- Parameters:
callable- the callablehandler- the function applied after callable- Returns:
- a function composed of supplier and handler
-
andThen
public static <T,R> Callable<R> andThen(Callable<T> callable, Function<T, R> resultHandler, Function<Throwable, R> exceptionHandler) Returns a composed function that first applies the Callable and then applies either the resultHandler or exceptionHandler.- Type Parameters:
T- return type of callableR- return type of resultHandler and exceptionHandler- Parameters:
callable- the callableresultHandler- the function applied after callable was successfulexceptionHandler- the function applied after callable has failed- Returns:
- a function composed of supplier and handler
-
recover
Returns a composed function that first executes the Callable and optionally recovers from an exception.- Type Parameters:
T- return type of after- Parameters:
callable- the callable which should be recovered from a certain exceptionexceptionHandler- the exception handler- Returns:
- a function composed of callable and exceptionHandler
-
recover
public static <T> Callable<T> recover(Callable<T> callable, Predicate<T> resultPredicate, UnaryOperator<T> resultHandler) Returns a composed Callable that first executes the Callable and optionally recovers from a specific result.- Type Parameters:
T- return type of after- Parameters:
callable- the callableresultPredicate- the result predicateresultHandler- the result handler- Returns:
- a function composed of supplier and exceptionHandler
-
recover
public static <T> Callable<T> recover(Callable<T> callable, List<Class<? extends Throwable>> exceptionTypes, Function<Throwable, T> exceptionHandler) Returns a composed function that first executes the Callable and optionally recovers from an exception.- Type Parameters:
T- return type of after- Parameters:
callable- the callable which should be recovered from a certain exceptionexceptionTypes- the specific exception types that should be recoveredexceptionHandler- the exception handler- Returns:
- a function composed of supplier and exceptionHandler
-
recover
public static <X extends Throwable,T> Callable<T> recover(Callable<T> callable, Class<X> exceptionType, Function<Throwable, T> exceptionHandler) Returns a composed function that first executes the Callable and optionally recovers from an exception.- Type Parameters:
T- return type of after- Parameters:
callable- the callable which should be recovered from a certain exceptionexceptionType- the specific exception type that should be recoveredexceptionHandler- the exception handler- Returns:
- a function composed of callable and exceptionHandler
-