Class FixedTaskExecutionBackOff

java.lang.Object
com.github.sonus21.rqueue.utils.backoff.FixedTaskExecutionBackOff
All Implemented Interfaces:
TaskExecutionBackOff

public class FixedTaskExecutionBackOff extends Object implements TaskExecutionBackOff
Implementation of the TaskExecutionBackOff class, that always return the same value, except if number of failures have increased too high.

Default delay for the task is 5 seconds, and maximum number of retries is 2147483647.

There's another implementation of this, that provides exponential delay.

See Also:
  • Field Details

    • DEFAULT_INTERVAL

      public static final long DEFAULT_INTERVAL
      The default task delay: 5000 ms = 5 seconds.
      See Also:
  • Constructor Details

    • FixedTaskExecutionBackOff

      public FixedTaskExecutionBackOff()
      Create an instance with an interval of 5000L ms and maximum value of retries.
    • FixedTaskExecutionBackOff

      public FixedTaskExecutionBackOff(long interval, int maxRetries)
      Create an instance.
      Parameters:
      interval - the delay between two attempts.
      maxRetries - the maximum number of retries.
  • Method Details

    • getInterval

      public long getInterval()
      Return the delay between two attempts in milliseconds.
      Returns:
      the configured interval in milliseconds.
    • setInterval

      public void setInterval(long interval)
      Set the delay between two attempts in milliseconds.
      Parameters:
      interval - delay between two attempts.
    • getMaxRetries

      public int getMaxRetries()
      Return the maximum number of retries.
      Returns:
      max retires
    • setMaxRetries

      public void setMaxRetries(int maxRetries)
      Set the maximum number of retries
      Parameters:
      maxRetries - max number of retires
    • nextBackOff

      public long nextBackOff(Object message, RqueueMessage rqueueMessage, int failureCount)
      Description copied from interface: TaskExecutionBackOff
      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:
      message - message that's fetched
      rqueueMessage - raw message
      failureCount - number of times this message has failed.
      Returns:
      backoff in the millisecond.
    • getMaxRetries

      protected int getMaxRetries(Object message, RqueueMessage rqueueMessage, int failureCount)
    • getInterval

      protected long getInterval(Object message, RqueueMessage rqueueMessage, int failureCount)
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object