Writing a Scheduler
This is a simple scheduler that prints "Hello World" to the console. See the steps to write and debug a scheduler in ATG.
ExampleScheduler.properties
package com.wilcats.schedulers; import atg.nucleus.GenericService; import atg.nucleus.ServiceException; import atg.service.scheduler.Schedulable; import atg.service.scheduler.Schedule; import atg.service.scheduler.ScheduledJob; import atg.service.scheduler.Scheduler; /** * * * @version : 1.0 */ public class ExampleScheduler extends GenericService implements Schedulable{ // Scheduler property Scheduler scheduler; public Scheduler getScheduler() { return scheduler; } public void setScheduler(Scheduler scheduler){ this.scheduler = scheduler; } // Schedule property Schedule schedule; public Schedule getSchedule() { return schedule; } public void setSchedule(Schedule schedule){ this.schedule = schedule; } int jobId; // Schedulable method public void performScheduledTask(Scheduler scheduler, ScheduledJob job){ logDebug("Hello World!!!"); System.out.println("Hello World"); } // Start method public void doStartService () throws ServiceException{ ScheduledJob job = new ScheduledJob("hello", "Prints Hello World", getAbsoluteName(), getSchedule(), this, ScheduledJob.SCHEDULER_THREAD); jobId = getScheduler().addScheduledJob(job); } // Stop method public void doStopService() throws ServiceException{ getScheduler().removeScheduledJob(jobId); } }
ExampleScheduler.properties
$class=com.wildcats.schedulers.ExampleScheduler $scope=global scheduler=/atg/dynamo/service/Scheduler schedule=every 30 seconds threadMethod=2 loggingDebug=true
Initialize this scheduler in initial.properties only if you want this scheduler to initialize/run on start up of the server. For more details on initial.properties read http://docs.oracle.com/cd/E23095_01/Platform.93/ATGProgGuide/html/s0204startinganucleuscomponent01.html
Intialize the ExampleScheduler in initial.properties like below:
Steps to execute a Scheduler/com/wilcats/schedulers/ExampleScheduler
- Write the above classes to your ATG code base
- Build your code.
- Start your server. For eg: Jboss server using startJboss.sh
- Go to ATG Dynamo Server Admin. See details in the next section.
- It will show you the component browser. Search your scheduler - ExampleScheduler
- Once you reach the ExampleScheduler page - go to the bottom of the page and you will see a set of methods listed. Click on doStartService. It will ask you to confirm to invoke this call.
- Confirm you want to invoke this method call.
- Check your server-log/console and you will see "Hello World" printed there.
ATG Dynamo Server Admin
The ATG Dynamo Server Admin gives you quick access to a number of useful features. For example, you can modify the configuration for ATG server instances, browse the Nucleus component hierarchy, change administrator passwords, and so on.
To start the ATG Dynamo Server Admin:
- In a browser window, go to the following URL: http://localhost:8080/dyn/admin
- Username: admin
- Password: admin
Debugging Schedulers
- In eclipse, go to Debug configurations -> Remote Java Applications -> right click create new -> change the port to 8787.
- Once you have started your server, you can add breakpoints in your code and start debugging
- Hint: Change the schedule of your scheduler to run every 4 hours. Put breakpoint on doStartService(), performScheduledTask(), doScheduledTask()
References
Oracle ATG Scheduler Services - http://docs.oracle.com/cd/E23095_01/Platform.93/ATGProgGuide/html/s0905schedulerservices01.html
Sample Scheduling a task in ATG - http://immuraliraj.blogspot.com/2012/12/sample-scheduling-task-atg.html
Schedule Settings - http://docs.oracle.com/cd/E24152_01/Platform.10-1/ATGPlatformProgGuide/html/s1005configuringaschedulablecomponent01.html