Class DefaultBackoffPolicy

  • All Implemented Interfaces:
    BackoffPolicy

    public final class DefaultBackoffPolicy
    extends java.lang.Object
    implements BackoffPolicy
    A BackoffPolicy that does an 'exponential' backoff. So each next attempt, the calculated delay is increased and randomized (so the next value can be smaller than the previous, but overall they will increase).
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultBackoffPolicy()
      Creates an ExponentialBackoffPolicy with 100 nanoseconds as minimal delay and 100 milliseconds as maximum delay.
      DefaultBackoffPolicy​(long minDelayNs)
      Creates an ExponentialBackoffPolicy with given maximum delay.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected long calcDelayNs​(int attempt)  
      void delay​(int attempt)
      Delays the calling Thread.
      void delayUninterruptible​(int attempt)
      Delays the calling Thread without being interrupted.
      private int f​(int x, double a, double b)  
      • Methods inherited from class java.lang.Object

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

      • minDelayNs

        private final long minDelayNs
      • slotTimes

        private final long[] slotTimes
    • Constructor Detail

      • DefaultBackoffPolicy

        public DefaultBackoffPolicy()
        Creates an ExponentialBackoffPolicy with 100 nanoseconds as minimal delay and 100 milliseconds as maximum delay.
      • DefaultBackoffPolicy

        public DefaultBackoffPolicy​(long minDelayNs)
        Creates an ExponentialBackoffPolicy with given maximum delay.
        Parameters:
        minDelayNs - the minimum delay in nanoseconds to wait. If a negative or zero value provided, it will be interpreted that no external minimal value is needed.
        Throws:
        java.lang.NullPointerException - if unit is null.
    • Method Detail

      • f

        private int f​(int x,
                      double a,
                      double b)
      • delay

        public void delay​(int attempt)
                   throws java.lang.InterruptedException
        Description copied from interface: BackoffPolicy
        Delays the calling Thread.

        The implementation is free to make this a no-op call.

        Specified by:
        delay in interface BackoffPolicy
        Throws:
        java.lang.InterruptedException
      • delayUninterruptible

        public void delayUninterruptible​(int attempt)
        Description copied from interface: BackoffPolicy
        Delays the calling Thread without being interrupted.

        The implementation is free to make this a no-op call.

        Specified by:
        delayUninterruptible in interface BackoffPolicy
        Parameters:
        attempt - the
      • calcDelayNs

        protected long calcDelayNs​(int attempt)