Class ExponentialBackoff


  • public class ExponentialBackoff
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static double DEFAULT_JITTER  
      static java.time.Duration MAX_BACKOFF  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.function.Function<Multi<java.lang.Throwable>,​org.reactivestreams.Publisher<java.lang.Long>> randomExponentialBackoffFunction​(long numRetries, java.time.Duration firstBackoff, java.time.Duration maxBackoff, double jitterFactor, java.util.concurrent.ScheduledExecutorService executor)
      Computes a method that would delay ticks using an exponential backoff.
      static java.util.function.Function<Multi<java.lang.Throwable>,​org.reactivestreams.Publisher<java.lang.Long>> randomExponentialBackoffFunctionExpireAt​(long expireAt, java.time.Duration firstBackoff, java.time.Duration maxBackoff, double jitterFactor, java.util.concurrent.ScheduledExecutorService executor)
      Computes a method that would delay ticks using an exponential backoff.
      • Methods inherited from class java.lang.Object

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

      • MAX_BACKOFF

        public static final java.time.Duration MAX_BACKOFF
    • Method Detail

      • randomExponentialBackoffFunction

        public static java.util.function.Function<Multi<java.lang.Throwable>,​org.reactivestreams.Publisher<java.lang.Long>> randomExponentialBackoffFunction​(long numRetries,
                                                                                                                                                                   java.time.Duration firstBackoff,
                                                                                                                                                                   java.time.Duration maxBackoff,
                                                                                                                                                                   double jitterFactor,
                                                                                                                                                                   java.util.concurrent.ScheduledExecutorService executor)
        Computes a method that would delay ticks using an exponential backoff.
        Parameters:
        numRetries - the max number of retries
        firstBackoff - the delay of the first backoff
        maxBackoff - the max backoff
        jitterFactor - the jitter factor in [0, 1]
        executor - the executor used for the delay
        Returns:
        the function
      • randomExponentialBackoffFunctionExpireAt

        public static java.util.function.Function<Multi<java.lang.Throwable>,​org.reactivestreams.Publisher<java.lang.Long>> randomExponentialBackoffFunctionExpireAt​(long expireAt,
                                                                                                                                                                           java.time.Duration firstBackoff,
                                                                                                                                                                           java.time.Duration maxBackoff,
                                                                                                                                                                           double jitterFactor,
                                                                                                                                                                           java.util.concurrent.ScheduledExecutorService executor)
        Computes a method that would delay ticks using an exponential backoff. Will keep retrying until an expiration time. The last attempt will start before the expiration time.
        Parameters:
        expireAt - absolute time in millis that specifies when to give up.
        firstBackoff - the delay of the first backoff
        maxBackoff - the max backoff
        jitterFactor - the jitter factor in [0, 1]
        executor - the executor used for the delay
        Returns:
        the function