Class CompletionStageUtils


  • public class CompletionStageUtils
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      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 BiFunction after 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • 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 exception
        exceptionHandler - 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 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 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 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> 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 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 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 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> 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 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> 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 exception
        resultPredicate - the result predicate
        resultHandler - 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 supplier
        resultPredicate - the result predicate
        resultHandler - 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 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