com.evolveum.midpoint.task.impl
Class TaskImpl

java.lang.Object
  extended by com.evolveum.midpoint.task.impl.TaskImpl
All Implemented Interfaces:
Task, Dumpable

public class TaskImpl
extends java.lang.Object
implements Task

Implementation of a Task. This is very simplistic now. It does not even serialize itself.

Author:
Radovan Semancik
See Also:
TaskManagerImpl

Method Summary
 boolean canRun()
          Returns true if the task can run (was not interrupted).
 void close(OperationResult parentResult)
          Close the task.
 java.lang.String dump()
          Return human-readable representation of the task content.
 boolean equals(java.lang.Object obj)
           
 void finishHandler()
          Marks current handler as finished, and removes it from the handler stack.
 TaskBinding getBinding()
           
 TaskExclusivityStatus getExclusivityStatus()
          Returns task exclusivity status.
 TaskExecutionStatus getExecutionStatus()
          Returns execution status.
 PropertyContainer getExtension()
          Returns task extension.
 Property getExtension(javax.xml.namespace.QName propertyName)
           
 java.lang.String getHandlerUri()
          Returns handler URI.
 java.lang.Long getLastRunFinishTimestamp()
           
 java.lang.Long getLastRunStartTimestamp()
           
 java.lang.String getName()
          Returns human-readable name of the task.
 java.lang.Long getNextRunStartTime()
           
<T extends ObjectType>
T
getObject(java.lang.Class<T> type, OperationResult parentResult)
          Returns object that the task is associated with.
 java.lang.String getObjectOid()
          Returns OID of the object that the task is associated with.
 ObjectReferenceType getObjectRef()
          Returns reference to the object that the task is associated with.
 java.lang.String getOid()
          Returns task OID.
 UriStack getOtherHandlersUriStack()
          Returns the stack of other handlers URIs.
 UserType getOwner()
          Returns user that owns this task.
 TaskPersistenceStatus getPersistenceStatus()
          Returns task persistence status.
 long getProgress()
           
 OperationResult getResult()
          Returns a top-level OperationResult stored in the task.
 ScheduleType getSchedule()
           
 java.lang.String getTaskIdentifier()
          Returns task (lightweight) identifier.
 TaskType getTaskTypeObject()
           
 int hashCode()
           
 boolean isAsynchronous()
          Returns true if the task is asynchronous.
 boolean isCycle()
           
 boolean isLooselyBound()
           
 boolean isSingle()
           
 boolean isTightlyBound()
           
 void makeRecurrent(long interval)
           
 void modifyExtension(java.util.List<PropertyModification> modifications, OperationResult parentResult)
          TODO The modification path is relative to the extension, therefore it will almost always be "." (or null).
 void recordProgress(long progress, OperationResult parentResult)
          Record progress of the task, storing it persistently if needed.
 void recordRunFinish(TaskRunResult runResult, OperationResult parentResult)
          Record finish of the last "run" of the task TODO: better documentation
 void recordRunStart(OperationResult parentResult)
           
 void refresh(OperationResult parentResult)
          Re-reads the task state from the persistent storage.
 void setExclusivityStatus(TaskExclusivityStatus exclusivityStatus)
          Sets task exclusivity status.
 void setExecutionStatus(TaskExecutionStatus executionStatus)
          Sets task execution status.
 void setHandlerUri(java.lang.String handlerUri)
          Sets handler URI.
 void setName(java.lang.String name)
          Sets the human-readable name of the task.
 void setObjectRef(ObjectReferenceType objectRef)
           
 void setOid(java.lang.String oid)
          Sets task OID.
 void setOwner(UserType owner)
           
 void setPersistenceStatus(TaskPersistenceStatus persistenceStatus)
          Sets task persistence status.
 void setResult(OperationResult result)
           
 void shutdown()
          Signal the task to shut down.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getTaskIdentifier

public java.lang.String getTaskIdentifier()
Description copied from interface: Task
Returns task (lightweight) identifier. This is an unique identification of any task, regardless whether it is persistent or transient (cf. OID). Therefore this can be used to identify all tasks, e.g. for the purposes of auditing and logging. Task identifier is assigned automatically when the task is created. It is immutable.

Specified by:
getTaskIdentifier in interface Task
Returns:
task (lightweight) identifier

getOwner

public UserType getOwner()
Description copied from interface: Task
Returns user that owns this task. It usually means the user that started the task or a system used that is used to execute the task. The owner will be used to determine access rights of the task, will be used for auditing, etc.

Specified by:
getOwner in interface Task
Returns:
task owner

setOwner

public void setOwner(UserType owner)
Specified by:
setOwner in interface Task

getExecutionStatus

public TaskExecutionStatus getExecutionStatus()
Description copied from interface: Task
Returns execution status.

Specified by:
getExecutionStatus in interface Task
Returns:
execution status.
See Also:
TaskExecutionStatus

getPersistenceStatus

public TaskPersistenceStatus getPersistenceStatus()
Description copied from interface: Task
Returns task persistence status.

Specified by:
getPersistenceStatus in interface Task
Returns:
task persistence status.
See Also:
TaskPersistenceStatus

