Class Retry


  • public final class Retry
    extends java.lang.Object
    Wrapper function that retries, with exponential backoff, in the event of an exception.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  Retry.RetryableFunction<T>
      Function that adds retries with exponential backoff.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T execute​(Retry.RetryableFunction<T> fn)
      Executes the wrapped function with default maximum number of retries in the event of an exception.
      static <T> T execute​(Retry.RetryableFunction<T> fn, int maxRetries)
      Executes the wrapped function with the specified maximum number of retries in the event of an exception.
      static <T> T execute​(Retry.RetryableFunction<T> fn, int maxRetries, java.util.Collection<java.lang.Class<? extends java.lang.Throwable>> expectedErrors)
      Executes the wrapped function, terminating immediately if one of the expected errors is encountered, otherwise the function will be retried up to the specified maximum number of retries.
      static <T> T execute​(Retry.RetryableFunction<T> fn, java.util.Collection<java.lang.Class<? extends java.lang.Throwable>> expectedErrors)
      Executes the wrapped function, terminating immediately if one of the expected errors is encountered.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • execute

        public static <T> T execute​(Retry.RetryableFunction<T> fn)
        Executes the wrapped function with default maximum number of retries in the event of an exception.
        Type Parameters:
        T - return type of the wrapped function
        Parameters:
        fn - wrapped function to execute
        Returns:
        result of the wrapped function
      • execute

        public static <T> T execute​(Retry.RetryableFunction<T> fn,
                                    int maxRetries)
        Executes the wrapped function with the specified maximum number of retries in the event of an exception.
        Type Parameters:
        T - return type of the wrapped function
        Parameters:
        fn - wrapped function to execute
        maxRetries - maximum number of times to retry the wrapped function in the event of an exception
        Returns:
        result of the wrapped function
      • execute

        public static <T> T execute​(Retry.RetryableFunction<T> fn,
                                    java.util.Collection<java.lang.Class<? extends java.lang.Throwable>> expectedErrors)
        Executes the wrapped function, terminating immediately if one of the expected errors is encountered.
        Type Parameters:
        T - return type of the wrapped function
        Parameters:
        fn - wrapped function to execute
        expectedErrors - a collection of errors that when encountered will cause the function to fail immediately without exhausting the maximum number of retries
        Returns:
        result of the wrapped function
      • execute

        public static <T> T execute​(Retry.RetryableFunction<T> fn,
                                    int maxRetries,
                                    java.util.Collection<java.lang.Class<? extends java.lang.Throwable>> expectedErrors)
        Executes the wrapped function, terminating immediately if one of the expected errors is encountered, otherwise the function will be retried up to the specified maximum number of retries.
        Type Parameters:
        T - return type of the wrapped function
        Parameters:
        fn - wrapped function to execute
        maxRetries - maximum number of times to retry the wrapped function in the event of an exception not specified in the expectedErrors
        expectedErrors - a collection of errors that when encountered will cause the function to fail immediately without exhausting the maximum number of retries
        Returns:
        result of the wrapped function