A Task is a worker object that allows the CIM framework to make a change in the system. Task objects implement the execute() method in the atg.cim.worker.ITask interface.
ITask defines the methods shown:
package atg.cim.worker;
import java.io.Serializable;
/**
* ITask objects are serializable javabeans that perform an action.
*/
public interface ITask extends Serializable {
/**
* Called by the CIM Framework before calling execute(). Logic checking if the
*task can be executed should be placed in this method.
*
* @return true if the object has all the values needed to execute
*/
public boolean canExecute();
/**
* Logic to perform a task should be placed in this method. Code should update
*the message property so the framework may retrieve the last state of the
*component.
*
* The IProgressMonitor may be null, so logic should test before using this
*argument.
*
* @throws TaskException
*/
public void execute(IProgressMonitor progressMonitor) throws TaskException;
/**
* Called by the CIM Framework before calling undo(). Logic to check should be
*placed in this method.
*
* @return true if the object can undo
*/
public boolean canUndo();
/**
* Logic to return a system to its before-execute state.
*
* The IProgressMonitor may be null, so logic should test before using this
*argument
*
* @throws TaskException
*/
public void undo(IProgressMonitor progressMonitor) throws TaskException;
/**
* Retrieve the text describing the state of the component for UI display.
*
* @return String containing the status of the component.
*/
public String getMessage();
}It is a good practice to end your class names with Task (for example: ATGPathTask).
You can extend the atg.cim.worker.Task class to create custom tasks, as shown in the Example: Writing a HelloWorld Task section.
The progressMonitor method can be used to display a status bar for any task that is defined in its XML as “long-running.” In the provided configuration scripts, tasks such as schema creation and data import are considered long-running. It can show progress when the amount of work is unknown (similar to the Windows spinning hourglass cursor), or to show increments of a known amount of work as they are completed. The Progress Monitor interface is shown here:
public interface IProgressMonitor {
/** Class version string */
public static final String CLASS_VERSION = "$Change: 509503 $$DateTime:
2008/09/16 13:48:09 $$Author: acollege $";
/**
* Constant indicating an unknown amount of work.
*/
public static final int UNKNOWN = -1;
/**
* Called by worker object at the start of a long running task. Should only be
*called once on a given
* IProgressMonitor instance.
*
* @param pTaskMsg - msg to display to the UI
* @param totalWork - the total number of units to be processed. Value may be
*IProgressMonitor.UNKNOWN for
* when the total number of work units is not known in advance
*/
public void beginTask(String pTaskMsg, int pTotalWork);
/**
* Called numerous times by a worker object as a long running task is being
*processed
*
* @param work the number of units of work completed for this call. This is an
*incremental value,
* not the cumulative amount of work performed so far.
*
*/
public void worked(int pWork);
/**
* Called once by worker object when work has been completed
*
*/
public void setTaskComplete(boolean pComplete);
}
