Package com.launchdarkly.eventsource
Class DefaultRetryDelayStrategy
java.lang.Object
com.launchdarkly.eventsource.RetryDelayStrategy
com.launchdarkly.eventsource.DefaultRetryDelayStrategy
Default implementation of the retry delay strategy, providing exponential backoff
and jitter.
The algorithm is as follows:
- Start with the configured base delay as set by
EventSource.Builder.retryDelay(long, java.util.concurrent.TimeUnit). - On each subsequent attempt, multiply the base delay by the backoff multiplier
(default:
DEFAULT_BACKOFF_MULTIPLIER) giving the current base delay. - If the maximum delay (default:
DEFAULT_MAX_DELAY_MILLIS) is non-zero, the base delay is pinned to be no greater than that value. - If the jitter multipler (default:
DEFAULT_JITTER_MULTIPLIER) is non-zero, the actual delay for each attempt is equal to the current base delay minus a pseudo-random number equal to that ratio times itself. For instance, a jitter multiplier of 0.25 would mean that a base delay of 1000 is changed to a value in the range [750, 1000].
This class is immutable. RetryDelayStrategy.defaultStrategy() returns the
default instance. To change any parameters, call methods which return a modified
instance:
RetryDelayStrategy strategy = RetryDelayStrategy.defaultStrategy()
.jitterMultiplier(0.25)
.maxDelay(20, TimeUnit.SECONDS);
- Since:
- 4.0.0
-
Nested Class Summary
Nested classes/interfaces inherited from class com.launchdarkly.eventsource.RetryDelayStrategy
RetryDelayStrategy.Result -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatThe default value forbackoffMultiplier(float): 2.static final floatThe default value forjitterMultiplier(float): 0.5.static final longThe default value formaxDelay(long, TimeUnit): 30 seconds. -
Method Summary
Modifier and TypeMethodDescriptionapply(long baseDelayMillis) Applies the strategy to compute the appropriate retry delay.backoffMultiplier(float newBackoffMultiplier) Returns a modified strategy with a specific backoff multipler.jitterMultiplier(float newJitterMultiplier) Returns a modified strategy with a specific jitter multipler.Returns a modified strategy with a specific maximum delay.Methods inherited from class com.launchdarkly.eventsource.RetryDelayStrategy
defaultStrategy
-
Field Details
-
DEFAULT_MAX_DELAY_MILLIS
public static final long DEFAULT_MAX_DELAY_MILLISThe default value formaxDelay(long, TimeUnit): 30 seconds.- See Also:
-
DEFAULT_BACKOFF_MULTIPLIER
public static final float DEFAULT_BACKOFF_MULTIPLIERThe default value forbackoffMultiplier(float): 2.- See Also:
-
DEFAULT_JITTER_MULTIPLIER
public static final float DEFAULT_JITTER_MULTIPLIERThe default value forjitterMultiplier(float): 0.5.- See Also:
-
-
Method Details
-
maxDelay
Returns a modified strategy with a specific maximum delay.- Parameters:
maxDelay- the maximum delay, in whatever time unit is specified bytimeUnittimeUnit- the time unit, orTimeUnit.MILLISECONDSif null- Returns:
- a new instance with the specified maximum delay
- See Also:
-
backoffMultiplier
Returns a modified strategy with a specific backoff multipler. A multipler of 1 means the base delay never changes, 2 means it doubles each time, etc.- Parameters:
newBackoffMultiplier- the backoff multipler- Returns:
- a new instance with the specified backoff multiplier
- See Also:
-
jitterMultiplier
Returns a modified strategy with a specific jitter multipler. A multipler of 0.5 means each delay is reduced randomly by up to 50%, 0.25 means it is reduced randomly by up to 25%, etc. Zero means there is no jitter.- Parameters:
newJitterMultiplier- the jigger multipler- Returns:
- a new instance with the specified jitter multipler
- See Also:
-
apply
Description copied from class:RetryDelayStrategyApplies the strategy to compute the appropriate retry delay.- Specified by:
applyin classRetryDelayStrategy- Parameters:
baseDelayMillis- the initial configured base delay as set byEventSource.Builder.retryDelay(long, java.util.concurrent.TimeUnit)- Returns:
- the computed delay
-