Package io.atomix.utils.concurrent
Class Retries
- java.lang.Object
-
- io.atomix.utils.concurrent.Retries
-
public final class Retries extends Object
Retry utilities.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voiddelay(int ms, int nanos)Suspends the current thread for a specified number of millis and nanos.static voidrandomDelay(int ms)Suspends the current thread for a random number of millis between 0 and the indicated limit.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.static <V> Supplier<V>retryable(Supplier<V> base, Class<? extends Throwable> exceptionClass, int maxRetries, int maxDelayBetweenRetries)Returns a Supplier that retries execution on failure.
-
-
-
Method Detail
-
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 inputV- type of function output- Parameters:
base- base functionexceptionClass- type of exception for which to retrymaxRetries- max number of retries before giving upmaxDelayBetweenRetries- 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 supplierexceptionClass- type of exception for which to retrymaxRetries- max number of retries before giving upmaxDelayBetweenRetries- 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 millisnanos- number of nanos
-
-