Package com.couchbase.client.core.time
Class Delay
java.lang.Object
com.couchbase.client.core.time.Delay
- Direct Known Subclasses:
ExponentialDelay
,FixedDelay
,LinearDelay
public abstract class Delay extends Object
Parent class of
Delay
s and provides factory methods to create them.- Since:
- 1.1.0
- Author:
- Michael Nitschinger
-
Method Summary
Modifier and Type Method Description abstract long
calculate(long attempt)
Calculate a specific delay based on the attempt passed in.static Delay
exponential(TimeUnit unit)
Creates a newExponentialDelay
with default boundaries and factor (1, 2, 4, 8, 16, 32...).static Delay
exponential(TimeUnit unit, long upper)
Creates a newExponentialDelay
with custom upper boundary and default factor (eg.static Delay
exponential(TimeUnit unit, long upper, long lower)
Creates a newExponentialDelay
with custom boundaries and default factor (eg.static Delay
exponential(TimeUnit unit, long upper, long lower, long growBy)
Creates a newExponentialDelay
with custom boundaries and factor (eg.static Delay
exponential(TimeUnit unit, long upper, long lower, long growBy, int powersOf)
Creates a newExponentialDelay
on a base different from powers of two, with custom boundaries and factor (eg.static Delay
fixed(long delay, TimeUnit unit)
Creates a newFixedDelay
.static Delay
linear(TimeUnit unit)
Creates a newLinearDelay
with no bounds and default factor.static Delay
linear(TimeUnit unit, long upper)
Creates a newLinearDelay
with a custom upper boundary and the default factor.static Delay
linear(TimeUnit unit, long upper, long lower)
Creates a newLinearDelay
with a custom boundaries and the default factor.static Delay
linear(TimeUnit unit, long upper, long lower, long growBy)
Creates a newLinearDelay
with a custom boundaries and factor.TimeUnit
unit()
-
Method Details
-
unit
- Returns:
- the time unit.
-
calculate
public abstract long calculate(long attempt)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.- Parameters:
attempt
- the attempt to calculate the delay from.- Returns:
- the calculate delay.
-
fixed
Creates a newFixedDelay
.- Parameters:
delay
- the time of the delay.unit
- the unit of the delay.- Returns:
- a created
FixedDelay
.
-
linear
Creates a newLinearDelay
with no bounds and default factor.- Parameters:
unit
- the unit of the delay.- Returns:
- a created
LinearDelay
.
-
linear
Creates a newLinearDelay
with a custom upper boundary and the default factor.- Parameters:
unit
- the unit of the delay.upper
- the upper boundary.- Returns:
- a created
LinearDelay
.
-
linear
Creates a newLinearDelay
with a custom boundaries and the default factor.- Parameters:
unit
- the unit of the delay.upper
- the upper boundary.lower
- the lower boundary.- Returns:
- a created
LinearDelay
.
-
linear
Creates a newLinearDelay
with a custom boundaries and factor.- Parameters:
unit
- the unit of the delay.upper
- the upper boundary.lower
- the lower boundary.growBy
- the multiplication factor.- Returns:
- a created
LinearDelay
.
-
exponential
Creates a newExponentialDelay
with default boundaries and factor (1, 2, 4, 8, 16, 32...).- Parameters:
unit
- the unit of the delay.- Returns:
- a created
ExponentialDelay
.
-
exponential
Creates a newExponentialDelay
with custom upper boundary and default factor (eg. with upper 8: 1, 2, 4, 8, 8, 8...).- Parameters:
unit
- the unit of the delay.upper
- the upper boundary.- Returns:
- a created
ExponentialDelay
.
-
exponential
Creates a newExponentialDelay
with custom boundaries and default factor (eg. with upper 8, lower 3: 3, 3, 4, 8, 8, 8...).- Parameters:
unit
- the unit of the delay.upper
- the upper boundary.lower
- the lower boundary.- Returns:
- a created
ExponentialDelay
.
-
exponential
Creates a newExponentialDelay
with custom boundaries and factor (eg. with upper 300, lower 0, growBy 10: 10, 20, 40, 80, 160, 300, ...).- Parameters:
unit
- the unit of the delay.upper
- the upper boundary.lower
- the lower boundary.growBy
- the multiplication factor.- Returns:
- a created
ExponentialDelay
.
-
exponential
Creates a newExponentialDelay
on a base different from powers of two, with custom boundaries and factor (eg. with upper 9000, lower 0, growBy 3, powerOf 10: 3, 30, 300, 3000, 9000, 9000, 9000, ...).- Parameters:
unit
- the unit of the delay.upper
- the upper boundary.lower
- the lower boundary.growBy
- the multiplication factor (or basis for the size of each delay).powersOf
- the base for exponential growth (eg. powers of 2, powers of 10, etc...)- Returns:
- a created
ExponentialDelay
.
-