Class ExponentialTaskExecutionBackOff
- java.lang.Object
-
- com.github.sonus21.rqueue.utils.backoff.ExponentialTaskExecutionBackOff
-
- All Implemented Interfaces:
TaskExecutionBackOff
public class ExponentialTaskExecutionBackOff extends java.lang.Object implements TaskExecutionBackOff
Implementation of theTaskExecutionBackOff
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
-
-
Field Summary
Fields Modifier and Type Field Description static long
DEFAULT_INITIAL_INTERVAL
The default initial delay for the any task: 1500 ms (1.5 seconds)static long
DEFAULT_MAX_INTERVAL
The default maximum delay for any task (3 hours)static double
DEFAULT_MULTIPLIER
The default multiplier (increases the delay by 50%).-
Fields inherited from interface com.github.sonus21.rqueue.utils.backoff.TaskExecutionBackOff
STOP
-
-
Constructor Summary
Constructors Constructor Description ExponentialTaskExecutionBackOff()
ExponentialTaskExecutionBackOff(long initialInterval, long maxInterval, double multiplier, int maxRetries)
Create an instance.
-
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 intervalint
getMaxRetries()
Return the maximum number of retries.double
getMultiplier()
get the multiplierlong
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 secondsvoid
setMaxRetries(int maxRetries)
Set the maximum number of retriesvoid
setMultiplier(double multiplier)
Set multiplier
-
-
-
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()
-
ExponentialTaskExecutionBackOff
public ExponentialTaskExecutionBackOff(long initialInterval, long maxInterval, double multiplier, int maxRetries)
Create an instance.- Parameters:
initialInterval
- the initial delay for the messagemaxInterval
- 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 interfaceTaskExecutionBackOff
- Parameters:
object
- message that's fetchedrqueueMessage
- raw messagefailureCount
- number of times this message has failed.- Returns:
- backoff in the millisecond.
-
getDelay
protected long getDelay(int failureCount)
-
-