Package com.launchdarkly.eventsource
Class DefaultRetryDelayStrategy
- java.lang.Object
-
- com.launchdarkly.eventsource.RetryDelayStrategy
-
- com.launchdarkly.eventsource.DefaultRetryDelayStrategy
-
public class DefaultRetryDelayStrategy extends RetryDelayStrategy
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
- Start with the configured base delay as set by
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.launchdarkly.eventsource.RetryDelayStrategy
RetryDelayStrategy.Result
-
-
Field Summary
Fields Modifier and Type Field Description static float
DEFAULT_BACKOFF_MULTIPLIER
The default value forbackoffMultiplier(float)
: 2.static float
DEFAULT_JITTER_MULTIPLIER
The default value forjitterMultiplier(float)
: 0.5.static long
DEFAULT_MAX_DELAY_MILLIS
The default value formaxDelay(long, TimeUnit)
: 30 seconds.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RetryDelayStrategy.Result
apply(long baseDelayMillis)
Applies the strategy to compute the appropriate retry delay.DefaultRetryDelayStrategy
backoffMultiplier(float newBackoffMultiplier)
Returns a modified strategy with a specific backoff multipler.DefaultRetryDelayStrategy
jitterMultiplier(float newJitterMultiplier)
Returns a modified strategy with a specific jitter multipler.DefaultRetryDelayStrategy
maxDelay(long maxDelay, java.util.concurrent.TimeUnit timeUnit)
Returns a modified strategy with a specific maximum delay.-
Methods inherited from class com.launchdarkly.eventsource.RetryDelayStrategy
defaultStrategy
-
-
-
-
Field Detail
-
DEFAULT_MAX_DELAY_MILLIS
public static final long DEFAULT_MAX_DELAY_MILLIS
The default value formaxDelay(long, TimeUnit)
: 30 seconds.- See Also:
- Constant Field Values
-
DEFAULT_BACKOFF_MULTIPLIER
public static final float DEFAULT_BACKOFF_MULTIPLIER
The default value forbackoffMultiplier(float)
: 2.- See Also:
- Constant Field Values
-
DEFAULT_JITTER_MULTIPLIER
public static final float DEFAULT_JITTER_MULTIPLIER
The default value forjitterMultiplier(float)
: 0.5.- See Also:
- Constant Field Values
-
-
Method Detail
-
maxDelay
public DefaultRetryDelayStrategy maxDelay(long maxDelay, java.util.concurrent.TimeUnit timeUnit)
Returns a modified strategy with a specific maximum delay.- Parameters:
maxDelay
- the maximum delay, in whatever time unit is specified bytimeUnit
timeUnit
- the time unit, orTimeUnit.MILLISECONDS
if null- Returns:
- a new instance with the specified maximum delay
- See Also:
DEFAULT_MAX_DELAY_MILLIS
-
backoffMultiplier
public DefaultRetryDelayStrategy backoffMultiplier(float newBackoffMultiplier)
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:
DEFAULT_BACKOFF_MULTIPLIER
-
jitterMultiplier
public DefaultRetryDelayStrategy jitterMultiplier(float newJitterMultiplier)
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:
DEFAULT_JITTER_MULTIPLIER
-
apply
public RetryDelayStrategy.Result apply(long baseDelayMillis)
Description copied from class:RetryDelayStrategy
Applies the strategy to compute the appropriate retry delay.- Specified by:
apply
in classRetryDelayStrategy
- Parameters:
baseDelayMillis
- the initial configured base delay as set byEventSource.Builder.retryDelay(long, java.util.concurrent.TimeUnit)
- Returns:
- the computed delay
-
-