Package com.launchdarkly.eventsource
Class ErrorStrategy
- java.lang.Object
-
- com.launchdarkly.eventsource.ErrorStrategy
-
public abstract class ErrorStrategy extends java.lang.Object
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 Classes Modifier and Type Class Description static class
ErrorStrategy.Action
Describes the possible actions EventSource could take after an error.static class
ErrorStrategy.Result
The 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 ErrorStrategy
alwaysContinue()
Specifies that EventSource should never throw an exception, but should return all errors asFaultEvent
s.static ErrorStrategy
alwaysThrow()
Specifies that EventSource should always throw an exception if there is an error.abstract ErrorStrategy.Result
apply(StreamException exception)
Applies the strategy to determine whether to retry after a failure.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.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.
-
-
-
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 asFaultEvent
s. 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 bytimeUnit
timeUnit
- the time unit, orTimeUnit.MILLISECONDS
if null- Returns:
- a strategy to be passed to
EventSource.Builder.errorStrategy(ErrorStrategy)
.
-
-