V - public abstract class RetryTask<V> extends Object implements RunnableFuture<V>, FutureObserver.ObservableFuture<V>, TimeConstants
| Modifier and Type | Field and Description |
|---|---|
protected static Logger |
logger
Logger for this class
|
DAYS, HOURS, MINUTES, SECONDS| Constructor and Description |
|---|
RetryTask(ExecutorService executor,
WakeupManager wakeupManager)
Create a new
RetryTask that will be scheduled with
the given executor service, and which will perform retry scheduling
using the given wakeup manager. |
RetryTask(TaskManager manager,
WakeupManager wakeupManager)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addObserver(FutureObserver<V> listener) |
int |
attempt()
Return the attempt number, starting with zero.
|
boolean |
cancel(boolean mayInterruptIfRunning)
Cancel the retrying of the task.
|
V |
get() |
V |
get(long time,
TimeUnit unit) |
boolean |
isCancelled()
Return
true if cancel has been invoked. |
boolean |
isDone()
Return
true if tryOnce has returned
successfully. |
long |
retryTime()
Return the next time at which we should make another attempt.
|
void |
run()
The
run method used as a
TaskManager.Task. |
long |
startTime()
Return the time this task was created.
|
abstract boolean |
tryOnce()
Make a single attempt.
|
boolean |
waitFor(long duration) |
protected static final Logger logger
@Deprecated public RetryTask(TaskManager manager, WakeupManager wakeupManager)
RetryTask that will be scheduled with
the given task manager, and which will perform retry scheduling
using the given wakeup manager.public RetryTask(ExecutorService executor, WakeupManager wakeupManager)
RetryTask that will be scheduled with
the given executor service, and which will perform retry scheduling
using the given wakeup manager.
TaskManager's Task.runAfter() is not called when using
this constructor.executor - wakeupManager - public boolean addObserver(FutureObserver<V> listener)
addObserver in interface FutureObserver.ObservableFuture<V>public abstract boolean tryOnce()
true if the attempt
was successful. If the attempt is not successful, the task
will be scheduled for a future retry.public void run()
run method used as a
TaskManager.Task. This invokes
tryOnce. If it is not successful, it schedules
the task for a future retry at the time it gets by invoking
retryTime.public long retryTime()
The implementation is free to do as it pleases with the policy here. The default implementation is to delay using intervals of 1 second, 5 seconds, 10 seconds, 1 minute, and 1 minute between attempts, and then retrying every five minutes forever.
The default implementation assumes it is being called from
the default run method and that the current thread
holds the lock on this object. If the caller does
not own the lock the result is undefined and could result in an
exception.
public long startTime()
public int attempt()
public boolean cancel(boolean mayInterruptIfRunning)
tryOnce. It will not
interfere with any ongoing invocation of tryOnce
unless a subclass overrides this to do so. Any override of this
method should invoke super.cancel().public boolean isCancelled()
true if cancel has been invoked.isCancelled in interface Future<V>public boolean isDone()
true if tryOnce has returned
successfully.public boolean waitFor(long duration)
throws InterruptedException
InterruptedExceptionpublic V get() throws InterruptedException, ExecutionException
get in interface Future<V>InterruptedExceptionExecutionExceptionpublic V get(long time, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
get in interface Future<V>InterruptedExceptionExecutionExceptionTimeoutExceptionCopyright © 2016–2018 The Apache Software Foundation. All rights reserved.