public class IntervalRetryScheduler extends Object implements RetryScheduler
Constructor and Description |
---|
IntervalRetryScheduler(ScheduledExecutorService executor,
int interval,
int maxRetryCount)
Initializes the retry scheduler to schedule retries on the given
executor using the given
interval and allowing maxRetryCount retries before giving up permanently. |
Modifier and Type | Method and Description |
---|---|
protected boolean |
isExplicitlyNonTransient(Throwable failure)
Indicates whether the given
failure is clearly non-transient. |
boolean |
scheduleRetry(CommandMessage commandMessage,
RuntimeException lastFailure,
List<Class<? extends Throwable>[]> failures,
Runnable dispatchTask)
Inspect the given
commandMessage that failed with given lastFailure . |
public IntervalRetryScheduler(ScheduledExecutorService executor, int interval, int maxRetryCount)
executor
using the given
interval
and allowing maxRetryCount
retries before giving up permanently.executor
- The executor on which to schedule retry executioninterval
- The interval in milliseconds at which to schedule a retrymaxRetryCount
- The maximum number of retries allowed for a single commandpublic boolean scheduleRetry(CommandMessage commandMessage, RuntimeException lastFailure, List<Class<? extends Throwable>[]> failures, Runnable dispatchTask)
RetryScheduler
commandMessage
that failed with given lastFailure
. The given
failures
provides a list of previous failures known for this command. The
commandDispatch
task can be used to schedule the command for dispatching.
The return value of this method indicates whether the command has been scheduled for a retry. When
true
, the original callbacks should not be invoked, as command execution is subject to a retry.
When false
, the failure is interpreted as terminal and the callback will be invoked with the last
failure recorded.
If the implementation throws an Exception, that exception is passed as the failure to the original callback.scheduleRetry
in interface RetryScheduler
commandMessage
- The Command Message being dispatchedlastFailure
- The last failure recorded for this commandfailures
- A condensed view of all known failures of this command. Each element in the array
represents the cause of the element preceding it.dispatchTask
- The task to be executed to retry a commandtrue
if the command has been rescheduled, otherwise false
protected boolean isExplicitlyNonTransient(Throwable failure)
failure
is clearly non-transient. That means, whether the
failure
explicitly states that a retry of the same Command would result in the same failure to
occur
again.failure
- The exception that occurred while processing a commandtrue
if the exception is clearly non-transient and the command should not be
retried, or false
when the command has a chance of succeeding if it retried.Copyright © 2010–2018. All rights reserved.