Class ExponentialDelay
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 parameter: 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 lowerBound will be replaced by the lower bound, and
each value over the upperBound will 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
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.
-
Method Summary
Modifier and TypeMethodDescriptionlongcalculate(long attempt) Calculate a specific delay based on the attempt passed in.protected longcalculateAlternatePower(long attempt) protected longcalculatePowerOfTwo(long attempt) toString()Methods inherited from class com.couchbase.client.dcp.core.time.Delay
exponential, exponential, exponential, exponential, exponential, fixed, linear, linear, linear, linear, unit
-
Method Details
-
calculate
public 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.
-
calculateAlternatePower
protected long calculateAlternatePower(long attempt) -
calculatePowerOfTwo
protected long calculatePowerOfTwo(long attempt) -
toString
-