Class RetryBuilder
- java.lang.Object
-
- com.couchbase.client.java.util.retry.RetryBuilder
-
@Committed @Public public class RetryBuilder extends Object
Builder forRetryWhenFunction
. Start withany()
,anyOf(Class[])
orallBut(Class[])
factory methods. By default, without calling additional methods it will retry on the specified exceptions, with a constant delay (seeRetry.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 aCannotRetryException
, which will be emitted via the observable's onError method.- Since:
- 2.1
- Author:
- Simon Baslé
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
RetryBuilder.InversePredicate
static interface
RetryBuilder.OnRetryAction
An interface alias forAction4<Integer, Throwable, Long, TimeUnit>
, suitable fordoOnRetry(Action4)
.protected static class
RetryBuilder.ShouldStopOnError
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static RetryBuilder
allBut(Class<? extends Throwable>... types)
Only errors that are NOT instanceOf the specified types will trigger a retrystatic RetryBuilder
any()
Any error will trigger a retrystatic RetryBuilder
anyMatches(rx.functions.Func1<Throwable,Boolean> retryErrorPredicate)
Any error that pass the predicate will trigger a retrystatic RetryBuilder
anyOf(Class<? extends Throwable>... types)
Only errors that are instanceOf the specified types will trigger a retryRetryWhenFunction
build()
Construct the resultingRetryWhenFunction
RetryBuilder
delay(Delay delay)
Customize the retryDelay
RetryBuilder
delay(Delay delay, rx.Scheduler scheduler)
Set both theDelay
and theScheduler
on which the delay is waited.RetryBuilder
delay(rx.Scheduler scheduler)
UseRetry.DEFAULT_DELAY
but wait on a specificScheduler
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).
-
-
-
Method Detail
-
anyOf
public static RetryBuilder anyOf(Class<? extends Throwable>... types)
Only errors that are instanceOf the specified types will trigger a retry
-
allBut
public static RetryBuilder allBut(Class<? extends Throwable>... types)
Only errors that are NOT instanceOf the specified types will trigger a retry
-
any
public static RetryBuilder any()
Any error will trigger a retry
-
anyMatches
public static RetryBuilder anyMatches(rx.functions.Func1<Throwable,Boolean> retryErrorPredicate)
Any error that pass the predicate will trigger a retry
-
once
public RetryBuilder once()
Make only one retry attempt (default). If an error that can trigger a retry occurs twice in a row, it will be wrapped as the cause inside aCannotRetryException
, which will be emitted via the observable's onError method.
-
max
public RetryBuilder max(int maxAttempts)
Make at most maxAttempts retry attempts. Note that the maximum accepted value is
, the internal retry mechanism will ensure a total ofInteger.MAX_VALUE
- 1maxAttempts + 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 aCannotRetryException
, which will be emitted via the observable's onError method.
-
delay
public RetryBuilder delay(Delay delay)
Customize the retryDelay
-
delay
public RetryBuilder delay(rx.Scheduler scheduler)
UseRetry.DEFAULT_DELAY
but wait on a specificScheduler
-
delay
public RetryBuilder delay(Delay delay, rx.Scheduler scheduler)
Set both theDelay
and theScheduler
on which the delay is waited. If the delay is null,Retry.DEFAULT_DELAY
is used.
-
doOnRetry
public 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). Only quick executing code should be performed, do not block in this action. The action receives the retry attempt number (1-n), the exception that caused the retry, the delay duration and timeunit for the scheduled retry.- Parameters:
doOnRetryAction
- the side-effect action to perform whenever a retry is scheduled.- See Also:
if you want a shorter signature.
-
build
public RetryWhenFunction build()
Construct the resultingRetryWhenFunction
-
-