public class ExponentialBackOffPolicy extends Object implements SleepingBackOffPolicy<ExponentialBackOffPolicy>
BackOffPolicy that increases the back off period
for each retry attempt in a given set using the exponential function.
This implementation is thread-safe and suitable for concurrent access.
Modifications to the configuration do not affect any retry sets that are
already in progress.
The setInitialInterval(long) property controls the initial value
passed to Math.exp(double) and the setMultiplier(double)
property controls by how much this value is increased for each subsequent
attempt.| Modifier and Type | Field and Description |
|---|---|
static long |
DEFAULT_INITIAL_INTERVAL
The default 'initialInterval' value - 100 millisecs.
|
static long |
DEFAULT_MAX_INTERVAL
The default maximum backoff time (30 seconds).
|
static double |
DEFAULT_MULTIPLIER
The default 'multiplier' value - value 2 (100% increase per backoff).
|
protected org.apache.commons.logging.Log |
logger |
| Constructor and Description |
|---|
ExponentialBackOffPolicy() |
| Modifier and Type | Method and Description |
|---|---|
void |
backOff(BackOffContext backOffContext)
Pause for a length of time equal to '
exp(backOffContext.expSeed)'. |
protected void |
cloneValues(ExponentialBackOffPolicy target) |
long |
getInitialInterval()
The initial period to sleep on the first backoff.
|
long |
getMaxInterval()
The maximum interval to sleep for.
|
double |
getMultiplier()
The multiplier to use to generate the next backoff interval from the
last.
|
protected ExponentialBackOffPolicy |
newInstance() |
void |
setInitialInterval(long initialInterval)
Set the initial sleep interval value.
|
void |
setMaxInterval(long maxInterval)
Setter for maximum back off period.
|
void |
setMultiplier(double multiplier)
Set the multiplier value.
|
void |
setSleeper(Sleeper sleeper)
Public setter for the
Sleeper strategy. |
BackOffContext |
start(RetryContext context)
Returns a new instance of
BackOffContext configured with the
'expSeed' and 'increment' values. |
String |
toString() |
ExponentialBackOffPolicy |
withSleeper(Sleeper sleeper)
Clone the policy and return a new policy which uses the passed sleeper.
|
protected final org.apache.commons.logging.Log logger
public static final long DEFAULT_INITIAL_INTERVAL
public static final long DEFAULT_MAX_INTERVAL
public static final double DEFAULT_MULTIPLIER
public void setSleeper(Sleeper sleeper)
Sleeper strategy.sleeper - the sleeper to set defaults to ThreadWaitSleeper.public ExponentialBackOffPolicy withSleeper(Sleeper sleeper)
SleepingBackOffPolicywithSleeper in interface SleepingBackOffPolicy<ExponentialBackOffPolicy>sleeper - Target to be invoked any time the backoff policy sleepsprotected ExponentialBackOffPolicy newInstance()
protected void cloneValues(ExponentialBackOffPolicy target)
public void setInitialInterval(long initialInterval)
100
millisecond. Cannot be set to a value less than one.public void setMultiplier(double multiplier)
2.0'. Hint: do not use
values much in excess of 1.0 (or the backoff will get very long very
fast).public void setMaxInterval(long maxInterval)
maxInterval - in milliseconds.public long getInitialInterval()
public long getMaxInterval()
public double getMultiplier()
public BackOffContext start(RetryContext context)
BackOffContext configured with the
'expSeed' and 'increment' values.start in interface BackOffPolicycontext - the current retry context, which might contain information
that we can use to decide how to proceed.BackOffContext or 'null'.public void backOff(BackOffContext backOffContext) throws BackOffInterruptedException
exp(backOffContext.expSeed)'.backOff in interface BackOffPolicyBackOffInterruptedException - if the attempt at back off is
interrupted.Copyright © 2014 SpringSource. All rights reserved.