Class Retries


  • public final class Retries
    extends Object
    Retry utilities.
    • Method Detail

      • retryable

        public static <U,​V> Function<U,​V> retryable​(Function<U,​V> base,
                                                                Class<? extends Throwable> exceptionClass,
                                                                int maxRetries,
                                                                int maxDelayBetweenRetries)
        Returns a function that retries execution on failure.
        Type Parameters:
        U - type of function input
        V - type of function output
        Parameters:
        base - base function
        exceptionClass - type of exception for which to retry
        maxRetries - max number of retries before giving up
        maxDelayBetweenRetries - max delay between successive retries. The actual delay is randomly picked from the interval (0, maxDelayBetweenRetries]
        Returns:
        function
      • retryable

        public static <V> Supplier<V> retryable​(Supplier<V> base,
                                                Class<? extends Throwable> exceptionClass,
                                                int maxRetries,
                                                int maxDelayBetweenRetries)
        Returns a Supplier that retries execution on failure.
        Type Parameters:
        V - type of supplied result
        Parameters:
        base - base supplier
        exceptionClass - type of exception for which to retry
        maxRetries - max number of retries before giving up
        maxDelayBetweenRetries - max delay between successive retries. The actual delay is randomly picked from the interval (0, maxDelayBetweenRetries]
        Returns:
        supplier
      • randomDelay

        public static void randomDelay​(int ms)
        Suspends the current thread for a random number of millis between 0 and the indicated limit.
        Parameters:
        ms - max number of millis
      • delay

        public static void delay​(int ms,
                                 int nanos)
        Suspends the current thread for a specified number of millis and nanos.
        Parameters:
        ms - number of millis
        nanos - number of nanos