Class RetryStrategy
-
- All Implemented Interfaces:
public class RetryStrategyA retry strategy for doing some job. It allows to specify initial delay before the task is started as well as retry delay. It will be executed as long as the task
Callablereturns true. It is also possible to configure whether the retries should be continued after unexpected exception or not. If we decide to not continue retries from outside the task cancel method will prevent from scheduling future retries(but it will not interrupt currently executing one). Check with isCancelled to stop the operation in progress. See "RetryStrategyTest" for usage samples.Pawel Domas
-
-
Constructor Summary
Constructors Constructor Description RetryStrategy()Creates new RetryStrategy instance that will use ScheduledExecutorService with pool size of 1 thread to schedule retry attempts. RetryStrategy(ScheduledExecutorService retryExecutor)Creates new instance of RetryStrategy that will use given ScheduledExecutorService to schedule retry attempts.
-
Method Summary
Modifier and Type Method Description synchronized voidcancel()Cancels any future retry attempts. synchronized booleanisCancelled()Returns true if this retry strategy has been cancelled or false otherwise. synchronized voidrunRetryingTask(RetryTask task)Start given RetryTask that will be executed for the first time after getInitialDelay. -
-
Constructor Detail
-
RetryStrategy
RetryStrategy()
Creates new RetryStrategy instance that will use ScheduledExecutorService with pool size of 1 thread to schedule retry attempts.
-
RetryStrategy
RetryStrategy(ScheduledExecutorService retryExecutor)
Creates new instance of RetryStrategy that will use given ScheduledExecutorService to schedule retry attempts.- Parameters:
retryExecutor- ScheduledExecutorService that will be used for scheduling retry attempts.
-
-
Method Detail
-
cancel
synchronized void cancel()
Cancels any future retry attempts. Currently running tasks are not interrupted.
-
isCancelled
synchronized boolean isCancelled()
Returns true if this retry strategy has been cancelled or false otherwise.
-
runRetryingTask
synchronized void runRetryingTask(RetryTask task)
Start given RetryTask that will be executed for the first time after getInitialDelay. After first execution next retry attempts will be rescheduled as long as it's callable method returns true or until (cancel is called.
- Parameters:
task- the retry task to be employed by this retry strategy instance
-
-
-
-