Class RetryDelayStrategy

java.lang.Object
com.launchdarkly.eventsource.RetryDelayStrategy
Direct Known Subclasses:
DefaultRetryDelayStrategy

public abstract class RetryDelayStrategy extends Object
RetryDelayStrategy is an abstraction of how EventSource should determine the delay between retry attempts when a stream fails.

The default behavior, provided by DefaultRetryDelayStrategy, provides customizable exponential backoff and jitter. Applications may also create their own implementations of RetryDelayStrategy if they desire different behavior. It is generally a best practice to use backoff and jitter, to avoid a reconnect storm during a service interruption.

Implementations should be immutable. Each instance represents a single state in the retry-delay sequence: getDelayMillis() returns the delay to use for the impending retry, and getNext() returns the strategy instance to use for the retry after that. Strategies with a base-delay concept may also implement withBaseDelayMillis(long) to accept server-directed reconnection-time overrides from the SSE retry: field.

Since:
4.0.0
  • Constructor Details

    • RetryDelayStrategy

      public RetryDelayStrategy()
  • Method Details

    • getDelayMillis

      public abstract long getDelayMillis()
      Returns the retry delay this instance represents, in milliseconds. Pure and deterministic on a given instance.
      Returns:
      the delay in milliseconds
      Since:
      5.0.0
    • getNext

      public abstract RetryDelayStrategy getNext()
      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.

      Returns:
      the strategy to use next, or null to reuse this instance
      Since:
      5.0.0
    • withBaseDelayMillis

      public RetryDelayStrategy withBaseDelayMillis(long millis)
      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.

      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
      Since:
      5.0.0
    • defaultStrategy

      public static DefaultRetryDelayStrategy defaultStrategy()
      Returns the default implementation, configured to use the default backoff and jitter.

      You can call DefaultRetryDelayStrategy methods on this instance to configure a strategy with different parameters.

      Returns:
      the DefaultRetryDelayStrategy.