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