public final class DefaultBackoffPolicy extends java.lang.Object implements BackoffPolicy
BackoffPolicy
that does an 'exponential' backoff. So each next attempt, the calculated delay is increased
and randomized (so the next value can be smaller than the previous, but overall they will increase).Modifier and Type | Field and Description |
---|---|
static BackoffPolicy |
MAX_100_MS |
private long |
minDelayNs |
private long[] |
slotTimes |
Constructor and Description |
---|
DefaultBackoffPolicy()
Creates an ExponentialBackoffPolicy with 100 nanoseconds as minimal delay and 100 milliseconds as maximum
delay.
|
DefaultBackoffPolicy(long minDelayNs)
Creates an ExponentialBackoffPolicy with given maximum delay.
|
Modifier and Type | Method and Description |
---|---|
protected long |
calcDelayNs(int attempt) |
void |
delay(int attempt)
Delays the calling Thread.
|
void |
delayUninterruptible(int attempt)
Delays the calling Thread without being interrupted.
|
private int |
f(int x,
double a,
double b) |
public static final BackoffPolicy MAX_100_MS
private final long minDelayNs
private final long[] slotTimes
public DefaultBackoffPolicy()
public DefaultBackoffPolicy(long minDelayNs)
minDelayNs
- the minimum delay in nanoseconds to wait. If a negative or zero value provided, it will be
interpreted that no external minimal value is needed.java.lang.NullPointerException
- if unit is null.private int f(int x, double a, double b)
public void delay(int attempt) throws java.lang.InterruptedException
BackoffPolicy
The implementation is free to make this a no-op call.
delay
in interface BackoffPolicy
java.lang.InterruptedException
public void delayUninterruptible(int attempt)
BackoffPolicy
The implementation is free to make this a no-op call.
delayUninterruptible
in interface BackoffPolicy
attempt
- theprotected long calcDelayNs(int attempt)