Class CallableUtils

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

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

    Modifier and Type Method Description
    static <T,​ R> java.util.concurrent.Callable<R> andThen​(java.util.concurrent.Callable<T> callable, java.util.function.BiFunction<T,​java.lang.Throwable,​R> handler)
    Returns a composed function that first applies the Callable and then applies BiFunction after to the result.
    static <T,​ R> java.util.concurrent.Callable<R> andThen​(java.util.concurrent.Callable<T> callable, java.util.function.Function<T,​R> resultHandler)
    Returns a composed function that first applies the Callable and then applies the resultHandler.
    static <T,​ R> java.util.concurrent.Callable<R> andThen​(java.util.concurrent.Callable<T> callable, java.util.function.Function<T,​R> resultHandler, java.util.function.Function<java.lang.Throwable,​R> exceptionHandler)
    Returns a composed function that first applies the Callable and then applies either the resultHandler or exceptionHandler.
    static <X extends java.lang.Throwable,​ T>
    java.util.concurrent.Callable<T>
    recover​(java.util.concurrent.Callable<T> callable, java.lang.Class<X> exceptionType, java.util.function.Function<java.lang.Throwable,​T> exceptionHandler)
    Returns a composed function that first executes the Callable and optionally recovers from an exception.
    static <T> java.util.concurrent.Callable<T> recover​(java.util.concurrent.Callable<T> callable, java.util.function.Function<java.lang.Throwable,​T> exceptionHandler)
    Returns a composed function that first executes the Callable and optionally recovers from an exception.
    static <T> java.util.concurrent.Callable<T> recover​(java.util.concurrent.Callable<T> callable, java.util.function.Predicate<T> resultPredicate, java.util.function.UnaryOperator<T> resultHandler)
    Returns a composed Callable that first executes the Callable and optionally recovers from a specific result.
    static <T> java.util.concurrent.Callable<T> recover​(java.util.concurrent.Callable<T> callable, java.util.List<java.lang.Class<? extends java.lang.Throwable>> exceptionTypes, java.util.function.Function<java.lang.Throwable,​T> exceptionHandler)
    Returns a composed function that first executes the Callable and optionally recovers from an exception.

    Methods inherited from class java.lang.Object

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

    • andThen

      public static <T,​ R> java.util.concurrent.Callable<R> andThen​(java.util.concurrent.Callable<T> callable, java.util.function.Function<T,​R> resultHandler)
      Returns a composed function that first applies the Callable and then applies the resultHandler.
      Type Parameters:
      T - return type of callable
      R - return type of handler
      Parameters:
      callable - the callable
      resultHandler - the function applied after callable
      Returns:
      a function composed of supplier and resultHandler
    • andThen

      public static <T,​ R> java.util.concurrent.Callable<R> andThen​(java.util.concurrent.Callable<T> callable, java.util.function.BiFunction<T,​java.lang.Throwable,​R> handler)
      Returns a composed function that first applies the Callable and then applies BiFunction after to the result.
      Type Parameters:
      T - return type of callable
      R - return type of handler
      Parameters:
      callable - the callable
      handler - the function applied after callable
      Returns:
      a function composed of supplier and handler
    • andThen

      public static <T,​ R> java.util.concurrent.Callable<R> andThen​(java.util.concurrent.Callable<T> callable, java.util.function.Function<T,​R> resultHandler, java.util.function.Function<java.lang.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 callable
      R - return type of resultHandler and exceptionHandler
      Parameters:
      callable - the callable
      resultHandler - the function applied after callable was successful
      exceptionHandler - the function applied after callable has failed
      Returns:
      a function composed of supplier and handler
    • recover

      public static <T> java.util.concurrent.Callable<T> recover​(java.util.concurrent.Callable<T> callable, java.util.function.Function<java.lang.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 exception
      exceptionHandler - the exception handler
      Returns:
      a function composed of callable and exceptionHandler
    • recover

      public static <T> java.util.concurrent.Callable<T> recover​(java.util.concurrent.Callable<T> callable, java.util.function.Predicate<T> resultPredicate, java.util.function.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 callable
      resultPredicate - the result predicate
      resultHandler - the result handler
      Returns:
      a function composed of supplier and exceptionHandler
    • recover

      public static <T> java.util.concurrent.Callable<T> recover​(java.util.concurrent.Callable<T> callable, java.util.List<java.lang.Class<? extends java.lang.Throwable>> exceptionTypes, java.util.function.Function<java.lang.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 exception
      exceptionTypes - the specific exception types that should be recovered
      exceptionHandler - the exception handler
      Returns:
      a function composed of supplier and exceptionHandler
    • recover

      public static <X extends java.lang.Throwable,​ T> java.util.concurrent.Callable<T> recover​(java.util.concurrent.Callable<T> callable, java.lang.Class<X> exceptionType, java.util.function.Function<java.lang.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 exception
      exceptionType - the specific exception type that should be recovered
      exceptionHandler - the exception handler
      Returns:
      a function composed of callable and exceptionHandler