E
- the class of exceptions that may be thrownpublic class Retry<E extends java.lang.Exception>
extends java.lang.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 java.lang.Exception>
A runnable action that may throw an exception of type
E . |
Modifier and Type | Method and Description |
---|---|
static <E extends java.lang.Exception> |
action(Retry.Action<E> action)
Create a retryable action.
|
Retry<E> |
maximumRetries(int maximumRetries) |
Retry<E> |
retryOnException(java.util.function.Predicate<java.lang.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,
java.util.concurrent.TimeUnit unit)
Set the sleep time between retries.
|
public static <E extends java.lang.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(java.util.function.Predicate<java.lang.Exception> retryOnException)
retryOnException
- determine if provided exception is retryable.public Retry<E> sleep(long duration, java.util.concurrent.TimeUnit unit)
duration
- the time to sleepunit
- the unit of time of durationpublic boolean run() throws E extends java.lang.Exception
maximum number of
retries
(default: 5). If an exception occurs then the action will be retried providing the exception is retryable
.false
if the action was unable to
completeE
- exception thrown during the actionE extends java.lang.Exception