com.evolveum.midpoint.task.impl
Class TaskManagerImpl

java.lang.Object
  extended by com.evolveum.midpoint.task.impl.TaskManagerImpl
All Implemented Interfaces:
TaskManager, org.springframework.beans.factory.BeanFactoryAware

@Service(value="taskManager")
@DependsOn(value="repositoryService")
public class TaskManagerImpl
extends java.lang.Object
implements TaskManager, org.springframework.beans.factory.BeanFactoryAware

Task Manager implementation. VERY SIMPLISTIC. This needs to be updated later. It assumes only a single host. No cluster, in fact not even a repository access. So the tasks will not survive restarts.

Author:
Radovan Semancik

Constructor Summary
TaskManagerImpl()
           
 
Method Summary
 java.lang.String addTask(TaskType taskType, OperationResult parentResult)
          Add new task.
 void claimTask(Task task, OperationResult parentResult)
          Claim task exclusively for this node.
 Task createTaskInstance()
          Creates new transient, running, claimed task instance.
 Task createTaskInstance(java.lang.String operationName)
          Creates new transient, running, claimed task instance.
 Task createTaskInstance(TaskType taskType)
          Creates task instance from the XML task representation.
 Task createTaskInstance(TaskType taskType, java.lang.String operationName)
          Creates task instance from the XML task representation.
 void deactivateServiceThreads()
          Deactivate service threads (temporarily).
 void deleteTask(java.lang.String oid, OperationResult parentResult)
          Deletes task with provided OID.
 java.util.Set<Task> getRunningTasks()
          Returns tasks that currently run on this node.
 boolean getServiceThreadsActivationState()
          Returns true if the service threads are running.
 Task getTask(java.lang.String taskOid, OperationResult parentResult)
          Returns a task with specified OID.
 void init()
           
 java.util.Set<Task> listTasks()
          Lists all tasks.
 void modifyTask(ObjectModificationType objectChange, OperationResult parentResult)
          Modifies task using relative change description.
 void processRunnableTask(Task task)
           
 void processRunnableTaskType(TaskType taskType)
          Process runnable task with TaskType XML object as an argument.
 void reactivateServiceThreads()
          Re-activate the service threads after they have been deactivated.
 void registerHandler(java.lang.String uri, TaskHandler handler)
          Register a handler for a specified handler URI.
 void releaseTask(Task task, OperationResult parentResult)
          Release a claimed task.
 void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
           
 void shutdown()
          Make sure all processes are stopped properly.
 void switchToBackground(Task task, OperationResult parentResult)
          Switches the provided task to background, making it asynchronous.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TaskManagerImpl

public TaskManagerImpl()
Method Detail

setBeanFactory

public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
                    throws org.springframework.beans.BeansException
Specified by:
setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
Throws:
org.springframework.beans.BeansException

init

@PostConstruct
public void init()

shutdown

@PreDestroy
public void shutdown()
Description copied from interface: TaskManager
Make sure all processes are stopped properly. Will block until all processes are shut down.

Specified by:
shutdown in interface TaskManager

createTaskInstance

public Task createTaskInstance()
Description copied from interface: TaskManager
Creates new transient, running, claimed task instance. This is fact creates usual "synchronous" task. This is useful for normal day-to-day tasks that are either synchronous or start as a synchronous and are switched to asynchronous task later.

Specified by:
createTaskInstance in interface TaskManager
Returns:
transient, running, claimed task instance

createTaskInstance

public Task createTaskInstance(java.lang.String operationName)
Description copied from interface: TaskManager
Creates new transient, running, claimed task instance. This is fact creates usual "synchronous" task. This is useful for normal day-to-day tasks that are either synchronous or start as a synchronous and are switched to asynchronous task later. The result inside the task will be initialized with specified operation name.

Specified by:
createTaskInstance in interface TaskManager
Parameters:
operationName - operation name to use as a root for new result in task
Returns:
new Java representation of the task

createTaskInstance

