Class ErrorStrategy

java.lang.Object
com.launchdarkly.eventsource.ErrorStrategy

public abstract class ErrorStrategy extends 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.
  • Constructor Details

    • ErrorStrategy

      public ErrorStrategy()
  • Method Details

    • 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 as FaultEvents. Be aware that using this mode could cause EventSource.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, 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 by timeUnit
      timeUnit - the time unit, or TimeUnit.MILLISECONDS if null
      Returns:
      a strategy to be passed to EventSource.Builder.errorStrategy(ErrorStrategy).