Package com.launchdarkly.eventsource
Class ErrorStrategy
- java.lang.Object
-
- com.launchdarkly.eventsource.ErrorStrategy
-
public abstract class ErrorStrategy extends java.lang.ObjectAn abstraction of how to determine whether a stream failure should be thrown to the caller as an exception, or treated as an event.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classErrorStrategy.ActionDescribes the possible actions EventSource could take after an error.static classErrorStrategy.ResultThe return type ofapply(StreamException).
-
Constructor Summary
Constructors Constructor Description ErrorStrategy()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static ErrorStrategyalwaysContinue()Specifies that EventSource should never throw an exception, but should return all errors asFaultEvents.static ErrorStrategyalwaysThrow()Specifies that EventSource should always throw an exception if there is an error.abstract ErrorStrategy.Resultapply(StreamException exception)Applies the strategy to determine whether to retry after a failure.static ErrorStrategycontinueWithMaxAttempts(int maxAttempts)Specifies that EventSource should automatically retry after a failure for up to this number of consecutive attempts, but should throw an exception after that point.static ErrorStrategycontinueWithTimeLimit(long maxTime, java.util.concurrent.TimeUnit timeUnit)Specifies that EventSource should automatically retry after a failure and can retry repeatedly until this amount of time has elapsed, but should throw an exception after that point.
-
-
-
Method Detail
-
apply
public abstract ErrorStrategy.Result apply(StreamException exception)
Applies the strategy to determine whether to retry after a failure.- Parameters:
exception- describes the failure- Returns:
- the result
-
alwaysThrow
public static ErrorStrategy alwaysThrow()
Specifies that EventSource should always throw an exception if there is an error. This is the default behavior if you do not configure another.- Returns:
- a strategy to be passed to
EventSource.Builder.errorStrategy(ErrorStrategy).
-
alwaysContinue
public static ErrorStrategy alwaysContinue()
Specifies that EventSource should never throw an exception, but should return all errors asFaultEvents. Be aware that using this mode could causeEventSource.start()to block indefinitely if connections never succeed.- Returns:
- a strategy to be passed to
EventSource.Builder.errorStrategy(ErrorStrategy).
-
continueWithMaxAttempts
public static ErrorStrategy continueWithMaxAttempts(int maxAttempts)
Specifies that EventSource should automatically retry after a failure for up to this number of consecutive attempts, but should throw an exception after that point.- Parameters:
maxAttempts- the maximum number of consecutive retries- Returns:
- a strategy to be passed to
EventSource.Builder.errorStrategy(ErrorStrategy).
-
continueWithTimeLimit
public static ErrorStrategy continueWithTimeLimit(long maxTime, java.util.concurrent.TimeUnit timeUnit)
Specifies that EventSource should automatically retry after a failure and can retry repeatedly until this amount of time has elapsed, but should throw an exception after that point.- Parameters:
maxTime- the time limit, in whatever units are specified bytimeUnittimeUnit- the time unit, orTimeUnit.MILLISECONDSif null- Returns:
- a strategy to be passed to
EventSource.Builder.errorStrategy(ErrorStrategy).
-
-