public abstract class TaskScheduler<K,T extends ScheduledTask<K>> extends Object implements Closeable
ScheduledTasks periodically. Subclasses can implement
startImpl(Optional) and closeImpl().
Implementations of this interface are expected to be thread-safe, and can be safely accessed by multiple concurrent threads.
| Modifier | Constructor and Description |
|---|---|
protected |
TaskScheduler() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
cancel(T task)
Attempts to cancel the specified
ScheduledTask. |
void |
close()
Closes this
TaskScheduler, ensuring that new tasks cannot be created
and cancelling existing tasks. |
com.google.common.base.Optional<T> |
getScheduledTask(K key)
Gets the
ScheduledTask with the specified key. |
Iterable<T> |
getScheduledTasks()
Gets all
ScheduledTasks. |
void |
schedule(T task,
long period,
TimeUnit unit)
Schedules a subclass of
ScheduledTask to run periodically. |
public final void schedule(T task, long period, TimeUnit unit) throws IOException
ScheduledTask to run periodically.task - the subclass of ScheduledTask to run every periodperiod - the period between successive executions of the taskunit - the time unit of the initialDelay and period parametersIOExceptionpublic final Iterable<T> getScheduledTasks()
ScheduledTasks.ScheduledTaskspublic final com.google.common.base.Optional<T> getScheduledTask(K key)
ScheduledTask with the specified key.ScheduledTaskpublic boolean cancel(T task)
ScheduledTask.task - the ScheduledTask to cancelScheduledTask was canceled; otherwise, falsepublic final void close()
throws IOException
TaskScheduler, ensuring that new tasks cannot be created
and cancelling existing tasks.close in interface Closeableclose in interface AutoCloseableIOException - if an I/O error occurs