Class ExponentialTaskExecutionBackOff
java.lang.Object
com.github.sonus21.rqueue.utils.backoff.ExponentialTaskExecutionBackOff
- All Implemented Interfaces:
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
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe default initial delay for the any task: 1500 ms (1.5 seconds)static final longThe default maximum delay for any task (3 hours)static final doubleThe default multiplier (increases the delay by 50%).Fields inherited from interface com.github.sonus21.rqueue.utils.backoff.TaskExecutionBackOff
STOP -
Constructor Summary
ConstructorsConstructorDescriptionExponentialTaskExecutionBackOff(long initialInterval, long maxInterval, double multiplier, int maxRetries) Create an instance. -
Method Summary
Modifier and TypeMethodDescriptionprotected longgetDelay(int failureCount) protected longgetDelay(Object message, RqueueMessage rqueueMessage, int failureCount) longReturn the initial interval in milliseconds.longget max intervalintReturn the maximum number of retries.protected intgetMaxRetries(Object message, RqueueMessage rqueueMessage, int failureCount) doubleget the multiplierlongnextBackOff(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 millisecondsvoidsetMaxRetries(int maxRetries) Set the maximum number of retriesvoidsetMultiplier(double multiplier) Set multiplier
-
Field Details
-
DEFAULT_INITIAL_INTERVAL
public static final long DEFAULT_INITIAL_INTERVALThe default initial delay for the any task: 1500 ms (1.5 seconds)- See Also:
-
DEFAULT_MULTIPLIER
public static final double DEFAULT_MULTIPLIERThe default multiplier (increases the delay by 50%).- See Also:
-
DEFAULT_MAX_INTERVAL
public static final long DEFAULT_MAX_INTERVALThe default maximum delay for any task (3 hours)- See Also:
-
-
Constructor Details
-
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 increased.maxRetries- the maximum retry count for any message.
-
-
Method Details
-
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 milliseconds.
-
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 milliseconds- Parameters:
maxInterval- value in milliseconds
-
nextBackOff
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
-
getDelay
-
getDelay
protected long getDelay(int failureCount)
-