Package com.couchbase.client.core.time
Class ExponentialDelay
java.lang.Object
com.couchbase.client.core.time.Delay
com.couchbase.client.core.time.ExponentialDelay
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 ^ (attemptNumber1)
. Actually each step can be based on a
different number than 1 unit of time using the growBy
parameter: growBy * 2 ^ (attemptNumber1)
.
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
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. Since:
 1.1.0
 Author:
 Michael Nitschinger

Method Summary
Modifier and Type Method 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()
Methods inherited from class com.couchbase.client.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: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. 
calculateAlternatePower
protected long calculateAlternatePower(long attempt) 
calculatePowerOfTwo
protected long calculatePowerOfTwo(long attempt) 
toString
