Showing posts with label HowTo. Show all posts
Showing posts with label HowTo. Show all posts

Tuesday, August 3, 2010

OIM Howto: Add parameters to your scheduled tasks

In many cases you want to externalize configuration parameters from the actual code in order to avoid having to recompile and deploy every time you want to change something. In scheduled tasks the simplest way to do this is to simply define your parameters in the scheduled task and then call them from the code.

public void init() {
 try {
    String dbName = getAttribute ( DATABASE_NAME );     
 } catch(Exception e) {
    logger.error ( "Exception while initializing recon analyzer scheduled task " + e.getMessage() ) ;
 }
}

This will get you access to the scheduled task attribute called DATABASE_NAME.

A slightly more advanced variant of the same is to let the attribute be a reference to another OIM object. In many cases ITResources are useful places to store attributes

String dbName = getAttribute ( DATABASE_NAME );
Hashtable itResourceAttr = tcUtilXellerateOperations.getITAssetProperties (super.getDataBase(), dbName.trim());

Now you have the parameters of this ItResource in the hashtable.

You will have to import com.thortech.xl.util.adapters.tcUtilXellerateOperations which is a very useful class full of nifty static methods.

Monday, August 2, 2010

OIM Howto: Create scheduled tasks

Scheduled tasks in OIM are used to run all kinds of reoccuring processes. They can also be used as convenient places to store little processes that needs to be run on demand.

To create a scheduled tasks you need to do the following things:
1. Create a java class that extends the SchedulerBaseTask (see example below)
2. Write your business logic
3. Compile and jar
4. Place the jar in the ScheduleTask directory in your OIM install
5. Create a new scheduled task using the OIM developer console
6. Link in the new class into your new scheduled task.
7. Done!

Example code for a scheduled task:

import com.thortech.xl.scheduler.tasks.SchedulerBaseTask;

public class ScheduledtaskExample extends SchedulerBaseTask {

   public void init()
   {
      //this method is run before execute by the scheduler 
   }

   public void execute() {
      //is executed by the scheduler
      runMyBusinessLogic();
   }

   private void runMyBusinessLogic(){
   //place your business logic here
   }
   
   public boolean stop() {
   //place logic that should run on a stop signal here
   }
}