public final class FluentBackoff
extends java.lang.Object
BackOff objects that allows customization of the retry algorithm.| Modifier and Type | Field and Description |
|---|---|
static FluentBackoff |
DEFAULT
By default the
BackOff created by this builder will use exponential backoff (base
exponent 1.5) with an initial backoff of 1 second. |
| Modifier and Type | Method and Description |
|---|---|
BackOff |
backoff()
Instantiates a
BackOff that will obey the current configuration. |
java.lang.String |
toString() |
FluentBackoff |
withExponent(double exponent)
Returns a copy of this
FluentBackoff that instead uses the specified exponent to
control the exponential growth of delay. |
FluentBackoff |
withInitialBackoff(org.joda.time.Duration initialBackoff)
Returns a copy of this
FluentBackoff that instead uses the specified initial backoff
duration. |
FluentBackoff |
withMaxBackoff(org.joda.time.Duration maxBackoff)
Returns a copy of this
FluentBackoff that limits the maximum backoff of an individual
attempt to the specified duration. |
FluentBackoff |
withMaxCumulativeBackoff(org.joda.time.Duration maxCumulativeBackoff)
Returns a copy of this
FluentBackoff that limits the total time spent in backoff
returned across all calls to BackOff.nextBackOffMillis(). |
FluentBackoff |
withMaxRetries(int maxRetries)
Returns a copy of this
FluentBackoff that limits the total number of retries, aka the
total number of calls to BackOff.nextBackOffMillis() before returning BackOff.STOP. |
public static final FluentBackoff DEFAULT
BackOff created by this builder will use exponential backoff (base
exponent 1.5) with an initial backoff of 1 second. These parameters can be overridden with
withExponent(double) and withInitialBackoff(Duration), respectively, and the
maximum backoff after exponential increase can be capped using withMaxBackoff(Duration).
The default BackOff does not limit the number of retries. To limit the backoff, the
maximum total number of retries can be set using withMaxRetries(int). The total time
spent in backoff can be time-bounded as well by configuring withMaxCumulativeBackoff(Duration). If either of these limits are reached, calls to BackOff.nextBackOffMillis() will return BackOff.STOP to signal that no more retries
should continue.
public BackOff backoff()
BackOff that will obey the current configuration.FluentBackoffpublic FluentBackoff withExponent(double exponent)
FluentBackoff that instead uses the specified exponent to
control the exponential growth of delay.
Does not modify this object.
FluentBackoffpublic FluentBackoff withInitialBackoff(org.joda.time.Duration initialBackoff)
FluentBackoff that instead uses the specified initial backoff
duration.
Does not modify this object.
FluentBackoffpublic FluentBackoff withMaxBackoff(org.joda.time.Duration maxBackoff)
FluentBackoff that limits the maximum backoff of an individual
attempt to the specified duration.
Does not modify this object.
FluentBackoffpublic FluentBackoff withMaxCumulativeBackoff(org.joda.time.Duration maxCumulativeBackoff)
FluentBackoff that limits the total time spent in backoff
returned across all calls to BackOff.nextBackOffMillis().
Does not modify this object.
FluentBackoffpublic FluentBackoff withMaxRetries(int maxRetries)
FluentBackoff that limits the total number of retries, aka the
total number of calls to BackOff.nextBackOffMillis() before returning BackOff.STOP.
Does not modify this object.
FluentBackoffpublic java.lang.String toString()
toString in class java.lang.Object