@Service(value="taskManagement") @Transactional(propagation=REQUIRED) public class TaskManagementImpl extends Object implements TaskManagement
Constructor and Description |
---|
TaskManagementImpl() |
Modifier and Type | Method and Description |
---|---|
Long |
addTask(String uniqueTaskName,
boolean active,
Long interval,
Date nextExecutionDate,
Class<? extends TaskHandler> handlerClass)
Add a new task.
|
Long |
addTask(String uniqueTaskName,
boolean active,
Long interval,
Date nextExecutionDate,
Map<String,String> properties,
Class<? extends TaskHandler> handlerClass)
Add a new task.
|
Long |
addTask(String uniqueTaskName,
boolean active,
Long interval,
Date nextExecutionDate,
Map<String,String> properties,
String handlerClass)
Add a new task.
|
Long |
addTask(String uniqueTaskName,
boolean active,
Long interval,
Date nextExecutionDate,
String handlerClass)
Add a new task.
|
void |
addTaskHandler(Class<? extends TaskHandler> taskHandler)
Add a handler for tasks.
|
void |
addTaskHandler(String handlerName,
Class<? extends TaskHandler> taskHandler)
Add a handler for tasks with the given name.
|
void |
addTaskHandlerWithTask(String handlerName,
Class<? extends TaskHandler> taskHandlerClazz,
Map<String,String> properties,
long startOffset,
boolean resetFailed)
Add a task handler and create a task for it.
|
void |
failTaskExecution(String uniqueTaskName)
Mark the execution of a task as failed.
|
TaskTO |
findTask(String uniqueTaskName)
Get the details of a task.
|
TaskTO |
getNextScheduledTask()
Return the next task to be scheduled.
|
TaskTO |
getNextScheduledTask(Date upperBound)
Return the next task to be scheduled.
|
Collection<TaskTO> |
getNextScheduledTasks(Date upperBound,
int maxTasks,
Collection<Long> taskIdsToExclude)
Get the tasks to schedule next
|
Collection<TaskExecution> |
getTaskExecutions(String instanceName)
Return all task executions running on the Communote with the given name.
|
boolean |
isTaskRunningOnCurrentInstance(String uniqueTaskName)
Return whether the given task is running on the current instance.
|
String |
killTaskExecution(Long executionId)
Kill the task with given execution ID by removing the execution and setting the task back to
pending.
|
void |
removeTask(String uniqueTaskName)
Remove a task if it is not RUNNING.
|
boolean |
removeTaskHandler(String handlerName)
Remove the task handler class from the list of known handlers.
|
void |
rescheduleTask(String uniqueTaskName,
Date nextExecutionDate)
Reschedule a pending task.
|
void |
resetTask(String uniqueTaskName)
Reset a task back from failed to pending.
|
Long |
startTaskExecution(String uniqueTaskName)
Mark a task as running on this instance by creating an execution for it and setting the
status to RUNNING.
|
Long |
startTaskExecutionTx(String uniqueTaskName)
Same as
TaskManagement.startTaskExecution(String) but can throw
DatabaseIntegrityViolationException. |
void |
stopAllTaskExecutions()
Calls stopAllTaskExecutions(true,now).
|
void |
stopAllTaskExecutions(boolean resetFailed,
Date rescheduleDate)
End all task executions of this instance and schedules them again.
|
void |
stopTaskExecution(String uniqueTaskName)
End the execution of the given task.
|
void |
stopTaskExecution(String uniqueTaskName,
Date rescheduleDate)
End the execution of the given task.
|
public Long addTask(String uniqueTaskName, boolean active, Long interval, Date nextExecutionDate, Class<? extends TaskHandler> handlerClass) throws TaskAlreadyExistsException
TaskManagement
addTask
in interface TaskManagement
uniqueTaskName
- Unique name for this task.active
- True, if active.interval
- Interval for the execution.nextExecutionDate
- The next execution date.handlerClass
- Class of the handler.TaskAlreadyExistsException
- Thrown, when there is already a task with this name.public Long addTask(String uniqueTaskName, boolean active, Long interval, Date nextExecutionDate, Map<String,String> properties, Class<? extends TaskHandler> handlerClass) throws TaskAlreadyExistsException
TaskManagement
addTask
in interface TaskManagement
uniqueTaskName
- Unique name for this task.active
- True, if active.interval
- Interval for the execution.nextExecutionDate
- The next execution date.properties
- Properties of this task.handlerClass
- Class of the handler.TaskAlreadyExistsException
- Thrown, when there is already a task with this name.public Long addTask(String uniqueTaskName, boolean active, Long interval, Date nextExecutionDate, Map<String,String> properties, String handlerClass) throws TaskAlreadyExistsException
TaskManagement
addTask
in interface TaskManagement
uniqueTaskName
- Unique name for this task.active
- True, if active.interval
- Interval for the execution.nextExecutionDate
- The next execution date.properties
- Properties of this task.handlerClass
- Full qualified class name for the handler.TaskAlreadyExistsException
- Thrown, when there is already a task with this name.public Long addTask(String uniqueTaskName, boolean active, Long interval, Date nextExecutionDate, String handlerClass) throws TaskAlreadyExistsException
TaskManagement
addTask
in interface TaskManagement
uniqueTaskName
- Unique name for this task.active
- True, if active.interval
- Interval for the execution.nextExecutionDate
- The next execution date.handlerClass
- Full qualified class name for the handler.TaskAlreadyExistsException
- Thrown, when there is already a task with this name.public void addTaskHandler(Class<? extends TaskHandler> taskHandler)
TaskManagement
addTaskHandler
in interface TaskManagement
taskHandler
- the task handler to add@Transactional(propagation=SUPPORTS) public void addTaskHandler(String handlerName, Class<? extends TaskHandler> taskHandler)
TaskManagement
addTaskHandler
in interface TaskManagement
handlerName
- the name of the handler to be usedtaskHandler
- the task handler to add@Transactional(propagation=NEVER) public void addTaskHandlerWithTask(String handlerName, Class<? extends TaskHandler> taskHandlerClazz, Map<String,String> properties, long startOffset, boolean resetFailed)
TaskManagement
addTaskHandlerWithTask
in interface TaskManagement
handlerName
- the name of the handler. The name will also be used as unique name for the task.taskHandlerClazz
- the TaskHandler
classproperties
- Properties for the task (if one is added).startOffset
- the offset in milliseconds to add to the current time to delay the execution of
the taskresetFailed
- if true and the status of an existing task is failed the task will be always
rescheduled.public void failTaskExecution(String uniqueTaskName) throws InvalidInstanceException
TaskManagement
failTaskExecution
in interface TaskManagement
uniqueTaskName
- Name of the task.InvalidInstanceException
- Thrown, when the task is not running on this instance.@Transactional(readOnly=true) public TaskTO findTask(String uniqueTaskName)
TaskManagement
findTask
in interface TaskManagement
uniqueTaskName
- The name of the taskpublic TaskTO getNextScheduledTask()
TaskManagement
getNextScheduledTask
in interface TaskManagement
public TaskTO getNextScheduledTask(Date upperBound)
TaskManagement
getNextScheduledTask
in interface TaskManagement
upperBound
- The upper bound of the task's next execution (exclusive).public Collection<TaskTO> getNextScheduledTasks(Date upperBound, int maxTasks, Collection<Long> taskIdsToExclude)
TaskManagement
getNextScheduledTasks
in interface TaskManagement
upperBound
- NextExecution < UpperBound.maxTasks
- maximum number of tasks to returntaskIdsToExclude
- the IDs of the task to exclude from the query. Can be null.@Transactional(readOnly=true) public Collection<TaskExecution> getTaskExecutions(String instanceName)
TaskManagement
getTaskExecutions
in interface TaskManagement
instanceName
- Name of the instance@Transactional(readOnly=true) public boolean isTaskRunningOnCurrentInstance(String uniqueTaskName)
TaskManagement
isTaskRunningOnCurrentInstance
in interface TaskManagement
uniqueTaskName
- the unique name of the taskpublic String killTaskExecution(Long executionId)
TaskManagement
killTaskExecution
in interface TaskManagement
executionId
- The execution IDpublic void removeTask(String uniqueTaskName) throws TaskAlreadyRunningException
TaskManagement
removeTask
in interface TaskManagement
uniqueTaskName
- The task to remove.TaskAlreadyRunningException
- Thrown, when the task is currently running.@Transactional(propagation=SUPPORTS) public boolean removeTaskHandler(String handlerName)
TaskManagement
removeTaskHandler
in interface TaskManagement
handlerName
- the handler namepublic void rescheduleTask(String uniqueTaskName, Date nextExecutionDate) throws TaskStatusException
TaskManagement
rescheduleTask
in interface TaskManagement
uniqueTaskName
- the unique name of task. If there is no task with the given name the call will be
ignored.nextExecutionDate
- the new execution dateTaskStatusException
- in case the task is not pendingpublic void resetTask(String uniqueTaskName)
TaskManagement
resetTask
in interface TaskManagement
uniqueTaskName
- The name of the task to reset@Transactional(propagation=NEVER) public Long startTaskExecution(String uniqueTaskName) throws TaskAlreadyRunningException, TaskNotActiveException, TaskManagementException
TaskManagement
startTaskExecution
in interface TaskManagement
uniqueTaskName
- Name of the task to start.TaskAlreadyRunningException
- in case the task is already running.TaskNotActiveException
- in case the task is not activated.TaskManagementException
- in case of an unexpected error@Transactional(propagation=REQUIRES_NEW) public Long startTaskExecutionTx(String uniqueTaskName) throws TaskNotActiveException, TaskAlreadyRunningException
TaskManagement
TaskManagement.startTaskExecution(String)
but can throw
DatabaseIntegrityViolationException. Therefore this method should never be called directly
and TaskManagement.startTaskExecution(String)
should be used instead.startTaskExecutionTx
in interface TaskManagement
uniqueTaskName
- Name of the task to start.TaskNotActiveException
- In case if the task is not activated.TaskAlreadyRunningException
- in case the task is already running.public void stopAllTaskExecutions()
TaskManagement
stopAllTaskExecutions
in interface TaskManagement
public void stopAllTaskExecutions(boolean resetFailed, Date rescheduleDate)
TaskManagement
stopAllTaskExecutions
in interface TaskManagement
resetFailed
- If set, all failed tasks will be reset.rescheduleDate
- If set, this will be the new date the task will be executed.public void stopTaskExecution(String uniqueTaskName) throws InvalidInstanceException
TaskManagement
stopTaskExecution
in interface TaskManagement
uniqueTaskName
- Name of the task.InvalidInstanceException
- in case the task is not executed on this instancepublic void stopTaskExecution(String uniqueTaskName, Date rescheduleDate) throws InvalidInstanceException
TaskManagement
stopTaskExecution
in interface TaskManagement
uniqueTaskName
- Unique name of the task.rescheduleDate
- If set, this will be the new date the task will be executed.InvalidInstanceException
- in case the task is not running on this instanceCopyright © 2019 Communote team. All rights reserved.