Package com.atlassian.jira.task
Class TaskManagerImpl
java.lang.Object
com.atlassian.jira.task.TaskManagerImpl
- All Implemented Interfaces:
InitializingComponent,TaskManager,TaskProgressListener,EventListener
public class TaskManagerImpl
extends Object
implements TaskManager, TaskProgressListener, InitializingComponent
An implementation of a
TaskManager. This manager uses an ExecutorService to
run submitted tasks.- Since:
- 3.13
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTaskManagerImpl(JiraAuthenticationContext authenticationContext, MessageHandlerService messageHandlerService, com.atlassian.cache.CacheManager cacheManager, SpanningOperationHolder spanningOperationHolder, org.ofbiz.core.entity.DelegatorInterface delegatorInterface, UserManager userManager, ClusterManager clusterManager) -
Method Summary
Modifier and TypeMethodDescriptionvoidCalled after all the beans are constructed and the ApplicationContext is fully populated.booleanawaitUntilActiveTasksComplete(long seconds) Waits on the TaskManager until all current active tasks are completed.voidcancelTask(Long taskId) Cancel a running task.voidcancelTaskIfRunningLocally(Long taskId) Cancel a running task if it is running on this cluster node.findFirstTask(TaskMatcher matcher) Find the first task that "matches" according to the passed matcher.findTasks(TaskMatcher matcher) Find all the tasks that "match" according to the passed matcher.Return a collection ofTaskDescriptors currently within the manager.<V extends Serializable>
TaskDescriptor<V>getLiveTask(TaskContext taskContext) Return the live task associated with the passed context, if one exists.Return a collection of submitted or runningTaskDescriptors in the manager.<V extends Serializable>
TaskDescriptor<V>Returns theTaskDescriptorof the task that is identified by the passed id.booleanhasLiveTaskWithContext(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.booleanhasTaskWithContext(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.booleanisCancellable(Long taskId) Returns true if the task can be cancelled.booleanisCancelled(Long taskId) Return true if this task has been cancelled.voidonProgressMade(TaskProgressEvent event) Called to indicate that task progress has been made.voidremoveTask(Long taskId) Remove a task from the manager.booleanshutdownAndWait(long timeout, TimeUnit unit) Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.voidAttempts to aggressively stop all actively executing tasks, halts the processing of waiting tasks.voidstart()Start the task manager.<V extends Serializable>
TaskDescriptor<V>submitTask(Callable<V> callable, String taskDescription, TaskContext taskContext) This submits aCallabletask to the manager which can then be started at the managers discretion, but hopefully very soon.<V extends Serializable>
TaskDescriptor<V>submitTask(Callable<V> callable, String taskDescription, TaskContext taskContext, boolean cancellable) This submits aCallabletask to the manager which can then be started at the managers discretion, but hopefully very soon.<V extends Serializable>
TaskDescriptor<V>submitTask(Callable<V> callable, String taskDescription, TaskContext taskContext, boolean cancellable, SpanningOperation spanningOperation) This submits aCallabletask to the manager which can then be started at the managers discretion, but hopefully very soon.voidwaitUntilTaskCompletes(Long taskId) Wait for a specific task to complete.
-
Field Details
-
TASK_CANCEL
- See Also:
-
-
Constructor Details
-
TaskManagerImpl
public TaskManagerImpl(JiraAuthenticationContext authenticationContext, MessageHandlerService messageHandlerService, com.atlassian.cache.CacheManager cacheManager, SpanningOperationHolder spanningOperationHolder, org.ofbiz.core.entity.DelegatorInterface delegatorInterface, UserManager userManager, ClusterManager clusterManager)
-
-
Method Details
-
afterInstantiation
Description copied from interface:InitializingComponentCalled after all the beans are constructed and the ApplicationContext is fully populated. Order of execution is order of bean creation, driven by InitializingComponentProcessor.- Specified by:
afterInstantiationin interfaceInitializingComponent- Throws:
Exception
-
submitTask
public <V extends Serializable> TaskDescriptor<V> submitTask(@Nonnull Callable<V> callable, @Nonnull String taskDescription, @Nonnull TaskContext taskContext) throws RejectedExecutionException Description copied from interface:TaskManagerThis submits aCallabletask to the manager which can then be started at the managers discretion, but hopefully very soon. TheTaskDescriptorreturned 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.- Specified by:
submitTaskin interfaceTaskManager- Parameters:
callable- the long running tasktaskDescription- the description of the tasktaskContext- some stateful context that the task knows about- Returns:
- a TaskDescriptor for the new long running task. The returned descriptor is a snapshot of the task state when the method returns and will not reflect any future changes.
- Throws:
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.
-
submitTask
public <V extends Serializable> TaskDescriptor<V> submitTask(@Nonnull Callable<V> callable, @Nonnull String taskDescription, @Nonnull TaskContext taskContext, boolean cancellable) Description copied from interface:TaskManagerThis submits aCallabletask to the manager which can then be started at the managers discretion, but hopefully very soon. TheTaskDescriptorreturned 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.- Specified by:
submitTaskin interfaceTaskManager- Parameters:
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.- Returns:
- a TaskDescriptor for the new long running task. The returned descriptor is a snapshot of the task state when the method returns and will not reflect any future changes.
-
submitTask
public <V extends Serializable> TaskDescriptor<V> submitTask(@Nonnull Callable<V> callable, @Nonnull String taskDescription, @Nonnull TaskContext taskContext, boolean cancellable, @Nullable SpanningOperation spanningOperation) throws RejectedExecutionException Description copied from interface:TaskManagerThis submits aCallabletask to the manager which can then be started at the managers discretion, but hopefully very soon. TheTaskDescriptorreturned 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.- Specified by:
submitTaskin interfaceTaskManager- Parameters:
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.spanningOperation- Operation that this task is part of- Returns:
- a TaskDescriptor for the new long running task. The returned descriptor is a snapshot of the task state when the method returns and will not reflect any future changes.
- Throws:
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.
-
removeTask
Description copied from interface:TaskManagerRemove a task from the manager. The task will still continue to execute if it has not already completed.- Specified by:
removeTaskin interfaceTaskManager- Parameters:
taskId- the task identifier.
-
cancelTask
Description copied from interface:TaskManagerCancel a running task. If the task is not running this message is a no-op.- Specified by:
cancelTaskin interfaceTaskManager- Parameters:
taskId- the task identifier.- Throws:
IllegalStateException- if the task is not cancellable
-
cancelTaskIfRunningLocally
Description copied from interface:TaskManagerCancel a running task if it is running on this cluster node.- Specified by:
cancelTaskIfRunningLocallyin interfaceTaskManager- Parameters:
taskId- the task identifier.
-
isCancellable
Description copied from interface:TaskManagerReturns true if the task can be cancelled. This does not take into account if the task is actually running or not.- Specified by:
isCancellablein interfaceTaskManager- Parameters:
taskId- the task identifier.- Returns:
- true if the task can be cancelled.
-
isCancelled
Description copied from interface:TaskManagerReturn true if this task has been cancelled.- Specified by:
isCancelledin interfaceTaskManager- Parameters:
taskId- the task identifier.- Returns:
- true if this task has been cancelled
-
start
public void start()Description copied from interface:TaskManagerStart the task manager. Normally the task manager starts on construction, but if it is shutdown, you may need to restart it. If the task manager is not shutdown, does nothing.- Specified by:
startin interfaceTaskManager
-
shutdownAndWait
Description copied from interface:TaskManagerInitiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.It will wait for at most
timeoutand then return true if the underlying execution threads are terminated completely.- Specified by:
shutdownAndWaitin interfaceTaskManager- Parameters:
timeout- the maximum time to wait for a graceful shutdown.unit- the time unit of the timeout argument.- Returns:
- true if the underlying execution threads have terminated completely.
-
shutdownNow
public void shutdownNow()Description copied from interface:TaskManagerAttempts to aggressively stop all actively executing tasks, halts the processing of waiting tasks.- Specified by:
shutdownNowin interfaceTaskManager
-
awaitUntilActiveTasksComplete
public boolean awaitUntilActiveTasksComplete(long seconds) Description copied from interface:TaskManagerWaits on the TaskManager until all current active tasks are completed. Calling this method does not stop tasks being added.- Specified by:
awaitUntilActiveTasksCompletein interfaceTaskManager- Parameters:
seconds- the number of seconds to wait.- Returns:
- true if all the active tasks are completed before the timeout, false otherwise.
-
waitUntilTaskCompletes
Description copied from interface:TaskManagerWait for a specific task to complete.- Specified by:
waitUntilTaskCompletesin interfaceTaskManager- Parameters:
taskId- Id of task to wait for- Throws:
ExecutionExceptionInterruptedException
-
getLiveTask
Description copied from interface:TaskManagerReturn the live task associated with the passed context, if one exists.- Specified by:
getLiveTaskin interfaceTaskManager- Parameters:
taskContext- the context to search for.- Returns:
- currently live task associated with the passed context. The descriptor returned is a snapshot
of the task state when the method returns will not reflect any future changes.
nullwill be returned when no matching task can be found.
-
getTask
Description copied from interface:TaskManagerReturns theTaskDescriptorof the task that is identified by the passed id.- Specified by:
getTaskin interfaceTaskManager- Parameters:
taskId- the id of the task to retrieve, if null then null will be returned- Returns:
- a
TaskDescriptoror 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.nullwill be returned when no matching task can be found.
-
hasLiveTaskWithContext
Description copied from interface:TaskManagerReturns true if the there are live tasks (running or submitted) that have a task context that is EQUAL to the passed in taskContext.- Specified by:
hasLiveTaskWithContextin interfaceTaskManager- Parameters:
taskContext- the specific task context (which implements equals() properly)- Returns:
- true if there are any tasks with an equal task context
-
hasTaskWithContext
Description copied from interface:TaskManagerReturns true if the there are any tasks (submitted, running or finished) that have a task context that is EQUAL to the passed in taskContext.- Specified by:
hasTaskWithContextin interfaceTaskManager- Parameters:
taskContext- the specific task context (which implements equals() properly)- Returns:
- true if there are any tasks with an equal task context
-
findFirstTask
Description copied from interface:TaskManagerFind the first task that "matches" according to the passed matcher.- Specified by:
findFirstTaskin interfaceTaskManager- Parameters:
matcher- the condition used to find the task.- Returns:
- task, for many matches favor TaskDescriptor with higher taskId (i.e. latest task), null if not found
-
findTasks
Description copied from interface:TaskManagerFind all the tasks that "match" according to the passed matcher.- Specified by:
findTasksin interfaceTaskManager- Parameters:
matcher- the condition used to find the task.- Returns:
- the tasks that "match" according to the passed matcher. The descriptors returned are a snapshot of the task state when the method returns will not reflect any future changes. An empty collection is returned when no tasks are matched.
-
getAllTasks
Description copied from interface:TaskManagerReturn a collection ofTaskDescriptors 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.
- Specified by:
getAllTasksin interfaceTaskManager- Returns:
- a collection of
TaskDescriptors. 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.
-
getLiveTasks
Description copied from interface:TaskManagerReturn a collection of submitted or runningTaskDescriptors in the manager.The returned collection is sorted by task id, which should be in addition order.
- Specified by:
getLiveTasksin interfaceTaskManager- Returns:
- a collection of running
TaskDescriptors. 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.
-
onProgressMade
Description copied from interface:TaskProgressListenerCalled to indicate that task progress has been made. The passed event indicates the current progress of the task.- Specified by:
onProgressMadein interfaceTaskProgressListener- Parameters:
event- the current progress of the task.
-