Package com.github.twitch4j.common.util
Class ExponentialBackoffStrategy.ExponentialBackoffStrategyBuilder
java.lang.Object
com.github.twitch4j.common.util.ExponentialBackoffStrategy.ExponentialBackoffStrategyBuilder
- Enclosing class:
- ExponentialBackoffStrategy
-
Method Summary
Modifier and TypeMethodDescriptionbaseMillis
(long baseMillis) The milliseconds value for the first non-zero backoff.build()
immediateFirst
(boolean immediateFirst) Whether the first attempt after a failure should take place without delay.initialJitterRange
(long initialJitterRange) The range of initial jitter amounts (in milliseconds) for when bothExponentialBackoffStrategy.isImmediateFirst()
andExponentialBackoffStrategy.isJitter()
are true.jitter
(boolean jitter) Whether (pseudo-)randomness should be applied when computing the exponential backoff.maximumBackoff
(long maximumBackoff) The maximum backoff value (on average), in milliseconds.maxRetries
(int maxRetries) The maximum number of retries that should be allowed.multiplier
(double multiplier) The multiplier on back-offs that is in the base of the exponent.toString()
-
Method Details
-
maximumBackoff
public ExponentialBackoffStrategy.ExponentialBackoffStrategyBuilder maximumBackoff(long maximumBackoff) The maximum backoff value (on average), in milliseconds. If set to a negative value, the algorithm will not be of the truncated variety.- Returns:
this
.
-
multiplier
The multiplier on back-offs that is in the base of the exponent.The default is 2, which results in doubling of average delays with additional failures. This generally should be set to a value greater than 1 so that delays tend to increase with more failures.
- Returns:
this
.
-
immediateFirst
public ExponentialBackoffStrategy.ExponentialBackoffStrategyBuilder immediateFirst(boolean immediateFirst) Whether the first attempt after a failure should take place without delay.To avoid a "stampeding herd" of reconnecting clients,
jitter(boolean)
can be enabled andinitialJitterRange(long)
can optionally be configured.- Returns:
this
.
-
jitter
Whether (pseudo-)randomness should be applied when computing the exponential backoff.Highly useful for avoiding the thundering herd problem.
- Returns:
this
.
-
initialJitterRange
public ExponentialBackoffStrategy.ExponentialBackoffStrategyBuilder initialJitterRange(long initialJitterRange) The range of initial jitter amounts (in milliseconds) for when bothExponentialBackoffStrategy.isImmediateFirst()
andExponentialBackoffStrategy.isJitter()
are true.- Returns:
this
.
-
baseMillis
The milliseconds value for the first non-zero backoff. WhenExponentialBackoffStrategy.isJitter()
is true, this becomes an average targeted value rather than a strictly enforced constant.- Returns:
this
.
-
maxRetries
The maximum number of retries that should be allowed.A negative value corresponds to no limit. A zero value corresponds to no retries allowed. A positive value enforces a specific maximum.
- Returns:
this
.
-
build
-
toString
-