Class RetryWithDelayHandler

java.lang.Object
com.couchbase.client.java.util.retry.RetryWithDelayHandler
All Implemented Interfaces:
rx.functions.Func1<Tuple2<Integer,​Throwable>,​rx.Observable<?>>, rx.functions.Function

@Committed
@Public
public class RetryWithDelayHandler
extends Object
implements rx.functions.Func1<Tuple2<Integer,​Throwable>,​rx.Observable<?>>
A class that allows to produce a "retry" delay depending on the number of retry attempts. The number of retries is bounded by a maximum number of attempts.
Since:
2.1
Author:
Simon Baslé
See Also:
how to wrap an Observable with this behavior, how to chain this behavior into an Observable's retryWhen operation., how to construct a RetryWhenFunction in a fluent manner.
  • Field Details

    • maxAttempts

      protected final int maxAttempts
    • retryDelay

      protected final Delay retryDelay
    • errorInterruptingPredicate

      protected final rx.functions.Func1<Throwable,​Boolean> errorInterruptingPredicate
    • optionalScheduler

      protected final rx.Scheduler optionalScheduler
    • doOnRetry

      protected final rx.functions.Action4<Integer,​Throwable,​Long,​TimeUnit> doOnRetry
  • Constructor Details

    • RetryWithDelayHandler

      public RetryWithDelayHandler​(int maxAttempts, Delay retryDelay)
      Construct a retry handler that will retry on all errors.
      Parameters:
      maxAttempts - the maximum number of retries before a CannotRetryException is thrown. It will be capped at Integer.MAX_VALUE - 1.
      retryDelay - the Delay to apply between each retry (can grow, eg. by using ExponentialDelay).
    • RetryWithDelayHandler

      public RetryWithDelayHandler​(int maxAttempts, Delay retryDelay, rx.functions.Func1<Throwable,​Boolean> errorInterruptingPredicate, rx.functions.Action4<Integer,​Throwable,​Long,​TimeUnit> doOnRetry)
      Construct a retry handler that will retry on most errors but will stop on specific errors.
      Parameters:
      maxAttempts - the maximum number of retries before a CannotRetryException is thrown. It will be capped at Integer.MAX_VALUE - 1.
      retryDelay - the Delay to apply between each retry (can grow, eg. by using ExponentialDelay).
      errorInterruptingPredicate - a predicate that determine if an error must stop the retry cycle (when true), in which case said error is cascaded down.
    • RetryWithDelayHandler

      protected RetryWithDelayHandler​(int maxAttempts, Delay retryDelay, rx.functions.Func1<Throwable,​Boolean> errorInterruptingPredicate, rx.functions.Action4<Integer,​Throwable,​Long,​TimeUnit> doOnRetry, rx.Scheduler scheduler)
      Protected constructor that also allows to set a Scheduler for the delay, especially useful for tests.
  • Method Details

    • messageForMaxAttempts

      protected static String messageForMaxAttempts​(long reachedAfterNRetries)
    • call

      public rx.Observable<?> call​(Tuple2<Integer,​Throwable> attemptError)
      Specified by:
      call in interface rx.functions.Func1<Tuple2<Integer,​Throwable>,​rx.Observable<?>>