public abstract class BackoffPolicy extends java.lang.Object implements java.lang.Iterable<TimeValue>
BackoffPolicy
are progressions which can be either finite or infinite although
the latter should not be used for retrying. A progression can be mapped to a java.util.Iterator
with the following
semantics:
#hasNext()
determines whether the progression has more elements. Return true
for infinite progressions#next()
determines the next element in the progression, i.e. the next wait time periodIterables
in order to be consumed multiple times.Constructor and Description |
---|
BackoffPolicy() |
Modifier and Type | Method and Description |
---|---|
static BackoffPolicy |
constantBackoff(TimeValue delay,
int maxNumberOfRetries)
Creates an new constant backoff policy with the provided configuration.
|
static BackoffPolicy |
exponentialBackoff()
Creates an new exponential backoff policy with a default configuration of 50 ms initial wait period and 8 retries taking
roughly 5.1 seconds in total.
|
static BackoffPolicy |
exponentialBackoff(TimeValue initialDelay,
int maxNumberOfRetries)
Creates an new exponential backoff policy with the provided configuration.
|
static BackoffPolicy |
noBackoff()
Creates a backoff policy that will not allow any backoff, i.e.
|
static BackoffPolicy |
wrap(BackoffPolicy delegate,
java.lang.Runnable onBackoff)
Wraps the backoff policy in one that calls a method every time a new backoff is taken from the policy.
|
public static BackoffPolicy noBackoff()
public static BackoffPolicy constantBackoff(TimeValue delay, int maxNumberOfRetries)
delay
- The delay defines how long to wait between retry attempts. Must not be null.
Must be <= Integer.MAX_VALUE
ms.maxNumberOfRetries
- The maximum number of retries. Must be a non-negative number.public static BackoffPolicy exponentialBackoff()
public static BackoffPolicy exponentialBackoff(TimeValue initialDelay, int maxNumberOfRetries)
initialDelay
- The initial delay defines how long to wait for the first retry attempt. Must not be null.
Must be <= Integer.MAX_VALUE
ms.maxNumberOfRetries
- The maximum number of retries. Must be a non-negative number.public static BackoffPolicy wrap(BackoffPolicy delegate, java.lang.Runnable onBackoff)