E - the class of exceptions that may be thrownpublic class Retry<E extends Exception> extends Object
retryable then
the action will be re-attempted. By default, any exception is considered retryable.
sleep between
retries.
is configurable (5 times by default).
| Modifier and Type | Class and Description |
|---|---|
static interface |
Retry.Action<E extends Exception>
A runnable action that may throw an exception of type
E. |
| Modifier and Type | Method and Description |
|---|---|
static <E extends Exception> |
action(Retry.Action<E> action)
Create a retryable action.
|
Retry<E> |
maximumRetries(int maximumRetries) |
Retry<E> |
retryOnException(Predicate<Exception> retryOnException)
Provide a predicate to determine if a thrown exception can be retried.
|
boolean |
run()
Run the action until it runs successfully, to a
maximum number of
retries (default: 5). |
Retry<E> |
sleep(long duration,
TimeUnit unit)
Set the sleep time between retries.
|
public static <E extends Exception> Retry<E> action(Retry.Action<E> action)
E - the class of exceptions that may be thrownaction - the action to be runpublic Retry<E> retryOnException(Predicate<Exception> retryOnException)
retryOnException - determine if provided exception is retryable.public Retry<E> sleep(long duration, TimeUnit unit)
duration - the time to sleepunit - the unit of time of durationpublic boolean run()
throws E extends Exception
maximum number of
retries (default: 5). If an exception occurs then the action will be retried providing the exception is retryable.Copyright © 2019. All rights reserved.