public Task createTaskInstance(TaskType taskType)
Description copied from interface: TaskManager
Creates task instance from the XML task representation.

Specified by:
createTaskInstance in interface TaskManager
Parameters:
taskType - JAXB (XML) representation of the task
Returns:
new Java representation of the task

createTaskInstance

public Task createTaskInstance(TaskType taskType,
                               java.lang.String operationName)
Description copied from interface: TaskManager
Creates task instance from the XML task representation. If there is not a result inside the task, it will create the result with specified operation name.

Specified by:
createTaskInstance in interface TaskManager
Parameters:
taskType - JAXB (XML) representation of the task
operationName - operation name to use as a root for new result in task
Returns:
new Java representation of the task

getTask

public Task getTask(java.lang.String taskOid,
                    OperationResult parentResult)
             throws ObjectNotFoundException,
                    SchemaException
Description copied from interface: TaskManager
Returns a task with specified OID. This operation will look up a task instance in the repository and return it in a form of Task object. Works only on persistent tasks.

Specified by:
getTask in interface TaskManager
Parameters:
taskOid - OID of the persistent task.
Returns:
Task instance
Throws:
ObjectNotFoundException - wrong OID format, etc.
SchemaException - error dealing with resource schema

claimTask

public void claimTask(Task task,
                      OperationResult parentResult)
               throws ObjectNotFoundException,
                      ConcurrencyException,
                      SchemaException
Description copied from interface: TaskManager
Claim task exclusively for this node. The operation will try to claim a task for this node. The operation will normally return, switching the task to a claimed state. Or it may throw exception if the task "claiming" failed. Claiming will only work on released tasks. But even if this node considers task to be released, it might have been claimed by another node in the meantime. This operation guarantees atomicity. It will claim task only on a single node. This method is in the TaskManager instead of Task, so the Task can stay free of RepositoryService dependency. TODO: EXCEPTIONS

Specified by:
claimTask in interface TaskManager
Parameters:
task - task instance to claim
Throws:
ObjectNotFoundException
ConcurrencyException
SchemaException

releaseTask

public void releaseTask(Task task,
                        OperationResult parentResult)
                 throws ObjectNotFoundException,
                        SchemaException
Description copied from interface: TaskManager
Release a claimed task. The task is released for other nodes to work on it. The task state is saved to the repository before release, if necessary. If a transient task is provided as an argument, the task will be made persistent during this call. Release only works on claimed tasks. This method is in the TaskManager instead of Task, so the Task can stay free of RepositoryService dependency.

Specified by:
releaseTask in interface TaskManager
Parameters:
task - task instance to release
Throws:
ObjectNotFoundException
SchemaException

switchToBackground

public void switchToBackground(Task task,
                               OperationResult parentResult)
Description copied from interface: TaskManager
Switches the provided task to background, making it asynchronous. The provided task will be "released" to other nodes to execute. If the task execution state is "running" the method also tries to make sure that the task will be immediately execute (e.g. by allocating a thread). However, the nodes may compete for the tasks or there may be explicit limitations. Therefore there is no guarantee that the task will execute on the same node that called the switchToBackground() method.

Specified by:
switchToBackground in interface TaskManager
Parameters:
task - task to switch to background.

listTasks

public java.util.Set<Task> listTasks()
Description copied from interface: TaskManager
Lists all tasks. This method is not very useful for normal operation, but may be useful for diagnostics. May list persistent and also transient tasks. Depends on implementation.

Specified by:
listTasks in interface TaskManager
Returns:
list of all known tasks

registerHandler

public void registerHandler(java.lang.String uri,
                            TaskHandler handler)
Description copied from interface: TaskManager
Register a handler for a specified handler URI.

Specified by:
registerHandler in interface TaskManager

processRunnableTaskType

public void processRunnableTaskType(TaskType taskType)
Process runnable task with TaskType XML object as an argument. This is called by a task scanner or anyone that has a runnable task. Precondition: claimed, runnable task As the task is claimed as it enters this methods, all we need is to execute it.

