Class CompletionStageUtils

java.lang.Object
io.github.resilience4j.core.CompletionStageUtils

public class CompletionStageUtils extends Object
  • Method Details

    • recover

      public static <T> CompletionStage<T> recover(CompletionStage<T> completionStage, Function<Throwable,T> exceptionHandler)
      Returns a CompletionStage that is recovered from any exception.
      Parameters:
      completionStage - the completionStage which should be recovered from any exception
      exceptionHandler - the function applied after callable has failed
      Returns:
      a CompletionStage that is recovered from any exception.
    • recover

      public static <T> CompletionStage<T> recover(CompletionStage<T> completionStage, List<Class<? extends Throwable>> exceptionTypes, Function<Throwable,T> exceptionHandler)
      Returns a CompletionStage that is recovered from a specific exception.
      Parameters:
      completionStage - the completionStage which should be recovered from a certain exception
      exceptionTypes - the specific exception types that should be recovered
      exceptionHandler - the function applied after callable has failed
      Returns:
      a CompletionStage that is recovered from a specific exception.
    • recover

      public static <X extends Throwable, T> CompletionStage<T> recover(CompletionStage<T> completionStage, Class<X> exceptionType, Function<Throwable,T> exceptionHandler)
      Returns a CompletionStage that is recovered from a specific exception.
      Parameters:
      completionStage - the completionStage which should be recovered from a certain exception
      exceptionType - the specific exception type that should be recovered
      exceptionHandler - the function applied after callable has failed
      Returns:
      a CompletionStage that is recovered from a specific exception.
    • recover

      public static <T> Supplier<CompletionStage<T>> recover(Supplier<CompletionStage<T>> completionStageSupplier, Function<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 exception
      exceptionHandler - the function applied after callable has failed
      Returns:
      a CompletionStage that is recovered from a specific exception.
    • recover

      public static <T, X extends Throwable> Supplier<CompletionStage<T>> recover(Supplier<CompletionStage<T>> completionStageSupplier, Class<X> exceptionType, Function<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 exception
      exceptionType - the specific exception type that should be recovered
      exceptionHandler - the function applied after callable has failed
      Returns:
      a CompletionStage that is recovered from a specific exception.
    • recover

      public static <T> Supplier<CompletionStage<T>> recover(Supplier<CompletionStage<T>> completionStageSupplier, List<Class<? extends Throwable>> exceptionTypes, Function<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 exception
      exceptionTypes - the specific exception types that should be recovered
      exceptionHandler - the function applied after callable has failed
      Returns:
      a CompletionStage that is recovered from a specific exception.
    • recover

      public static <T> CompletionStage<T> recover(CompletionStage<T> completionStage, Predicate<T> resultPredicate, 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 exception
      resultPredicate - the result predicate
      resultHandler - the result handler
      Returns:
      a function composed of supplier and exceptionHandler
    • recover

      public static <T> Supplier<CompletionStage<T>> recover(Supplier<CompletionStage<T>> completionStageSupplier, Predicate<T> resultPredicate, 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 supplier
      resultPredicate - the result predicate
      resultHandler - the result handler
      Returns:
      a function composed of supplier and exceptionHandler
    • andThen

      public static <T, R> Supplier<CompletionStage<R>> andThen(Supplier<CompletionStage<T>> completionStageSupplier, BiFunction<T,Throwable,R> handler)
      Returns a composed CompletionStage that first applies the CompletionStage and then applies BiFunction after to the result.
      Type Parameters:
      T - return type of after
      Parameters:
      completionStageSupplier - the CompletionStage supplier
      handler - the function applied after supplier
      Returns:
      a function composed of supplier and handler