@InterfaceStability.Committed @InterfaceAudience.Public public class RetryBuilder extends Object
RetryWhenFunction
. Start with any()
, anyOf(Class[])
or allBut(Class[])
factory methods.
By default, without calling additional methods it will retry on the specified exceptions, with a constant delay
(see Retry.DEFAULT_DELAY
), and only once.
Note that if retriable errors keep occurring more than the maximum allowed number of attempts, the last error that
triggered the extraneous attempt will be wrapped as the cause inside a CannotRetryException
, which will be
emitted via the observable's onError method.Modifier and Type | Class and Description |
---|---|
protected static class |
RetryBuilder.InversePredicate |
static interface |
RetryBuilder.OnRetryAction
An interface alias for
Action4<Integer, Throwable, Long, TimeUnit> , suitable
for doOnRetry(Action4) . |
protected static class |
RetryBuilder.ShouldStopOnError |
Modifier and Type | Method and Description |
---|---|
static RetryBuilder |
allBut(Class<? extends Throwable>... types)
Only errors that are NOT instanceOf the specified types will trigger a retry
|
static RetryBuilder |
any()
Any error will trigger a retry
|
static RetryBuilder |
anyMatches(rx.functions.Func1<Throwable,Boolean> retryErrorPredicate)
Any error that pass the predicate will trigger a retry
|
static RetryBuilder |
anyOf(Class<? extends Throwable>... types)
Only errors that are instanceOf the specified types will trigger a retry
|
RetryWhenFunction |
build()
Construct the resulting
RetryWhenFunction |
RetryBuilder |
delay(Delay delay)
Customize the retry
Delay |
RetryBuilder |
delay(Delay delay,
rx.Scheduler scheduler)
Set both the
Delay and the Scheduler on which the delay is waited. |
RetryBuilder |
delay(rx.Scheduler scheduler)
Use
Retry.DEFAULT_DELAY but wait on a specific Scheduler |
RetryBuilder |
doOnRetry(rx.functions.Action4<Integer,Throwable,Long,TimeUnit> doOnRetryAction)
Execute some code each time a retry is scheduled (at the moment the retriable exception
is caught, but before the retry delay is applied).
|
RetryBuilder |
max(int maxAttempts)
Make at most maxAttempts retry attempts.
|
RetryBuilder |
once()
Make only one retry attempt (default).
|
public static RetryBuilder anyOf(Class<? extends Throwable>... types)
public static RetryBuilder allBut(Class<? extends Throwable>... types)
public static RetryBuilder any()
public static RetryBuilder anyMatches(rx.functions.Func1<Throwable,Boolean> retryErrorPredicate)
public RetryBuilder once()
CannotRetryException
, which will be emitted via the observable's onError method.public RetryBuilder max(int maxAttempts)
Integer.MAX_VALUE
- 1
, the internal retry mechanism will ensure a total of maxAttempts + 1
total attempts,
accounting for the original call.
If an error that can trigger a retry occurs more that maxAttempts, it will be wrapped as the
cause inside a CannotRetryException
, which will be emitted via the observable's onError method.public RetryBuilder delay(Delay delay)
Delay
public RetryBuilder delay(rx.Scheduler scheduler)
Retry.DEFAULT_DELAY
but wait on a specific Scheduler
public RetryBuilder delay(Delay delay, rx.Scheduler scheduler)
Delay
and the Scheduler
on which the delay is waited.
If the delay is null, Retry.DEFAULT_DELAY
is used.public RetryBuilder doOnRetry(rx.functions.Action4<Integer,Throwable,Long,TimeUnit> doOnRetryAction)
doOnRetryAction
- the side-effect action to perform whenever a retry is scheduled.if you want a shorter signature.
public RetryWhenFunction build()
RetryWhenFunction
Copyright © 2015 Couchbase, Inc.