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
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)
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.
Modifier and Type | Method and Description |
---|---|
long |
calculate(long attempt)
Calculate a specific delay based on the attempt passed in.
|
protected long |
calculateAlternatePower(long attempt) |
protected long |
calculatePowerOfTwo(long attempt) |
String |
toString() |
exponential, exponential, exponential, exponential, exponential, fixed, linear, linear, linear, linear, unit
public long calculate(long attempt)
Delay
Calculate 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.
protected long calculateAlternatePower(long attempt)
protected long calculatePowerOfTwo(long attempt)
Copyright © 2018 Couchbase, Inc.. All rights reserved.