public class ExponentialDelay extends Delay
Delay which increases exponentially on every attempt. Considering retry attempts start at 1, attempt 0 would be the initial call and will always yield 0 (or the lower bound). Then each retry step will by default yield
1 * 2 ^ (attemptNumber-1). Actually each step can be based on a different number than 1 unit of time using the
growBy * 2 ^ (attemptNumber-1). By default with growBy = 1 this gives us 0 (initial attempt), 1, 2, 4, 8, 16, 32... Each of the resulting values that is below the
lowerBoundwill be replaced by the lower bound, and each value over the
upperBoundwill be replaced by the upper bound. For example, given the following
Delay.exponential(TimeUnit.MILLISECONDS, 4000, 0, 500)* the upper of 4000 means the delay will be capped at 4s * the lower of 0 is useful to allow for immediate execution of original attempt, attempt 0 (if we ever call the delay with a parameter of 0) * the growBy of 500 means that we take steps based on 500ms This yields the following delays:
0ms, 500ms, 1s, 2s, 4s, 4s, 4s,...In detail :
0, 500 * 2^0, 500 * 2^1, 500 * 2^2, 500 * 2^3, max(4000, 500 * 2^4), max(4000, 500 * 2^5),.... Finally, the powers used in the computation can be changed from powers of two by default to another base using the powersOf parameter.
- Michael Nitschinger
Modifier and Type Method Description
(long attempt)Calculate a specific delay based on the attempt passed in.
Methods inherited from class com.couchbase.client.core.time.Delay
exponential, exponential, exponential, exponential, exponential, fixed, linear, linear, linear, linear, unit
calculatepublic long calculate(long attempt)Description copied from class:
DelayCalculate a specific delay based on the attempt passed in. This method is to be implemented by the child implementations and depending on the params that were set during construction time.
calculateAlternatePowerprotected long calculateAlternatePower(long attempt)
calculatePowerOfTwoprotected long calculatePowerOfTwo(long attempt)
toStringpublic String toString()