Package org.multiverse.api
Class DefaultBackoffPolicy
java.lang.Object
org.multiverse.api.DefaultBackoffPolicy
- All Implemented Interfaces:
BackoffPolicy
A
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).-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BackoffPolicyprivate final longprivate final long[] -
Constructor Summary
ConstructorsConstructorDescriptionCreates an ExponentialBackoffPolicy with 100 nanoseconds as minimal delay and 100 milliseconds as maximum delay.DefaultBackoffPolicy(long minDelayNs) Creates an ExponentialBackoffPolicy with given maximum delay. -
Method Summary
Modifier and TypeMethodDescriptionprotected longcalcDelayNs(int attempt) voiddelay(int attempt) Delays the calling Thread.voiddelayUninterruptible(int attempt) Delays the calling Thread without being interrupted.private intf(int x, double a, double b)
-
Field Details
-
MAX_100_MS
-
minDelayNs
private final long minDelayNs -
slotTimes
private final long[] slotTimes
-
-
Constructor Details
-
DefaultBackoffPolicy
public DefaultBackoffPolicy()Creates an ExponentialBackoffPolicy with 100 nanoseconds as minimal delay and 100 milliseconds as maximum delay. -
DefaultBackoffPolicy
public DefaultBackoffPolicy(long minDelayNs) Creates an ExponentialBackoffPolicy with given maximum delay.- Parameters:
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.- Throws:
NullPointerException- if unit is null.
-
-
Method Details
-
f
private int f(int x, double a, double b) -
delay
Description copied from interface:BackoffPolicyDelays the calling Thread.The implementation is free to make this a no-op call.
- Specified by:
delayin interfaceBackoffPolicy- Parameters:
attempt-- Throws:
InterruptedException
-
delayUninterruptible
public void delayUninterruptible(int attempt) Description copied from interface:BackoffPolicyDelays the calling Thread without being interrupted.The implementation is free to make this a no-op call.
- Specified by:
delayUninterruptiblein interfaceBackoffPolicy- Parameters:
attempt- the
-
calcDelayNs
protected long calcDelayNs(int attempt)
-