Class RetryUtils


  • public class RetryUtils
    extends java.lang.Object
    • Method Detail

      • executeWithMaxAttempt

        public static void executeWithMaxAttempt​(VeniceCheckedRunnable runnable,
                                                 int maxAttempt,
                                                 java.time.Duration delay,
                                                 java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes)
        Execute a Runnable with fixed delay with a maximum attempt. If all attempts are made and still no success, the last thrown exception will be thrown. This function logs the throwable that failed intermediate execution attempts.
        Parameters:
        runnable - Execution unit which returns nothing (Void)
        maxAttempt - Total maximum attempts made before giving up. Value should be at least one.
        delay - Fixed delay between retry attempts.
        retryFailureTypes - Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it gets thrown to the caller.
      • executeWithMaxAttemptNoIntermediateLogging

        public static void executeWithMaxAttemptNoIntermediateLogging​(VeniceCheckedRunnable runnable,
                                                                      int maxAttempt,
                                                                      java.time.Duration delay,
                                                                      java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes)
        Execute a Runnable with fixed delay with a maximum attempt. If all attempts are made and still no success, the last thrown exception will be thrown. This function does not log the throwable that failed intermediate execution attempts.
        Parameters:
        runnable - Execution unit which returns nothing (Void)
        maxAttempt - Total maximum attempts made before giving up. Value should be at least one.
        delay - Fixed delay between retry attempts.
        retryFailureTypes - Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it gets thrown to the caller.
      • executeWithMaxAttempt

        public static void executeWithMaxAttempt​(VeniceCheckedRunnable runnable,
                                                 int maxAttempt,
                                                 java.time.Duration delay,
                                                 java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes,
                                                 RetryUtils.IntermediateFailureHandler intermediateFailureHandler)
        Execute a Runnable with fixed delay with a maximum attempt. If all attempts are made and still no success, the last thrown exception will be thrown.
        Parameters:
        runnable - Execution unit which returns nothing (Void)
        maxAttempt - Total maximum attempts made before giving up. Value should be at least one.
        delay - Fixed delay between retry attempts.
        retryFailureTypes - Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it gets thrown to the caller.
        intermediateFailureHandler - A handler for intermediate failure(s).
      • executeWithMaxAttemptAndExponentialBackoff

        public static void executeWithMaxAttemptAndExponentialBackoff​(VeniceCheckedRunnable runnable,
                                                                      int maxAttempt,
                                                                      java.time.Duration initialDelay,
                                                                      java.time.Duration maxDelay,
                                                                      java.time.Duration maxDuration,
                                                                      java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes)
        Execute a Runnable with exponential backoff. If all attempts are made or the max duration has reached and still no success, the last thrown exception will be thrown. This function logs the throwable that failed intermediate execution attempts.
        Parameters:
        runnable - Execution unit which returns nothing (Void)
        maxAttempt - Total maximum attempts made before giving up. Value should be at least one.
        initialDelay - First delay duration.
        maxDelay - Maximum delay duration.
        maxDuration - Maximum total execution.
        retryFailureTypes - Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it gets thrown to the caller.
      • executeWithMaxAttemptAndExponentialBackoff

        public static void executeWithMaxAttemptAndExponentialBackoff​(VeniceCheckedRunnable runnable,
                                                                      int maxAttempt,
                                                                      java.time.Duration initialDelay,
                                                                      java.time.Duration maxDelay,
                                                                      java.time.Duration maxDuration,
                                                                      java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes,
                                                                      RetryUtils.IntermediateFailureHandler intermediateFailureHandler)
        Execute a Runnable with exponential backoff. If all attempts are made or the max duration has reached and still no success, the last thrown exception will be thrown.
        Parameters:
        runnable - Execution unit which returns nothing (Void)
        maxAttempt - Total maximum attempts made before giving up. Value should be at least one.
        initialDelay - First delay duration.
        maxDelay - Maximum delay duration.
        maxDuration - Maximum total execution.
        retryFailureTypes - Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it gets thrown to the caller.
        intermediateFailureHandler - A handler for intermediate failure(s).
      • executeWithMaxAttempt

        public static <T> T executeWithMaxAttempt​(VeniceCheckedSupplier<T> supplier,
                                                  int maxAttempt,
                                                  java.time.Duration delay,
                                                  java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes)
        Execute a Supplier with fixed delay with a maximum attempt. If all attempts are made and still no success, the last thrown exception will be thrown. This function logs the throwable that failed intermediate execution attempts.
        Parameters:
        supplier - Execution unit which returns something (RetryUtils)
        maxAttempt - Total maximum attempts made before giving up. Value should be at least one.
        delay - Fixed delay between retry attempts.
        retryFailureTypes - Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it gets thrown to the caller.
      • executeWithMaxAttempt

        public static <T> T executeWithMaxAttempt​(VeniceCheckedSupplier<T> supplier,
                                                  int maxAttempt,
                                                  java.time.Duration delay,
                                                  java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes,
                                                  RetryUtils.IntermediateFailureHandler intermediateFailureHandler)
        Execute a Supplier with fixed delay with a maximum attempt. If all attempts are made and still no success, the last thrown exception will be thrown.
        Parameters:
        supplier - Execution unit which returns something (RetryUtils)
        maxAttempt - Total maximum attempts made before giving up. Value should be at least one.
        delay - Fixed delay between retry attempts.
        retryFailureTypes - Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it gets thrown to the caller.
        intermediateFailureHandler - A handler for intermediate failure(s).
      • executeWithMaxAttemptAndExponentialBackoff

        public static <T> T executeWithMaxAttemptAndExponentialBackoff​(VeniceCheckedSupplier<T> supplier,
                                                                       int maxAttempt,
                                                                       java.time.Duration initialDelay,
                                                                       java.time.Duration maxDelay,
                                                                       java.time.Duration maxDuration,
                                                                       java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes)
        Execute a Supplier with exponential backoff. If all attempts are made or the max duration has reached and still no success, the last thrown exception will be thrown. This function logs the throwable that failed intermediate execution attempts.
        Parameters:
        supplier - Execution unit which returns something (RetryUtils)
        maxAttempt - Total maximum attempts made before giving up. Value should be at least one.
        initialDelay - First delay duration.
        maxDelay - Maximum delay duration.
        maxDuration - Maximum total execution.
        retryFailureTypes - Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it gets thrown to the caller.
      • executeWithMaxAttemptAndExponentialBackoff

        public static <T> T executeWithMaxAttemptAndExponentialBackoff​(VeniceCheckedSupplier<T> supplier,
                                                                       int maxAttempt,
                                                                       java.time.Duration initialDelay,
                                                                       java.time.Duration maxDelay,
                                                                       java.time.Duration maxDuration,
                                                                       java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes,
                                                                       RetryUtils.IntermediateFailureHandler intermediateFailureHandler)
        Execute a Supplier with exponential backoff. If all attempts are made or the max duration has reached and still no success, the last thrown exception will be thrown.
        Parameters:
        supplier - Execution unit which returns something (RetryUtils)
        maxAttempt - Total maximum attempts made before giving up. Value should be at least one.
        initialDelay - First delay duration.
        maxDelay - Maximum delay duration.
        maxDuration - Maximum total execution.
        retryFailureTypes - Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it get thrown to the caller.
        intermediateFailureHandler - A handler for intermediate failure(s).
      • executeWithMaxRetriesAndFixedAttemptDuration

        public static <T> T executeWithMaxRetriesAndFixedAttemptDuration​(VeniceCheckedSupplier<T> supplier,
                                                                         int maxRetry,
                                                                         java.time.Duration durationPerAttempt,
                                                                         java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes)
        Execute a Supplier with maximum retries and fix duration per retry attempt. If all attempts are made and still no success, the last thrown exception will be thrown.
        Parameters:
        supplier - Execution unit which returns something (RetryUtils)
        maxRetry - Total maximum retries made before giving up.
        durationPerAttempt - Total duration per attempt. The delay after attempt will be the (duration per attempt - time spent in the current attempt).
        retryFailureTypes - Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it is thrown to the caller.