Class Backoff


  • public class Backoff
    extends java.lang.Object
    Implements various backoff strategies.

    Strategies are defined by a Stream of durations and are intended to determine the duration after which a task is to be retried.

    • Constructor Summary

      Constructors 
      Constructor Description
      Backoff()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.stream.Stream<java.lang.Long> constant​(long startMs)
      Create a stream with constant backoffs.
      static java.util.stream.Stream<java.lang.Long> decorrelatedJittered​(long startMs, long maxMs)
      Create an infinite backoffs that have jitter with a random distribution between startMs and 3 times the previously selected value, capped at maxMs.
      static java.util.stream.Stream<java.lang.Long> equalJittered​(long startMs, long maxMs)
      Create infinite backoffs that keep half of the exponential growth, and jitter between 0 and that amount.
      static java.util.stream.Stream<java.lang.Long> exponential​(long startMs, int multiplier, long maxMs)
      Create a stream with exponential backoffs.
      static java.util.stream.Stream<java.lang.Long> exponentialJittered​(long startMs, long maxMs)
      Create a stream of exponential backoffs with jitters.
      • Methods inherited from class java.lang.Object

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

      • Backoff

        public Backoff()
    • Method Detail

      • constant

        public static java.util.stream.Stream<java.lang.Long> constant​(long startMs)
        Create a stream with constant backoffs.
        Parameters:
        startMs - initial backoff in milliseconds
        Returns:
        a stream with constant backoff values.
      • exponential

        public static java.util.stream.Stream<java.lang.Long> exponential​(long startMs,
                                                                          int multiplier,
                                                                          long maxMs)
        Create a stream with exponential backoffs.
        Parameters:
        startMs - initial backoff in milliseconds.
        multiplier - the multiplier for next backoff.
        maxMs - max backoff in milliseconds.
        Returns:
        a stream with exponential backoffs.
      • exponentialJittered

        public static java.util.stream.Stream<java.lang.Long> exponentialJittered​(long startMs,
                                                                                  long maxMs)
        Create a stream of exponential backoffs with jitters.

        This is "full jitter" via http://www.awsarchitectureblog.com/2015/03/backoff.html

        Parameters:
        startMs - initial backoff in milliseconds.
        maxMs - max backoff in milliseconds.
        Returns:
        a stream of exponential backoffs with jitters.
      • decorrelatedJittered

        public static java.util.stream.Stream<java.lang.Long> decorrelatedJittered​(long startMs,
                                                                                   long maxMs)
        Create an infinite backoffs that have jitter with a random distribution between startMs and 3 times the previously selected value, capped at maxMs.

        this is "decorrelated jitter" via http://www.awsarchitectureblog.com/2015/03/backoff.html

        Parameters:
        startMs - initial backoff in milliseconds
        maxMs - max backoff in milliseconds
        Returns:
        a stream of jitter backoffs.
      • equalJittered

        public static java.util.stream.Stream<java.lang.Long> equalJittered​(long startMs,
                                                                            long maxMs)
        Create infinite backoffs that keep half of the exponential growth, and jitter between 0 and that amount.

        this is "equal jitter" via http://www.awsarchitectureblog.com/2015/03/backoff.html

        Parameters:
        startMs - initial backoff in milliseconds.
        maxMs - max backoff in milliseconds.
        Returns:
        a stream of exponential backoffs with jitters.