Class Retry


  • @Committed
    @Public
    public class Retry
    extends Object
    Utility methods to deal with retrying Observables.
    Since:
    2.1
    Author:
    Simon Baslé
    • 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 an Observable 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 - the Observable 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 an Observable so that it will retry on all errors. The retry will occur for a maximum number of attempts and with a provided Delay between each attempt.
        Type Parameters:
        T - the type of items emitted by the source Observable.
        Parameters:
        source - the Observable to wrap.
        maxAttempts - the maximum number of times to attempt a retry. It will be capped at Integer.MAX_VALUE - 1.
        retryDelay - the Delay between each attempt.
        Returns:
        the wrapped retrying Observable.
      • wrapForRetry

        public static <T> rx.Observable<T> wrapForRetry​(rx.Observable<T> source,
                                                        RetryWithDelayHandler handler)
        Wrap an Observable so that it will retry on some errors. The retry will occur for a maximum number of attempts and with a provided Delay between each attempt represented by the RetryWithDelayHandler, 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 - the Observable to wrap.
        handler - the RetryWithDelayHandler, 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.