public final class Retry
extends java.lang.Object
Retry.withExpBackoff(1, 10, 5)
.retryingOn(FooException.class)
.throwingOn(RuntimeException.class).run(() -> {
//Do stuff here.
}
The above will retry the code in the block up to 5 times if it throws FooException. If it throws
a RuntimeException or returns successfully it will throw or return immediately. The delay
following each of the filed attempts would be 1, 10, 100, 1000, and 10000ms respectively. If all
retries fail RetriesExhaustedException will be thrown.
Note that the class is not a builder object, so the methods in the chain must be invoked in order. The intermediate objects in the chain are reusable and threadsafe, so they can be shared between invocations.
In the event that the exception passed to retryingOn() and throwingOn() are related. i.e. In the above example if FooException were to extend RuntimeException. Then the more specific exception is given preference. (In the above case FooException would be retried).
| Modifier and Type | Class and Description |
|---|---|
static interface |
Retry.Retryable<ReturnT,RetryableET extends java.lang.Exception,NonRetryableET extends java.lang.Exception> |
static class |
Retry.RetryAndThrowBase<ThrowsT extends java.lang.Exception> |
static class |
Retry.RetryAndThrowConditionally
Returned by
Retry.RetryExceptionally.throwingOn(Class) to add the type of exception that should cause the
method to throw right away. |
static class |
Retry.RetryAndThrowExceptionally<RetryT extends java.lang.Exception,ThrowsT extends java.lang.Exception>
Returned by
Retry.RetryExceptionally.throwingOn(Class) to add the type of exception that should cause the
method to throw right away. |
static class |
Retry.RetryExceptionally<RetryT extends java.lang.Exception>
Returned by
Retry.RetryWithBackoff.retryingOn(Class) to add the type of exception that should result in a retry. |
static class |
Retry.RetryUnconditionally
Returned by
indefinitelyWithExpBackoff(long, int, long, Consumer) (Class)} to
retry indefinitely. |
static class |
Retry.RetryWithBackoff
Returned by
withExpBackoff(long, int, int) to set the retry schedule. |
| Modifier and Type | Method and Description |
|---|---|
static Retry.RetryUnconditionally |
indefinitelyWithExpBackoff(long initialMillis,
int multiplier,
long maxDelay,
java.util.function.Consumer<java.lang.Throwable> consumer) |
static Retry.RetryUnconditionally |
indefinitelyWithExpBackoff(java.lang.String failureMessage) |
static Retry.RetryWithBackoff |
withExpBackoff(long initialMillis,
int multiplier,
int attempts) |
static Retry.RetryWithBackoff |
withExpBackoff(long initialMillis,
int multiplier,
int attempts,
long maxDelay) |
public static Retry.RetryWithBackoff withExpBackoff(long initialMillis, int multiplier, int attempts)
public static Retry.RetryWithBackoff withExpBackoff(long initialMillis, int multiplier, int attempts, long maxDelay)
public static Retry.RetryUnconditionally indefinitelyWithExpBackoff(long initialMillis, int multiplier, long maxDelay, java.util.function.Consumer<java.lang.Throwable> consumer)
public static Retry.RetryUnconditionally indefinitelyWithExpBackoff(java.lang.String failureMessage)