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.

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 Details

  • Method Details

    • initialDelay

      public DefaultRetryDelayStrategy initialDelay(long initialDelay, TimeUnit timeUnit)
      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 by timeUnit
      timeUnit - the time unit, or TimeUnit.MILLISECONDS if null
      Returns:
      a new instance with the specified initial delay
      Since:
      5.0.0
      See Also:
    • 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:
    • getDelayMillis

      public long getDelayMillis()
      Description copied from class: RetryDelayStrategy
      Returns the retry delay this instance represents, in milliseconds. Pure and deterministic on a given instance.
      Specified by:
      getDelayMillis in class RetryDelayStrategy
      Returns:
      the delay in milliseconds
    • getNext

      public RetryDelayStrategy getNext()
      Description copied from class: RetryDelayStrategy
      Returns 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. Returning null is treated as equivalent to returning this.

      Specified by:
      getNext in class RetryDelayStrategy
      Returns:
      the strategy to use next, or null to reuse this instance
    • withBaseDelayMillis

      public DefaultRetryDelayStrategy withBaseDelayMillis(long millis)
      Description copied from class: RetryDelayStrategy
      Returns 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:
      withBaseDelayMillis in class RetryDelayStrategy
      Parameters:
      millis - the new base delay in milliseconds
      Returns:
      a fresh instance with the given base, or this if the strategy does not honor base overrides