|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface TaskManager
The TaskManager
contains a collection of tasks that are long running. It schedules them to run
at its discretion, but it does try to run them as soon as possible, assuming there is sufficient resources available.
TaskDescriptor
.
NOTE: All task descriptors returned are a snapshot of the task state when the method returns. So while the task may finish, the TaskDescriptor will
not be updated to reflect that. You must always re-ask the TaskManager for a new TaskDescriptor to find out if a task has finished or not.
Method Summary | ||
---|---|---|
boolean |
awaitUntilActiveTasksComplete(long seconds)
Waits on the TaskManager until all current active tasks are completed. |
|
TaskDescriptor<?> |
findFirstTask(TaskMatcher matcher)
Find the first task that "matches" according to the passed matcher. |
|
Collection<TaskDescriptor<?>> |
findTasks(TaskMatcher matcher)
Find all the tasks that "match" according to the passed matcher. |
|
Collection<TaskDescriptor<?>> |
getAllTasks()
Return a collection of TaskDescriptor s currently within the manager. |
|
|
getLiveTask(TaskContext taskContext)
Return the live task associated with the passed context, if one exists. |
|
Collection<TaskDescriptor<?>> |
getLiveTasks()
Return a collection of sumitted or running TaskDescriptor s in the manager. |
|
|
getTask(Long taskId)
Returns the TaskDescriptor of the task that is identified by the passed id. |
|
boolean |
hasLiveTaskWithContext(TaskContext taskContext)
Returns true if the there are live tasks (running or submitted) that have a task context that is EQUAL to the passed in taskContext. |
|
boolean |
hasTaskWithContext(TaskContext taskContext)
Returns true if the there are any tasks (submitted, running or finished) that have a task context that is EQUAL to the passed in taskContext. |
|
boolean |
removeTask(Long taskId)
Remove a task from the manager. |
|
boolean |
shutdownAndWait(long waitSeconds)
Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. |
|
void |
shutdownNow()
Attempts to aggressively stop all actively executing tasks, halts the processing of waiting tasks. |
|
void |
start()
Start the task manager. |
|
|
submitTask(Callable<V> callable,
String taskDescription,
TaskContext taskContext)
This submits a Callable task to the manager which can then be started at the managers discretion, but hopefully very soon. |
|
|
submitTask(Callable<V> callable,
String taskDescription,
TaskContext taskContext,
boolean cancellable)
This submits a Callable task to the manager which can then be started at the managers discretion, but hopefully very soon. |
Method Detail |
---|
Collection<TaskDescriptor<?>> getAllTasks()
TaskDescriptor
s currently within the manager. This will include
tasks that are yet to start, tasks that are running and completed tasks.
The returned collection is sorted by task id, which should be in addition order.
TaskDescriptor
s. The descriptors returned are a snapshot
of each task state when the method returns will not reflect any future changes. An empty collection
is returned when there are no current tasks.Collection<TaskDescriptor<?>> getLiveTasks()
TaskDescriptor
s in the manager.
The returned collection is sorted by task id, which should be in addition order.
TaskDescriptor
s. The descriptors returned are a snapshot
of each task state when the method returns and will not reflect any future changes. An empty collection
is returned when there are no descriptors to return.<V> TaskDescriptor<V> getLiveTask(@Nonnull TaskContext taskContext)
taskContext
- the context to search for.
null
will be returned
when no matching task can be found.<V> TaskDescriptor<V> getTask(Long taskId)
TaskDescriptor
of the task that is identified by the passed id.
taskId
- the id of the task to retrieve, if null then null will be returned
TaskDescriptor
or null if the manager has not such task. The descriptor returned is a snapshot
of the task state when the method returns will not reflect any future changes. null
will be returned
when no matching task can be found.<V> TaskDescriptor<V> submitTask(@Nonnull Callable<V> callable, @Nonnull String taskDescription, @Nonnull TaskContext taskContext) throws RejectedExecutionException, AlreadyExecutingException
Callable
task to the manager which can then be started at the managers discretion, but hopefully very soon.
The TaskDescriptor
returned is a snapshot of the task's state when the method returns and will not change to reflect
the task's future state changes. The task's ID can be found in the returned TaskDescriptor.
The task is not cancellable.
callable
- the long running tasktaskDescription
- the description of the tasktaskContext
- some stateful context that the task knows about
RejectedExecutionException
- if the task manager is being shutdown and cannot accept new tasks.
AlreadyExecutingException
- if a task with an equal TaskContext is already running in the task manager.<V> TaskDescriptor<V> submitTask(@Nonnull Callable<V> callable, @Nonnull String taskDescription, @Nonnull TaskContext taskContext, boolean cancellable) throws RejectedExecutionException, AlreadyExecutingException
Callable
task to the manager which can then be started at the managers discretion, but hopefully very soon.
The TaskDescriptor
returned is a snapshot of the task's state when the method returns and will not change to reflect
the task's future state changes. The task's ID can be found in the returned TaskDescriptor.
callable
- the long running tasktaskDescription
- the description of the tasktaskContext
- some stateful context that the task knows aboutcancellable
- If set to true indicates that this potentially long running task supports being cancelled.
RejectedExecutionException
- if the task manager is being shutdown and cannot accept new tasks.
AlreadyExecutingException
- if a task with an equal TaskContext is already running in the task manager.boolean removeTask(@Nonnull Long taskId)
taskId
- the task identifier.
void start()
boolean shutdownAndWait(long waitSeconds)
waitSeconds
- the numder of seconds to wait for graceful shutdown.
void shutdownNow()
boolean awaitUntilActiveTasksComplete(long seconds)
seconds
- the number of seconds to wait.
boolean hasTaskWithContext(@Nonnull TaskContext taskContext)
taskContext
- the specific task context (which implements equals() propertly)
boolean hasLiveTaskWithContext(@Nonnull TaskContext taskContext)
taskContext
- the specific task context (which implements equals() propertly)
TaskDescriptor<?> findFirstTask(@Nonnull TaskMatcher matcher)
matcher
- the condition used to find the task.
null
will be returned
when no matching task can be found.Collection<TaskDescriptor<?>> findTasks(@Nonnull TaskMatcher matcher)
matcher
- the condition used to find the task.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |