public class TaskManagerImpl extends Object implements TaskManager, TaskProgressListener
TaskManager
. This manager uses an ExecutorService
to
run submitted tasks.Modifier and Type | Field and Description |
---|---|
static String |
TASK_CANCEL |
Constructor and Description |
---|
TaskManagerImpl(JiraAuthenticationContext authenticationContext,
MessageHandlerService messageHandlerService,
com.atlassian.cache.CacheManager cacheManager,
org.ofbiz.core.entity.DelegatorInterface delegatorInterface,
UserManager userManager) |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitUntilActiveTasksComplete(long seconds)
Waits on the TaskManager until all current active tasks are completed.
|
void |
cancelTask(Long taskId)
Cancel a running task.
|
void |
cancelTaskIfRunningLocally(Long taskId)
Cancel a running task if it is running on this cluster node.
|
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. |
<V extends Serializable> |
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. |
<V extends Serializable> |
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 |
isCancellable(Long taskId)
Returns true if the task can be cancelled.
|
boolean |
isCancelled(Long taskId)
Return true if this task has been cancelled.
|
void |
onProgressMade(TaskProgressEvent event)
Called to indicate that task progress has been made.
|
void |
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.
|
boolean |
shutdownAndWait(long timeout,
TimeUnit unit)
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.
|
<V extends Serializable> |
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. |
<V extends Serializable> |
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. |
void |
waitUntilTaskCompletes(Long taskId)
Wait for a specific task to complete.
|
public static final String TASK_CANCEL
public TaskManagerImpl(JiraAuthenticationContext authenticationContext, MessageHandlerService messageHandlerService, com.atlassian.cache.CacheManager cacheManager, org.ofbiz.core.entity.DelegatorInterface delegatorInterface, UserManager userManager)
public <V extends Serializable> TaskDescriptor<V> submitTask(@Nonnull Callable<V> callable, @Nonnull String taskDescription, @Nonnull TaskContext taskContext) throws RejectedExecutionException
TaskManager
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.submitTask
in interface TaskManager
callable
- the long running tasktaskDescription
- the description of the tasktaskContext
- some stateful context that the task knows aboutRejectedExecutionException
- 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.public <V extends Serializable> TaskDescriptor<V> submitTask(@Nonnull Callable<V> callable, @Nonnull String taskDescription, @Nonnull TaskContext taskContext, boolean cancellable) throws RejectedExecutionException
TaskManager
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.submitTask
in interface TaskManager
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.public void removeTask(@Nonnull Long taskId)
TaskManager
removeTask
in interface TaskManager
taskId
- the task identifier.public void cancelTask(@Nonnull Long taskId) throws IllegalStateException
TaskManager
cancelTask
in interface TaskManager
taskId
- the task identifier.IllegalStateException
- if the task is not cancellablepublic void cancelTaskIfRunningLocally(@Nonnull Long taskId)
TaskManager
cancelTaskIfRunningLocally
in interface TaskManager
taskId
- the task identifier.public boolean isCancellable(@Nonnull Long taskId)
TaskManager
isCancellable
in interface TaskManager
taskId
- the task identifier.public boolean isCancelled(Long taskId)
TaskManager
isCancelled
in interface TaskManager
taskId
- the task identifier.public void start()
TaskManager
start
in interface TaskManager
public boolean shutdownAndWait(long waitSeconds)
TaskManager
It will wait for at most waitSeconds
and then
return true if the underlying execution threads are terminated completely.
shutdownAndWait
in interface TaskManager
waitSeconds
- the maximum number of seconds to wait for graceful shutdown.public boolean shutdownAndWait(long timeout, TimeUnit unit)
TaskManager
It will wait for at most timeout
and then return true if the underlying execution threads are
terminated completely.
shutdownAndWait
in interface TaskManager
timeout
- the maximum time to wait for a graceful shutdown.unit
- the time unit of the timeout argument.public void shutdownNow()
TaskManager
shutdownNow
in interface TaskManager
public boolean awaitUntilActiveTasksComplete(long seconds)
TaskManager
awaitUntilActiveTasksComplete
in interface TaskManager
seconds
- the number of seconds to wait.public void waitUntilTaskCompletes(Long taskId) throws ExecutionException, InterruptedException
TaskManager
waitUntilTaskCompletes
in interface TaskManager
taskId
- Id of task to wait forExecutionException
InterruptedException
public <V extends Serializable> TaskDescriptor<V> getLiveTask(@Nonnull TaskContext taskContext)
TaskManager
getLiveTask
in interface TaskManager
taskContext
- the context to search for.null
will be returned
when no matching task can be found.public <V extends Serializable> TaskDescriptor<V> getTask(Long taskId)
TaskManager
TaskDescriptor
of the task that is identified by the passed id.getTask
in interface TaskManager
taskId
- the id of the task to retrieve, if null then null will be returnedTaskDescriptor
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.public boolean hasLiveTaskWithContext(@Nonnull TaskContext taskContext)
TaskManager
hasLiveTaskWithContext
in interface TaskManager
taskContext
- the specific task context (which implements equals() propertly)public boolean hasTaskWithContext(@Nonnull TaskContext taskContext)
TaskManager
hasTaskWithContext
in interface TaskManager
taskContext
- the specific task context (which implements equals() propertly)public TaskDescriptor<?> findFirstTask(@Nonnull TaskMatcher matcher)
TaskManager
findFirstTask
in interface TaskManager
matcher
- the condition used to find the task.null
will be returned
when no matching task can be found.public Collection<TaskDescriptor<?>> findTasks(@Nonnull TaskMatcher matcher)
TaskManager
findTasks
in interface TaskManager
matcher
- the condition used to find the task.public Collection<TaskDescriptor<?>> getAllTasks()
TaskManager
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.
getAllTasks
in interface TaskManager
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.public Collection<TaskDescriptor<?>> getLiveTasks()
TaskManager
TaskDescriptor
s in the manager.
The returned collection is sorted by task id, which should be in addition order.
getLiveTasks
in interface TaskManager
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.public void onProgressMade(TaskProgressEvent event)
TaskProgressListener
onProgressMade
in interface TaskProgressListener
event
- the current progress of the task.Copyright © 2002-2017 Atlassian. All Rights Reserved.