getExclusivityStatus

public TaskExclusivityStatus getExclusivityStatus()
Description copied from interface: Task
Returns task exclusivity status.

Specified by:
getExclusivityStatus in interface Task
Returns:
task exclusivity status.
See Also:
TaskExclusivityStatus

getBinding

public TaskBinding getBinding()
Specified by:
getBinding in interface Task

isAsynchronous

public boolean isAsynchronous()
Description copied from interface: Task
Returns true if the task is asynchronous. The asynchronous task is not executing in foreground. Therefore any thread that is not explicitly allocated for the task can be discarded. E.g. if a GUI thread detects that the task is asynchronous it knows that there is no point in waiting for the task result. It can just display appropriate message to the user (e.g. "please come back later") and return control back to the web container.

Specified by:
isAsynchronous in interface Task
Returns:
true if the task is asynchronous.

getProgress

public long getProgress()
Specified by:
getProgress in interface Task

getObjectRef

public ObjectReferenceType getObjectRef()
Description copied from interface: Task
Returns reference to the object that the task is associated with. Tasks may be associated with a particular objects. For example a "import from resource" task is associated with the resource definition object that it imports from. Similarly for synchronization and reconciliation tasks (cycles). This is an optional property.

Specified by:
getObjectRef in interface Task
Returns:

setObjectRef

public void setObjectRef(ObjectReferenceType objectRef)
Specified by:
setObjectRef in interface Task

getObjectOid

public java.lang.String getObjectOid()
Description copied from interface: Task
Returns OID of the object that the task is associated with. Convenience method. This will get the OID from the objectRef.

Specified by:
getObjectOid in interface Task

getObject

public <T extends ObjectType> T getObject(java.lang.Class<T> type,
                                          OperationResult parentResult)
                               throws ObjectNotFoundException,
                                      SchemaException
Description copied from interface: Task
Returns object that the task is associated with. Tasks may be associated with a particular objects. For example a "import from resource" task is associated with the resource definition object that it imports from. Similarly for synchronization and reconciliation tasks (cycles). This is an optional property. The object will only be returned if the task really contains an object without OID (e.g. unfinished account shadow). In all other cases this method may return null. Use getObjectRef instead. Optional. May return null.

Specified by:
getObject in interface Task
Throws:
ObjectNotFoundException
SchemaException

getResult

public OperationResult getResult()
Description copied from interface: Task
Returns a top-level OperationResult stored in the task.

Specified by:
getResult in interface Task
Returns:
task operation result.

setResult

public void setResult(OperationResult result)

getHandlerUri

public java.lang.String getHandlerUri()
Description copied from interface: Task
Returns handler URI. Handler URI indirectly specifies which class is responsible to handle the task. The handler will execute reaction to a task lifecycle events such as executing the task, task heartbeat, etc.

Specified by:
getHandlerUri in interface Task
Returns:
handler URI

setHandlerUri

public void setHandlerUri(java.lang.String handlerUri)
Description copied from interface: Task
Sets handler URI. Handler URI indirectly specifies which class is responsible to handle the task. The handler will execute reaction to a task lifecycle events such as executing the task, task heartbeat, etc.

Specified by:
setHandlerUri in interface Task
Parameters:
handlerUri - new handler URI

getOtherHandlersUriStack

public UriStack getOtherHandlersUriStack()
Description copied from interface: Task
Returns the stack of other handlers URIs. The idea is that a task may have a chain of handlers, forming a stack. After a handler at the top of the stack finishes its processing, TaskManager will remove it from the stack and invoke the then-current handler. After that finishes, the next handler will be called, and so on, until the stack is empty.

Specified by:
getOtherHandlersUriStack in interface Task
Returns:

setExecutionStatus

public void setExecutionStatus(TaskExecutionStatus executionStatus)
Description copied from interface: Task
Sets task execution status.

Specified by:
setExecutionStatus in interface Task
Parameters:
executionStatus - new task execution status.
See Also:
TaskExecutionStatus

setPersistenceStatus

public void setPersistenceStatus(TaskPersistenceStatus persistenceStatus)
Description copied from interface: Task
Sets task persistence status.

Specified by:
setPersistenceStatus in interface Task
Parameters:
persistenceStatus - new task persistence status.
See Also:
TaskPersistenceStatus

setExclusivityStatus

public void setExclusivityStatus(TaskExclusivityStatus exclusivityStatus)
Description copied from interface: Task
Sets task exclusivity status.

Specified by:
setExclusivityStatus in interface Task
Parameters:
exclusivityStatus - new task exclusivity status.
See Also:
TaskExclusivityStatus

getOid

public java.lang.String getOid()
Description copied from interface: Task
Returns task OID. Only persistent tasks have OID. This returns null if the task is not persistent.

Specified by:
getOid in interface Task
Returns:
task OID

setOid

public void setOid(java.lang.String oid)
Description copied from interface: Task
Sets task OID. This method should not be used outside task manager. The OID should be considered read-only. TODO: be stricter and maybe do not publish this method at all.

Specified by:
setOid in interface Task
Parameters:
oid - new task OID.

