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 theTaskExecutionBackOffclass, 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 longDEFAULT_INITIAL_INTERVALThe default initial delay for the any task: 1500 ms (1.5 seconds)static longDEFAULT_MAX_INTERVALThe default maximum delay for any task (3 hours)static doubleDEFAULT_MULTIPLIERThe 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 longgetDelay(int failureCount)protected longgetDelay(java.lang.Object message, RqueueMessage rqueueMessage, int failureCount)longgetInitialInterval()Return the initial interval in milliseconds.longgetMaxInterval()get max intervalintgetMaxRetries()Return the maximum number of retries.protected intgetMaxRetries(java.lang.Object message, RqueueMessage rqueueMessage, int failureCount)doublegetMultiplier()get the multiplierlongnextBackOff(java.lang.Object message, RqueueMessage rqueueMessage, int failureCount)Return the number of milliseconds to wait for the same message to be consumed by other consumers.voidsetInitialInterval(long initialInterval)Set the initial interval in milliseconds.voidsetMaxInterval(long maxInterval)Set the max interval in milli secondsvoidsetMaxRetries(int maxRetries)Set the maximum number of retriesvoidsetMultiplier(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 message, 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:
nextBackOffin interfaceTaskExecutionBackOff- Parameters:
message- message that's fetchedrqueueMessage- raw messagefailureCount- number of times this message has failed.- Returns:
- backoff in the millisecond.
-
getMaxRetries
protected int getMaxRetries(java.lang.Object message, RqueueMessage rqueueMessage, int failureCount)
-
getDelay
protected long getDelay(java.lang.Object message, RqueueMessage rqueueMessage, int failureCount)
-
getDelay
protected long getDelay(int failureCount)
-
-