Class Retries

java.lang.Object
io.atomix.client.utils.concurrent.Retries

public final class Retries extends Object
Retry utilities.
  • Method Details

    • retryAsync

      public static <T> CompletableFuture<T> retryAsync(Supplier<CompletableFuture<T>> callback, Predicate<Throwable> exceptionPredicate, Duration maxDelayBetweenRetries, ScheduledExecutorService executor)
    • retryAsync

      public static <T> CompletableFuture<T> retryAsync(Supplier<CompletableFuture<T>> callback, Predicate<Throwable> exceptionPredicate, Duration maxDelayBetweenRetries, @Nullable Duration timeout, ScheduledExecutorService executor)
    • retryAsync

      public static <T> CompletableFuture<T> retryAsync(Supplier<CompletableFuture<T>> callback, Predicate<Throwable> exceptionPredicate, int maxRetries, Duration maxDelayBetweenRetries, ScheduledExecutorService executor)
    • retryable

      public static <U, V> Function<U,V> retryable(Function<U,V> base, Class<? extends Throwable> exceptionClass, int maxRetries, int maxDelayBetweenRetries)
      Returns a function that retries execution on failure.
      Type Parameters:
      U - type of function input
      V - type of function output
      Parameters:
      base - base function
      exceptionClass - type of exception for which to retry
      maxRetries - max number of retries before giving up
      maxDelayBetweenRetries - max delay between successive retries. The actual delay is randomly picked from the interval (0, maxDelayBetweenRetries]
      Returns:
      function
    • retryable

      public static <V> Supplier<V> retryable(Supplier<V> base, Class<? extends Throwable> exceptionClass, int maxRetries, int maxDelayBetweenRetries)
      Returns a Supplier that retries execution on failure.
      Type Parameters:
      V - type of supplied result
      Parameters:
      base - base supplier
      exceptionClass - type of exception for which to retry
      maxRetries - max number of retries before giving up
      maxDelayBetweenRetries - max delay between successive retries. The actual delay is randomly picked from the interval (0, maxDelayBetweenRetries]
      Returns:
      supplier
    • randomDelay

      public static void randomDelay(int ms)
      Suspends the current thread for a random number of millis between 0 and the indicated limit.
      Parameters:
      ms - max number of millis
    • delay

      public static void delay(int ms, int nanos)
      Suspends the current thread for a specified number of millis and nanos.
      Parameters:
      ms - number of millis
      nanos - number of nanos