Class RetryFilter
- java.lang.Object
-
- cn.boboweike.carrot.tasks.filters.RetryFilter
-
- All Implemented Interfaces:
ElectStateFilter,TaskFilter
public class RetryFilter extends Object implements ElectStateFilter
A TaskFilter of typeElectStateFilterthat will retry the task if it fails for up to 10 times with an exponential back-off policy. This TaskFilter is added by default in Carrot.If you want to configure the amount of retries, create a new instance and pass it to the CarrotConfiguration, e.g.:
Carrot.configure() ... .withTaskFilter(new RetryFilter(20, 4)) // this will result in 20 retries and the retries will happen after 4 seconds, 16 seconds, 64 seconds, ... ... .initialize();
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_BACKOFF_POLICY_TIME_SEEDstatic intDEFAULT_NBR_OF_RETRIES
-
Constructor Summary
Constructors Constructor Description RetryFilter()RetryFilter(int numberOfRetries)RetryFilter(int numberOfRetries, int backOffPolicyTimeSeed)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected longgetExponentialBackoffPolicy(Task task, int seed)protected longgetSecondsToAdd(Task task)voidonStateElection(Task task, TaskState newState)
-
-
-
Field Detail
-
DEFAULT_BACKOFF_POLICY_TIME_SEED
public static final int DEFAULT_BACKOFF_POLICY_TIME_SEED
- See Also:
- Constant Field Values
-
DEFAULT_NBR_OF_RETRIES
public static final int DEFAULT_NBR_OF_RETRIES
- See Also:
- Constant Field Values
-
-
Method Detail
-
onStateElection
public void onStateElection(Task task, TaskState newState)
- Specified by:
onStateElectionin interfaceElectStateFilter
-
getSecondsToAdd
protected long getSecondsToAdd(Task task)
-
getExponentialBackoffPolicy
protected long getExponentialBackoffPolicy(Task task, int seed)
-
-