Package io.github.resilience4j.core
Class CompletionStageUtils
java.lang.Object
io.github.resilience4j.core.CompletionStageUtils
public class CompletionStageUtils
extends java.lang.Object
-
Method Summary
Modifier and Type Method Description static <T, R> java.util.function.Supplier<java.util.concurrent.CompletionStage<R>>
andThen(java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> completionStageSupplier, java.util.function.BiFunction<T,java.lang.Throwable,R> handler)
Returns a composed CompletionStage that first applies the CompletionStage and then applies BiFunctionafter
to the result.static <X extends java.lang.Throwable, T>
java.util.concurrent.CompletionStage<T>recover(java.util.concurrent.CompletionStage<T> completionStage, java.lang.Class<X> exceptionType, java.util.function.Function<java.lang.Throwable,T> exceptionHandler)
Returns a CompletionStage that is recovered from a specific exception.static <T> java.util.concurrent.CompletionStage<T>
recover(java.util.concurrent.CompletionStage<T> completionStage, java.util.function.Function<java.lang.Throwable,T> exceptionHandler)
Returns a CompletionStage that is recovered from any exception.static <T> java.util.concurrent.CompletionStage<T>
recover(java.util.concurrent.CompletionStage<T> completionStage, java.util.function.Predicate<T> resultPredicate, java.util.function.UnaryOperator<T> resultHandler)
Returns a composed CompletionStage that first executes the CompletionStage and optionally recovers from a specific result.static <T> java.util.concurrent.CompletionStage<T>
recover(java.util.concurrent.CompletionStage<T> completionStage, java.util.List<java.lang.Class<? extends java.lang.Throwable>> exceptionTypes, java.util.function.Function<java.lang.Throwable,T> exceptionHandler)
Returns a CompletionStage that is recovered from a specific exception.static <T, X extends java.lang.Throwable>
java.util.function.Supplier<java.util.concurrent.CompletionStage<T>>recover(java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> completionStageSupplier, java.lang.Class<X> exceptionType, java.util.function.Function<java.lang.Throwable,T> exceptionHandler)
Returns a decorated CompletionStage that is recovered from a specific exception.static <T> java.util.function.Supplier<java.util.concurrent.CompletionStage<T>>
recover(java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> completionStageSupplier, java.util.function.Function<java.lang.Throwable,T> exceptionHandler)
Returns a decorated CompletionStage that is recovered from a specific exception.static <T> java.util.function.Supplier<java.util.concurrent.CompletionStage<T>>
recover(java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> completionStageSupplier, java.util.function.Predicate<T> resultPredicate, java.util.function.UnaryOperator<T> resultHandler)
Returns a composed CompletionStage that first executes the CompletionStage and optionally recovers from a specific result.static <T> java.util.function.Supplier<java.util.concurrent.CompletionStage<T>>
recover(java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> completionStageSupplier, java.util.List<java.lang.Class<? extends java.lang.Throwable>> exceptionTypes, java.util.function.Function<java.lang.Throwable,T> exceptionHandler)
Returns a decorated CompletionStage that is recovered from a specific exception.
-
Method Details
-
recover
public static <T> java.util.concurrent.CompletionStage<T> recover(java.util.concurrent.CompletionStage<T> completionStage, java.util.function.Function<java.lang.Throwable,T> exceptionHandler)Returns a CompletionStage that is recovered from any exception.- Parameters:
completionStage
- the completionStage which should be recovered from any exceptionexceptionHandler
- the function applied after callable has failed- Returns:
- a CompletionStage that is recovered from any exception.
-
recover
public static <T> java.util.concurrent.CompletionStage<T> recover(java.util.concurrent.CompletionStage<T> completionStage, java.util.List<java.lang.Class<? extends java.lang.Throwable>> exceptionTypes, java.util.function.Function<java.lang.Throwable,T> exceptionHandler)Returns a CompletionStage that is recovered from a specific exception.- Parameters:
completionStage
- the completionStage which should be recovered from a certain exceptionexceptionTypes
- the specific exception types that should be recoveredexceptionHandler
- the function applied after callable has failed- Returns:
- a CompletionStage that is recovered from a specific exception.
-
recover
public static <X extends java.lang.Throwable, T> java.util.concurrent.CompletionStage<T> recover(java.util.concurrent.CompletionStage<T> completionStage, java.lang.Class<X> exceptionType, java.util.function.Function<java.lang.Throwable,T> exceptionHandler)Returns a CompletionStage that is recovered from a specific exception.- Parameters:
completionStage
- the completionStage which should be recovered from a certain exceptionexceptionType
- the specific exception type that should be recoveredexceptionHandler
- the function applied after callable has failed- Returns:
- a CompletionStage that is recovered from a specific exception.
-
recover
public static <T> java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> recover(java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> completionStageSupplier, java.util.function.Function<java.lang.Throwable,T> exceptionHandler)Returns a decorated CompletionStage that is recovered from a specific exception.- Parameters:
completionStageSupplier
- a supplier of the completionStage which should be recovered from a certain exceptionexceptionHandler
- the function applied after callable has failed- Returns:
- a CompletionStage that is recovered from a specific exception.
-
recover
public static <T, X extends java.lang.Throwable> java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> recover(java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> completionStageSupplier, java.lang.Class<X> exceptionType, java.util.function.Function<java.lang.Throwable,T> exceptionHandler)Returns a decorated CompletionStage that is recovered from a specific exception.- Parameters:
completionStageSupplier
- a supplier of the completionStage which should be recovered from a certain exceptionexceptionType
- the specific exception type that should be recoveredexceptionHandler
- the function applied after callable has failed- Returns:
- a CompletionStage that is recovered from a specific exception.
-
recover
public static <T> java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> recover(java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> completionStageSupplier, java.util.List<java.lang.Class<? extends java.lang.Throwable>> exceptionTypes, java.util.function.Function<java.lang.Throwable,T> exceptionHandler)Returns a decorated CompletionStage that is recovered from a specific exception.- Parameters:
completionStageSupplier
- a supplier of the completionStage which should be recovered from a certain exceptionexceptionTypes
- the specific exception types that should be recoveredexceptionHandler
- the function applied after callable has failed- Returns:
- a CompletionStage that is recovered from a specific exception.
-
recover
public static <T> java.util.concurrent.CompletionStage<T> recover(java.util.concurrent.CompletionStage<T> completionStage, java.util.function.Predicate<T> resultPredicate, java.util.function.UnaryOperator<T> resultHandler)Returns a composed CompletionStage that first executes the CompletionStage and optionally recovers from a specific result.- Type Parameters:
T
- return type of after- Parameters:
completionStage
- the completionStage which should be recovered from a certain exceptionresultPredicate
- the result predicateresultHandler
- the result handler- Returns:
- a function composed of supplier and exceptionHandler
-
recover
public static <T> java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> recover(java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> completionStageSupplier, java.util.function.Predicate<T> resultPredicate, java.util.function.UnaryOperator<T> resultHandler)Returns a composed CompletionStage that first executes the CompletionStage and optionally recovers from a specific result.- Type Parameters:
T
- return type of after- Parameters:
completionStageSupplier
- the CompletionStage supplierresultPredicate
- the result predicateresultHandler
- the result handler- Returns:
- a function composed of supplier and exceptionHandler
-
andThen
public static <T, R> java.util.function.Supplier<java.util.concurrent.CompletionStage<R>> andThen(java.util.function.Supplier<java.util.concurrent.CompletionStage<T>> completionStageSupplier, java.util.function.BiFunction<T,java.lang.Throwable,R> handler)Returns a composed CompletionStage that first applies the CompletionStage and then applies BiFunctionafter
to the result.- Type Parameters:
T
- return type of after- Parameters:
completionStageSupplier
- the CompletionStage supplierhandler
- the function applied after supplier- Returns:
- a function composed of supplier and handler
-