Package com.github.twitch4j.common.util
Class ExponentialBackoffStrategy.ExponentialBackoffStrategyBuilder
java.lang.Object
com.github.twitch4j.common.util.ExponentialBackoffStrategy.ExponentialBackoffStrategyBuilder
- Enclosing class:
- ExponentialBackoffStrategy
public static class ExponentialBackoffStrategy.ExponentialBackoffStrategyBuilder
extends java.lang.Object
-
Method Summary
Modifier and Type Method Description ExponentialBackoffStrategy.ExponentialBackoffStrategyBuilderbaseMillis(long baseMillis)The milliseconds value for the first non-zero backoff.ExponentialBackoffStrategybuild()ExponentialBackoffStrategy.ExponentialBackoffStrategyBuilderimmediateFirst(boolean immediateFirst)Whether the first attempt after a failure should take place without delay.ExponentialBackoffStrategy.ExponentialBackoffStrategyBuilderinitialJitterRange(long initialJitterRange)The range of initial jitter amounts (in milliseconds) for when bothExponentialBackoffStrategy.isImmediateFirst()andExponentialBackoffStrategy.isJitter()are true.ExponentialBackoffStrategy.ExponentialBackoffStrategyBuilderjitter(boolean jitter)Whether (pseudo-)randomness should be applied when computing the exponential backoff.ExponentialBackoffStrategy.ExponentialBackoffStrategyBuildermaximumBackoff(long maximumBackoff)The maximum backoff value (on average), in milliseconds.ExponentialBackoffStrategy.ExponentialBackoffStrategyBuildermaxRetries(int maxRetries)The maximum number of retries that should be allowed.ExponentialBackoffStrategy.ExponentialBackoffStrategyBuildermultiplier(double multiplier)The multiplier on back-offs that is in the base of the exponent.java.lang.StringtoString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
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
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-