public abstract class Delay extends Object
Parent class of Delay
s and provides factory methods to create them.
Modifier and Type | Method and Description |
---|---|
abstract long |
calculate(long attempt)
Calculate a specific delay based on the attempt passed in.
|
static Delay |
exponential(TimeUnit unit)
Creates a new
ExponentialDelay with default boundaries and factor (1, 2, 4, 8, 16, 32…). |
static Delay |
exponential(TimeUnit unit,
long upper)
Creates a new
ExponentialDelay with custom upper boundary and default factor (eg. |
static Delay |
exponential(TimeUnit unit,
long upper,
long lower)
Creates a new
ExponentialDelay with custom boundaries and default factor (eg. |
static Delay |
exponential(TimeUnit unit,
long upper,
long lower,
long growBy)
Creates a new
ExponentialDelay with custom boundaries and factor (eg. |
static Delay |
exponential(TimeUnit unit,
long upper,
long lower,
long growBy,
int powersOf)
Creates a new
ExponentialDelay on a base different from powers of two, with custom boundaries and factor (eg. |
static Delay |
fixed(long delay,
TimeUnit unit)
Creates a new
FixedDelay . |
static Delay |
linear(TimeUnit unit)
Creates a new
LinearDelay with no bounds and default factor. |
static Delay |
linear(TimeUnit unit,
long upper)
Creates a new
LinearDelay with a custom upper boundary and the default factor. |
static Delay |
linear(TimeUnit unit,
long upper,
long lower)
Creates a new
LinearDelay with a custom boundaries and the default factor. |
static Delay |
linear(TimeUnit unit,
long upper,
long lower,
long growBy)
Creates a new
LinearDelay with a custom boundaries and factor. |
TimeUnit |
unit()
|
public TimeUnit unit()
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.
attempt
- the attempt to calculate the delay from.public static Delay fixed(long delay, TimeUnit unit)
Creates a new FixedDelay
.
delay
- the time of the delay.unit
- the unit of the delay.FixedDelay
.public static Delay linear(TimeUnit unit)
Creates a new LinearDelay
with no bounds and default factor.
unit
- the unit of the delay.LinearDelay
.public static Delay linear(TimeUnit unit, long upper)
Creates a new LinearDelay
with a custom upper boundary and the default factor.
unit
- the unit of the delay.upper
- the upper boundary.LinearDelay
.public static Delay linear(TimeUnit unit, long upper, long lower)
Creates a new LinearDelay
with a custom boundaries and the default factor.
unit
- the unit of the delay.upper
- the upper boundary.lower
- the lower boundary.LinearDelay
.public static Delay linear(TimeUnit unit, long upper, long lower, long growBy)
Creates a new LinearDelay
with a custom boundaries and factor.
unit
- the unit of the delay.upper
- the upper boundary.lower
- the lower boundary.growBy
- the multiplication factor.LinearDelay
.public static Delay exponential(TimeUnit unit)
Creates a new ExponentialDelay
with default boundaries and factor (1, 2, 4, 8, 16, 32…).
unit
- the unit of the delay.ExponentialDelay
.public static Delay exponential(TimeUnit unit, long upper)
Creates a new ExponentialDelay
with custom upper boundary and default factor (eg. with upper 8: 1, 2, 4, 8, 8, 8…).
unit
- the unit of the delay.upper
- the upper boundary.ExponentialDelay
.public static Delay exponential(TimeUnit unit, long upper, long lower)
Creates a new ExponentialDelay
with custom boundaries and default factor (eg. with upper 8, lower 3: 3, 3, 4, 8, 8, 8…).
unit
- the unit of the delay.upper
- the upper boundary.lower
- the lower boundary.ExponentialDelay
.public static Delay exponential(TimeUnit unit, long upper, long lower, long growBy)
Creates a new ExponentialDelay
with custom boundaries and factor (eg. with upper 300, lower 0, growBy 10: 10, 20, 40, 80, 160, 300, …).
unit
- the unit of the delay.upper
- the upper boundary.lower
- the lower boundary.growBy
- the multiplication factor.ExponentialDelay
.public static Delay exponential(TimeUnit unit, long upper, long lower, long growBy, int powersOf)
Creates a new ExponentialDelay
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, …).
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…)ExponentialDelay
.Copyright © 2018 Couchbase, Inc.. All rights reserved.