Class RetryDelayStrategy
- java.lang.Object
-
- com.launchdarkly.eventsource.RetryDelayStrategy
-
- Direct Known Subclasses:
DefaultRetryDelayStrategy
public abstract class RetryDelayStrategy extends java.lang.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 of this interface should be immutable. To implement strategies where the delay uses different parameters on each subsequent retry (such as exponential backoff), the strategy should return a new instance of its own class in
RetryDelayStrategy.Result.getNext()
, rather than modifying the state of the existing instance. This makes it easy for EventSource to reset to the original delay state when appropriate by simply reusing the original instance.- Since:
- 4.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RetryDelayStrategy.Result
The return type ofapply(long)
.
-
Constructor Summary
Constructors Constructor Description RetryDelayStrategy()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract RetryDelayStrategy.Result
apply(long baseDelayMillis)
Applies the strategy to compute the appropriate retry delay.static DefaultRetryDelayStrategy
defaultStrategy()
Returns the default implementation, configured to use the default backoff and jitter.
-
-
-
Method Detail
-
apply
public abstract RetryDelayStrategy.Result apply(long baseDelayMillis)
Applies the strategy to compute the appropriate retry delay.- Parameters:
baseDelayMillis
- the initial configured base delay as set byEventSource.Builder.retryDelay(long, java.util.concurrent.TimeUnit)
- Returns:
- the computed delay
-
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
.
-
-