Class Retry
- java.lang.Object
-
- com.couchbase.client.java.util.retry.Retry
-
@Committed @Public public class Retry extends Object
Utility methods to deal with retryingObservables.- Since:
- 2.1
- Author:
- Simon Baslé
-
-
Field Summary
Fields Modifier and Type Field Description static DelayDEFAULT_DELAY
-
Method Summary
All Methods Static Methods Concrete Methods 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 anObservableso 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 anObservableso that it will retry on all errors.static <T> rx.Observable<T>wrapForRetry(rx.Observable<T> source, RetryWithDelayHandler handler)Wrap anObservableso that it will retry on some errors.
-
-
-
Field Detail
-
DEFAULT_DELAY
public static final Delay DEFAULT_DELAY
-
-
Method Detail
-
wrapForRetry
public static <T> rx.Observable<T> wrapForRetry(rx.Observable<T> source, int maxAttempts)Wrap anObservableso 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- theObservableto 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 anObservableso that it will retry on all errors. The retry will occur for a maximum number of attempts and with a providedDelaybetween each attempt.- Type Parameters:
T- the type of items emitted by the source Observable.- Parameters:
source- theObservableto wrap.maxAttempts- the maximum number of times to attempt a retry. It will be capped at.Integer.MAX_VALUE- 1retryDelay- theDelaybetween each attempt.- Returns:
- the wrapped retrying Observable.
-
wrapForRetry
public static <T> rx.Observable<T> wrapForRetry(rx.Observable<T> source, RetryWithDelayHandler handler)Wrap anObservableso that it will retry on some errors. The retry will occur for a maximum number of attempts and with a providedDelaybetween 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- theObservableto 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.
-
-