Class ExponentialTaskExecutionBackOff

  • All Implemented Interfaces:
    TaskExecutionBackOff

    public class ExponentialTaskExecutionBackOff
    extends java.lang.Object
    implements TaskExecutionBackOff
    Implementation of the TaskExecutionBackOff class, that increases the delay exponentially at the specified rate.

    The delay is defined as Math.pow(multiplier, failureCount) * initialInterval.

    Default delay for the task is 1.5 seconds, that increases at the rate of 1.5 on each failure. After a hundred plus failures, it will reach the limit of long value 9223372036854775807L, and no more retry would be possible, by default any task can be delay upto 3 hours 10800000L.

    Using multiplier 1 would mean using the fixed execution back off FixedTaskExecutionBackOff

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected long getDelay​(int failureCount)  
      long getInitialInterval()
      Return the initial interval in milliseconds.
      long getMaxInterval()
      get max interval
      int getMaxRetries()
      Return the maximum number of retries.
      double getMultiplier()
      get the multiplier
      long nextBackOff​(java.lang.Object object, RqueueMessage rqueueMessage, int failureCount)
      Return the number of milliseconds to wait for the same message to be consumed by other consumers.
      void setInitialInterval​(long initialInterval)
      Set the initial interval in milliseconds.
      void setMaxInterval​(long maxInterval)
      Set the max interval in milli seconds
      void setMaxRetries​(int maxRetries)
      Set the maximum number of retries
      void setMultiplier​(double multiplier)
      Set multiplier
      • Methods inherited from class java.lang.Object

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

      • DEFAULT_INITIAL_INTERVAL

        public static final long DEFAULT_INITIAL_INTERVAL
        The default initial delay for the any task: 1500 ms (1.5 seconds)
        See Also:
        Constant Field Values
      • DEFAULT_MULTIPLIER

        public static final double DEFAULT_MULTIPLIER
        The default multiplier (increases the delay by 50%).
        See Also:
        Constant Field Values
      • DEFAULT_MAX_INTERVAL

        public static final long DEFAULT_MAX_INTERVAL
        The default maximum delay for any task (3 hours)
        See Also:
        Constant Field Values
    • Constructor Detail

      • ExponentialTaskExecutionBackOff

        public ExponentialTaskExecutionBackOff()
        Create an instance with an initial interval of 1500L ms, maximum interval of 10800000L, multiplier of 1.5 and default unlimited retries.
      • ExponentialTaskExecutionBackOff

        public ExponentialTaskExecutionBackOff​(long initialInterval,
                                               long maxInterval,
                                               double multiplier,
                                               int maxRetries)
        Create an instance.
        Parameters:
        initialInterval - the initial delay for the message
        maxInterval - the maximum delay for the message.
        multiplier - the factor at which delay would be increases.
        maxRetries - the maximum retry count for any message.
    • Method Detail

      • getInitialInterval

        public long getInitialInterval()
        Return the initial interval in milliseconds.
        Returns:
        configured initial interval.
      • setInitialInterval

        public void setInitialInterval​(long initialInterval)
        Set the initial interval in milliseconds.
        Parameters:
        initialInterval - initial interval in milli seconds.
      • getMaxRetries

        public int getMaxRetries()
        Return the maximum number of retries.
        Returns:
        maximum retries that will be performed.
      • setMaxRetries

        public void setMaxRetries​(int maxRetries)
        Set the maximum number of retries
        Parameters:
        maxRetries - maximum retries
      • getMultiplier

        public double getMultiplier()
        get the multiplier
        Returns:
        multiplier for this back off.
      • setMultiplier

        public void setMultiplier​(double multiplier)
        Set multiplier
        Parameters:
        multiplier - value of the multiplier
      • getMaxInterval

        public long getMaxInterval()
        get max interval
        Returns:
        long value
      • setMaxInterval

        public void setMaxInterval​(long maxInterval)
        Set the max interval in milli seconds
        Parameters:
        maxInterval - value in milli seconds
      • nextBackOff

        public long nextBackOff​(java.lang.Object object,
                                RqueueMessage rqueueMessage,
                                int failureCount)
        Return the number of milliseconds to wait for the same message to be consumed by other consumers. (-1L) to indicate that no further enqueue should be made for the message.
        Specified by:
        nextBackOff in interface TaskExecutionBackOff
        Parameters:
        object - message that's fetched
        rqueueMessage - raw message
        failureCount - number of times this message has failed.
        Returns:
        backoff in the millisecond.
      • getDelay

        protected long getDelay​(int failureCount)