Class RetryUtils


  • public class RetryUtils
    extends Object
    • Constructor Detail

      • RetryUtils

        public RetryUtils()
    • Method Detail

      • retry

        public static <T> T retry​(RetryUtils.Task<T> f,
                                  com.google.common.base.Predicate<Throwable> shouldRetry,
                                  int quietTries,
                                  int maxTries,
                                  @Nullable
                                  RetryUtils.CleanupAfterFailure cleanupAfterFailure,
                                  @Nullable
                                  String messageOnRetry)
                           throws Exception
        Retry an operation using fuzzy exponentially increasing backoff. The wait time after the nth failed attempt is min(60000ms, 1000ms * pow(2, n - 1)), fuzzed by a number drawn from a Gaussian distribution with mean 0 and standard deviation 0.2. If maxTries is exhausted, or if shouldRetry returns false, the last exception thrown by "f" will be thrown by this function.
        Parameters:
        f - the operation
        shouldRetry - predicate determining whether we should retry after a particular exception thrown by "f"
        quietTries - first quietTries attempts will log exceptions at DEBUG level rather than WARN
        maxTries - maximum number of attempts
        Returns:
        result of the first successful operation
        Throws:
        Exception - if maxTries is exhausted, or shouldRetry returns false
      • nextRetrySleepMillis

        public static long nextRetrySleepMillis​(int nTry)