Class Retry
java.lang.Object
com.couchbase.client.java.util.retry.Retry
@Committed @Public public class Retry extends Object
Utility methods to deal with retrying
Observable
s.- Since:
- 2.1
- Author:
- Simon Baslé
-
Field Summary
Fields Modifier and Type Field Description static Delay
DEFAULT_DELAY
-
Method Summary
Modifier and Type Method Description protected static rx.Observable<Tuple2<Integer,Throwable>>
errorsWithAttempts(rx.Observable<? extends Throwable> errors, int expectedAttempts)
Internal utility method to combine errors in an observable with their attempt number.static <T> rx.Observable<T>
wrapForRetry(rx.Observable<T> source, int maxAttempts)
Wrap anObservable
so that it will retry on all errors for a maximum number of times.static <T> rx.Observable<T>
wrapForRetry(rx.Observable<T> source, int maxAttempts, Delay retryDelay)
Wrap anObservable
so that it will retry on all errors.static <T> rx.Observable<T>
wrapForRetry(rx.Observable<T> source, RetryWithDelayHandler handler)
Wrap anObservable
so that it will retry on some errors.
-
Field Details
-
DEFAULT_DELAY
-
-
Method Details
-
wrapForRetry
public static <T> rx.Observable<T> wrapForRetry(rx.Observable<T> source, int maxAttempts)Wrap anObservable
so that it will retry on all errors for a maximum number of times. The retry is almost immediate (1ms delay).- Type Parameters:
T
- the type of items emitted by the source Observable.- Parameters:
source
- theObservable
to wrap.maxAttempts
- the maximum number of times to attempt a retry. It will be capped at
.Integer.MAX_VALUE
- 1- Returns:
- the wrapped retrying Observable.
-
wrapForRetry
public static <T> rx.Observable<T> wrapForRetry(rx.Observable<T> source, int maxAttempts, Delay retryDelay)Wrap anObservable
so that it will retry on all errors. The retry will occur for a maximum number of attempts and with a providedDelay
between each attempt.- Type Parameters:
T
- the type of items emitted by the source Observable.- Parameters:
source
- theObservable
to wrap.maxAttempts
- the maximum number of times to attempt a retry. It will be capped at
.Integer.MAX_VALUE
- 1retryDelay
- theDelay
between each attempt.- Returns:
- the wrapped retrying Observable.
-
wrapForRetry
public static <T> rx.Observable<T> wrapForRetry(rx.Observable<T> source, RetryWithDelayHandler handler)Wrap anObservable
so that it will retry on some errors. The retry will occur for a maximum number of attempts and with a providedDelay
between each attempt represented by theRetryWithDelayHandler
, which can also filter on errors and stop the retry cycle for certain type of errors.- Type Parameters:
T
- the type of items emitted by the source Observable.- Parameters:
source
- theObservable
to wrap.handler
- theRetryWithDelayHandler
, describes maximum number of attempts, delay and fatal errors.- Returns:
- the wrapped retrying Observable.
-
errorsWithAttempts
protected static rx.Observable<Tuple2<Integer,Throwable>> errorsWithAttempts(rx.Observable<? extends Throwable> errors, int expectedAttempts)Internal utility method to combine errors in an observable with their attempt number.- Parameters:
errors
- the errors.expectedAttempts
- the maximum of combinations to make (for retry, should be the maximum number of authorized retries + 1).- Returns:
- an Observable that combines the index/attempt number of each error with its error in a
Tuple2
.
-