3.8 Task Chaining

You can create a task that automatically executes upon completion of another task—a process called task chaining. Task chaining can help you avoid duplicating work when you have a task that already accomplishes part of what you need your task to do. You can chain a task that does the remaining work to an existing task. For example, suppose you need a task that creates a user and assigns the user to an organizational unit. iManager includes the Create User task for creating users. You can create a task that assigns a user to an organizational unit and chain it to the Creat User task.

To chain tasks you need to

3.8.1 Setting Objects in the Initial Task

To pass objects from the initial task, you need to call com.novell.nps.gadgetManager.JobData.put(Object key, Object value) or com.novell.nps.gadgetManager.JobData.setObjectNames(String[] names) in the first task in the chain. For example:

 import com.novell.nps.gadgetManager.JobData;
 
 JobData data = JobData.getJobData(this);
 if (null != data)
 {
   data.put(ANYKey, anyValue);
 }
 

The Create User task provided by iManager is already enabled for serving as the initial task in a task chain. The name of the User object created is set using the following code:

 JobData data = JobData.getJobData(this);
 if (null != data)
 {
   data.setObjectNames(new String[]{targetOE.getFullName()});
 }
 

3.8.2 Getting Objects in the Chained Task

To get an object reference from the initial task, call com.novell.nps.gadgetManager.JobData.getJobData(GadgetInstance gadget):

 JobData data = JobData.getJobData(this);
 if (null != data)
 {
   String [] objNames = data.getObjectNames();
 }
 

3.8.3 Defining the Chained Task in a Registration File

Use the <chained-task> element to define the chained task in a registration file:

 <plugin>
   <chained-task>
     <id>moduleId.ChainedTaskId</id>
     <chaining-initial-task-id>base.CreateUser</chaining-initial-task-id>
     <order>300</order>
      ... (Everything else your task needs, just like a normal task,
           <class-name>, <display-name>, etc.)
   </chained-task>
 </plugin>
 

The <chained-task> element is identical to the <task> element, except that it allows for an additional child element, <chaining-initial-task-id>, which is the element you use to specify the task that the chained task will follow. The <order> element specifies the order of appearance of tasks in a role.