Parameters:
task - XML TaskType object

processRunnableTask

public void processRunnableTask(Task task)

getRunningTasks

public java.util.Set<Task> getRunningTasks()
Description copied from interface: TaskManager
Returns tasks that currently run on this node. E.g. tasks that have allocated threads. It should be a different view than looking for a claimed tasks in the repository, although normally it should return the same data. This should look at the real situation (e.g. threads) and should be used to troubleshoot task management problems.

Specified by:
getRunningTasks in interface TaskManager
Returns:
tasks that currently run on this node.

addTask

public java.lang.String addTask(TaskType taskType,
                                OperationResult parentResult)
                         throws ObjectAlreadyExistsException,
                                SchemaException
Description copied from interface: TaskManager
Add new task. The OID provided in the task may be empty. In that case the OID will be assigned by the implementation of this method and it will be provided as return value. This operation should fail if such object already exists (if object with the provided OID already exists). The operation may fail if provided OID is in an unusable format for the storage. Generating own OIDs and providing them to this method is not recommended for normal operation. Should be atomic. Should not allow creation of two objects with the same OID (even if created in parallel). The operation may fail if the object to be created does not conform to the underlying schema of the storage system or the schema enforced by the implementation.

Specified by:
addTask in interface TaskManager
parentResult - parent OperationResult (in/out)
Returns:
OID assigned to the created object
Throws:
ObjectAlreadyExistsException - object with specified identifiers already exists, cannot add
SchemaException - error dealing with storage schema, e.g. schema violation

modifyTask

public void modifyTask(ObjectModificationType objectChange,
                       OperationResult parentResult)
                throws ObjectNotFoundException,
                       SchemaException
Description copied from interface: TaskManager
Modifies task using relative change description. Must fail if object with provided OID does not exists. Must fail if any of the described changes cannot be applied. Should be atomic. If two or more modify operations are executed in parallel, the operations should be merged. In case that the operations are in conflict (e.g. one operation adding a value and the other removing the same value), the result is not deterministic. The operation may fail if the modified object does not conform to the underlying schema of the storage system or the schema enforced by the implementation. TODO: optimistic locking

Specified by:
modifyTask in interface TaskManager
Parameters:
objectChange - specification of object changes
parentResult - parent OperationResult (in/out)
Throws:
ObjectNotFoundException - specified object does not exist
SchemaException - resulting object would violate the schema

deleteTask

public void deleteTask(java.lang.String oid,
                       OperationResult parentResult)
                throws ObjectNotFoundException
Description copied from interface: TaskManager
Deletes task with provided OID. Must fail if object with specified OID does not exists. Should be atomic.

Specified by:
deleteTask in interface TaskManager
Parameters:
oid - OID of object to delete
parentResult - parent OperationResult (in/out)
Throws:
ObjectNotFoundException - specified object does not exist

deactivateServiceThreads

public void deactivateServiceThreads()
Description copied from interface: TaskManager
Deactivate service threads (temporarily). This will suspend all background activity such as scanning threads, heartbeats and similar mechanisms. Note: The threads are normally activated after task manager implementation starts. This methods should not be used in a normal case. WARNING: this feature is intended for development-time diagnostics and should not be used on production environments. Suspending the threads may affect correct behavior of the system (such as timeouts on heartbeats). Use this feature only if you really know what you are doing.

Specified by:
deactivateServiceThreads in interface TaskManager

reactivateServiceThreads

public void reactivateServiceThreads()
Description copied from interface: TaskManager
Re-activate the service threads after they have been deactivated.

Specified by:
reactivateServiceThreads in interface TaskManager

getServiceThreadsActivationState

public boolean getServiceThreadsActivationState()
Description copied from interface: TaskManager
Returns true if the service threads are running. This method returns true in a normal case. It returns false is the threads were temporarily suspended.

Specified by:
getServiceThreadsActivationState in interface TaskManager
Returns:
true if the service threads are running.


Copyright © 2011 evolveum. All Rights Reserved.