getName

public java.lang.String getName()
Description copied from interface: Task
Returns human-readable name of the task.

Specified by:
getName in interface Task
Returns:
human-readable name of the task.

setName

public void setName(java.lang.String name)
Description copied from interface: Task
Sets the human-readable name of the task.

Specified by:
setName in interface Task
Parameters:
name - new human-readable name of the task.

getExtension

public PropertyContainer getExtension()
Description copied from interface: Task
Returns task extension. The extension is a part of task that can store arbitrary data. It usually holds data specific to a task type, internal task state, business state or similar data that are out of scope of this interface definition. Although this methods returns list, it should be rather regarded as set. The list is used to avoid unnecessary reordering of properties in the storage (in case store is ordering-sensitive). Returned list should be regarded as immutable. In case that the client does any change, weird things may happen.

Specified by:
getExtension in interface Task
Returns:
task extension

getExtension

public Property getExtension(javax.xml.namespace.QName propertyName)
Specified by:
getExtension in interface Task

modifyExtension

public void modifyExtension(java.util.List<PropertyModification> modifications,
                            OperationResult parentResult)
                     throws ObjectNotFoundException,
                            SchemaException
Description copied from interface: Task
TODO The modification path is relative to the extension, therefore it will almost always be "." (or null).

Specified by:
modifyExtension in interface Task
Throws:
ObjectNotFoundException
SchemaException

getTaskTypeObject

public TaskType getTaskTypeObject()
Specified by:
getTaskTypeObject in interface Task

getLastRunStartTimestamp

public java.lang.Long getLastRunStartTimestamp()
Specified by:
getLastRunStartTimestamp in interface Task

getLastRunFinishTimestamp

public java.lang.Long getLastRunFinishTimestamp()
Specified by:
getLastRunFinishTimestamp in interface Task

getNextRunStartTime

public java.lang.Long getNextRunStartTime()
Specified by:
getNextRunStartTime in interface Task

dump

public java.lang.String dump()
Description copied from interface: Task
Return human-readable representation of the task content. Useful for diagnostics. May return multi-line string.

Specified by:
dump in interface Task
Specified by:
dump in interface Dumpable
Returns:
human-readable representation of the task content

recordRunStart

public void recordRunStart(OperationResult parentResult)
                    throws ObjectNotFoundException,
                           SchemaException
Specified by:
recordRunStart in interface Task
Throws:
ObjectNotFoundException
SchemaException

recordRunFinish

public void recordRunFinish(TaskRunResult runResult,
                            OperationResult parentResult)
                     throws ObjectNotFoundException,
                            SchemaException
Description copied from interface: Task
Record finish of the last "run" of the task TODO: better documentation

Specified by:
recordRunFinish in interface Task
Parameters:
runResult - result of the run to record
Throws:
ObjectNotFoundException
SchemaException

recordProgress

public void recordProgress(long progress,
                           OperationResult parentResult)
                    throws ObjectNotFoundException,
                           SchemaException
Description copied from interface: Task
Record progress of the task, storing it persistently if needed.

Specified by:
recordProgress in interface Task
Throws:
ObjectNotFoundException
SchemaException

refresh

public void refresh(OperationResult parentResult)
             throws ObjectNotFoundException,
                    SchemaException
Description copied from interface: Task
Re-reads the task state from the persistent storage. The task state may be synchronized with the repository all the time. But the specified timing is implementation-specific. Call to this method will make sure that the task contains fresh data. This has no effect on transient tasks.

Specified by:
refresh in interface Task
Throws:
ObjectNotFoundException
SchemaException

close

public void close(OperationResult parentResult)
           throws ObjectNotFoundException,
                  SchemaException
Description copied from interface: Task
Close the task. This will NOT release the task. TODO

Specified by:
close in interface Task
Throws:
ObjectNotFoundException
SchemaException

isSingle

public boolean isSingle()
Specified by:
isSingle in interface Task

isCycle

public boolean isCycle()
Specified by:
isCycle in interface Task

isTightlyBound

public boolean isTightlyBound()
Specified by:
isTightlyBound in interface Task

isLooselyBound

public boolean isLooselyBound()
Specified by:
isLooselyBound in interface Task

getSchedule

public ScheduleType getSchedule()
Specified by:
getSchedule in interface Task

shutdown

public void shutdown()
Description copied from interface: Task
Signal the task to shut down. It may not stop immediately, but it should stop eventually.

Specified by:
shutdown in interface Task

canRun

public boolean canRun()
Description copied from interface: Task
Returns true if the task can run (was not interrupted). Will return false e.g. if shutdown was signaled.

Specified by:
canRun in interface Task
Returns:
true if the task can run

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

makeRecurrent

public void makeRecurrent(long interval)

finishHandler

public void finishHandler()
Description copied from interface: Task
Marks current handler as finished, and removes it from the handler stack. This method *probably* should be called either implicitly by SingleRunner (after a handler returns from run() method) or explicitly by task handler, in case of CycleRunner. TODO this has to be thought out a bit.

Specified by:
finishHandler in interface Task


Copyright © 2012 evolveum. All Rights Reserved.