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 Summary
Fields Modifier and Type Field Description protected rx.functions.Action4<Integer,Throwable,Long,TimeUnit>
doOnRetry
protected rx.functions.Func1<Throwable,Boolean>
errorInterruptingPredicate
protected int
maxAttempts
protected rx.Scheduler
optionalScheduler
protected Delay
retryDelay
-
Constructor Summary
Constructors Modifier Constructor Description RetryWithDelayHandler(int maxAttempts, Delay retryDelay)
Construct aretry handler
that will retry on all errors.RetryWithDelayHandler(int maxAttempts, Delay retryDelay, rx.functions.Func1<Throwable,Boolean> errorInterruptingPredicate, rx.functions.Action4<Integer,Throwable,Long,TimeUnit> doOnRetry)
Construct aretry handler
that will retry on most errors but will stop on specific errors.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 aScheduler
for the delay, especially useful for tests.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description rx.Observable<?>
call(Tuple2<Integer,Throwable> attemptError)
protected static String
messageForMaxAttempts(long reachedAfterNRetries)
-
-
-
Constructor Detail
-
RetryWithDelayHandler
public RetryWithDelayHandler(int maxAttempts, Delay retryDelay)
Construct aretry handler
that will retry on all errors.- Parameters:
maxAttempts
- the maximum number of retries before aCannotRetryException
is thrown. It will be capped at
.Integer.MAX_VALUE
- 1retryDelay
- theDelay
to apply between each retry (can grow, eg. by usingExponentialDelay
).
-
RetryWithDelayHandler
public RetryWithDelayHandler(int maxAttempts, Delay retryDelay, rx.functions.Func1<Throwable,Boolean> errorInterruptingPredicate, rx.functions.Action4<Integer,Throwable,Long,TimeUnit> doOnRetry)
Construct aretry handler
that will retry on most errors but will stop on specific errors.- Parameters:
maxAttempts
- the maximum number of retries before aCannotRetryException
is thrown. It will be capped at
.Integer.MAX_VALUE
- 1retryDelay
- theDelay
to apply between each retry (can grow, eg. by usingExponentialDelay
).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 aScheduler
for the delay, especially useful for tests.
-
-