Class DefaultRetryDelayStrategy
Each instance is immutable: getDelayMillis() returns the delay for this
instance, and getNext() returns the successor instance with the base
delay multiplied by the backoff multiplier (pinned at the max delay). Jitter is
rolled once per instance at construction so getDelayMillis() is
deterministic on a given instance.
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()
.initialDelay(1, TimeUnit.SECONDS)
.jitterMultiplier(0.25f)
.maxDelay(20, TimeUnit.SECONDS);
- Since:
- 4.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatThe default value forbackoffMultiplier(float): 2.static final longThe default value forinitialDelay(long, TimeUnit): 1 second.static final floatThe default value forjitterMultiplier(float): 0.5.static final longThe default value formaxDelay(long, TimeUnit): 30 seconds. -
Method Summary
Modifier and TypeMethodDescriptionbackoffMultiplier(float newBackoffMultiplier) Returns a modified strategy with a specific backoff multipler.longReturns the retry delay this instance represents, in milliseconds.getNext()Returns the strategy instance to use for the retry after this one.initialDelay(long initialDelay, TimeUnit timeUnit) Returns a modified strategy with a specific initial (base) delay.jitterMultiplier(float newJitterMultiplier) Returns a modified strategy with a specific jitter multipler.Returns a modified strategy with a specific maximum delay.withBaseDelayMillis(long millis) Returns a fresh instance of this strategy with its base delay set to the given value and any backoff progression reset.Methods inherited from class com.launchdarkly.eventsource.RetryDelayStrategy
defaultStrategy
-
Field Details
-
DEFAULT_INITIAL_DELAY_MILLIS
public static final long DEFAULT_INITIAL_DELAY_MILLISThe default value forinitialDelay(long, TimeUnit): 1 second.- See Also:
-
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
-
initialDelay
Returns a modified strategy with a specific initial (base) delay. The returned instance is fresh — its backoff progression is reset.- Parameters:
initialDelay- the initial delay in whatever time unit is specified bytimeUnittimeUnit- the time unit, orTimeUnit.MILLISECONDSif null- Returns:
- a new instance with the specified initial delay
- Since:
- 5.0.0
- See Also:
-
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:
-
getDelayMillis
public long getDelayMillis()Description copied from class:RetryDelayStrategyReturns the retry delay this instance represents, in milliseconds. Pure and deterministic on a given instance.- Specified by:
getDelayMillisin classRetryDelayStrategy- Returns:
- the delay in milliseconds
-
getNext
Description copied from class:RetryDelayStrategyReturns the strategy instance to use for the retry after this one. Does not modify this instance.Strategies that never advance (e.g., a constant-delay strategy) return
this. Strategies with backoff progression return a new instance carrying the advanced state. Returningnullis treated as equivalent to returningthis.- Specified by:
getNextin classRetryDelayStrategy- Returns:
- the strategy to use next, or
nullto reuse this instance
-
withBaseDelayMillis
Description copied from class:RetryDelayStrategyReturns a fresh instance of this strategy with its base delay set to the given value and any backoff progression reset.The default implementation returns
this. Strategies without a base-delay concept opt out of wire-directed base overrides by not implementing this method.- Overrides:
withBaseDelayMillisin classRetryDelayStrategy- Parameters:
millis- the new base delay in milliseconds- Returns:
- a fresh instance with the given base, or
thisif the strategy does not honor base overrides
-