public abstract class RetryTask extends Object implements TaskManager.Task, TimeConstants
Modifier and Type | Class and Description |
---|---|
private class |
RetryTask.RetryTime
This is the runnable class for the
WakeupManager ,
since we need different implementations of
WakeupManager.run and
TaskManager.run . |
Modifier and Type | Field and Description |
---|---|
private int |
attempt |
private boolean |
cancelled |
private boolean |
complete |
private static long[] |
delays
Default delay backoff times.
|
private static Logger |
logger
Logger for this class
|
private TaskManager |
manager |
private RetryTask.RetryTime |
retry |
private long |
startTime |
private WakeupManager.Ticket |
ticket |
private WakeupManager |
wakeup |
DAYS, HOURS, MINUTES, SECONDS
Constructor and Description |
---|
RetryTask(TaskManager manager,
WakeupManager wakeupManager)
Create a new
RetryTask that will be scheduled with
the given task manager, and which will perform retry scheduling
using the given wakeup manager. |
Modifier and Type | Method and Description |
---|---|
int |
attempt()
Return the attempt number, starting with zero.
|
void |
cancel()
Cancel the retrying of the task.
|
boolean |
cancelled()
Return
true if cancel has been invoked. |
boolean |
complete()
Return
true if tryOnce has returned
successfully. |
void |
reset()
Reset values for a new use of this task.
|
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, or the last
time
reset was called. |
abstract boolean |
tryOnce()
Make a single attempt.
|
boolean |
waitFor() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
runAfter
private TaskManager manager
private RetryTask.RetryTime retry
private boolean cancelled
private boolean complete
private WakeupManager.Ticket ticket
private long startTime
private int attempt
private WakeupManager wakeup
private static final long[] delays
retryTime()
private static final Logger logger
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 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()
reset
was called.public int attempt()
public void cancel()
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 cancelled()
true
if cancel
has been invoked.public boolean complete()
true
if tryOnce
has returned
successfully.public boolean waitFor() throws InterruptedException
InterruptedException
public void reset()
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.