Class 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.
    • Constructor Detail

      • ErrorStrategy

        public ErrorStrategy()
    • 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
      • 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 by timeUnit
        timeUnit - the time unit, or TimeUnit.MILLISECONDS if null
        Returns:
        a strategy to be passed to EventSource.Builder.errorStrategy(ErrorStrategy).