public class UniformRandomBackOffPolicy extends StatelessBackOffPolicy implements SleepingBackOffPolicy<UniformRandomBackOffPolicy>
BackOffPolicy that pauses for a random period of
time before continuing. A pause is implemented using Sleeper.sleep(long).
setMinBackOffPeriod(long) is thread-safe and it is safe to call
setMaxBackOffPeriod(long) during execution from multiple threads, however
this may cause a single retry operation to have pauses of different
intervals.| Modifier and Type | Field and Description |
|---|---|
private static long |
DEFAULT_BACK_OFF_MAX_PERIOD
Default max back off period - 1500ms.
|
private static long |
DEFAULT_BACK_OFF_MIN_PERIOD
Default min back off period - 500ms.
|
private long |
maxBackOffPeriod |
private long |
minBackOffPeriod |
private java.util.Random |
random |
private Sleeper |
sleeper |
| Constructor and Description |
|---|
UniformRandomBackOffPolicy() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doBackOff()
Pause for the
setMinBackOffPeriod(long). |
long |
getMaxBackOffPeriod()
The maximum backoff period in milliseconds.
|
long |
getMinBackOffPeriod()
The minimum backoff period in milliseconds.
|
void |
setMaxBackOffPeriod(long backOffPeriod)
Set the maximum back off period in milliseconds.
|
void |
setMinBackOffPeriod(long backOffPeriod)
Set the minimum back off period in milliseconds.
|
void |
setSleeper(Sleeper sleeper)
Public setter for the
Sleeper strategy. |
java.lang.String |
toString() |
UniformRandomBackOffPolicy |
withSleeper(Sleeper sleeper)
Clone the policy and return a new policy which uses the passed sleeper.
|
backOff, startclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitbackOff, startprivate static final long DEFAULT_BACK_OFF_MIN_PERIOD
private static final long DEFAULT_BACK_OFF_MAX_PERIOD
private volatile long minBackOffPeriod
private volatile long maxBackOffPeriod
private java.util.Random random
private Sleeper sleeper
public UniformRandomBackOffPolicy withSleeper(Sleeper sleeper)
SleepingBackOffPolicywithSleeper in interface SleepingBackOffPolicy<UniformRandomBackOffPolicy>sleeper - Target to be invoked any time the backoff policy sleepspublic void setSleeper(Sleeper sleeper)
Sleeper strategy.sleeper - the sleeper to set defaults to ThreadWaitSleeper.public void setMinBackOffPeriod(long backOffPeriod)
public long getMinBackOffPeriod()
public void setMaxBackOffPeriod(long backOffPeriod)
public long getMaxBackOffPeriod()
protected void doBackOff()
throws BackOffInterruptedException
setMinBackOffPeriod(long).doBackOff in class StatelessBackOffPolicyBackOffInterruptedException - if interrupted during sleep.public java.lang.String toString()
toString in class java.lang.Object