Class Retries
java.lang.Object
io.atomix.client.utils.concurrent.Retries
Retry utilities.
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 Details
-
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
-