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
  • Field Details

  • Method Details

    • maxDelay

      public DefaultRetryDelayStrategy maxDelay(long maxDelay, TimeUnit timeUnit)
      Returns a modified strategy with a specific maximum delay.
      Parameters:
      maxDelay - the maximum delay, in whatever time unit is specified by timeUnit
      timeUnit - the time unit, or TimeUnit.MILLISECONDS if null
      Returns:
      a new instance with the specified maximum delay
      See Also:
    • 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:
    • 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:
    • 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 class RetryDelayStrategy
      Parameters:
      baseDelayMillis - the initial configured base delay as set by EventSource.Builder.retryDelay(long, java.util.concurrent.TimeUnit)
      Returns:
      the computed delay