Package com.launchdarkly.eventsource
Class ErrorStrategy
java.lang.Object
com.launchdarkly.eventsource.ErrorStrategy
An 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 ClassesModifier and TypeClassDescriptionstatic enumDescribes the possible actions EventSource could take after an error.static classThe return type ofapply(StreamException). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ErrorStrategySpecifies that EventSource should never throw an exception, but should return all errors asFaultEvents.static ErrorStrategySpecifies 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, 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.
-
Constructor Details
-
ErrorStrategy
public ErrorStrategy()
-
-
Method Details
-
apply
Applies the strategy to determine whether to retry after a failure.- Parameters:
exception- describes the failure- Returns:
- the result
-
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
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
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
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).
-