1:/** 2: * Title: MyScheduledTask.java<p> 3: * Description: A servlet to try out the Dynamo scheduler<p> 4: * Company: Critical Mass Productions Inc.<p> 5: * @author Darcy Schultz 6: * @version $Revision: $ 7: */ 8:import atg.nucleus.*; 9:import atg.service.scheduler.*; 10: 11:public class MyScheduledTask extends GenericService implements Schedulable{ 12: /** 13: * A handle to the Dynamo scheduler object 14: */ 15: private Scheduler mScheduler = null; 16: 17: /** 18: * a private variable to store the job this object represents in the Dynamo scheduler 19: */ 20: private int mJobId; 21: 22: /** 23: * a property to set the time between job executions 24: */ 25: private long mTimeBetween; 26: 27: /** 28: * This constant is used for debugging a 'live' environment. 29: * It returns information to positely identify the version of the class instance. 30: * The string is automatically updated by CVS. 31: */ 32: public static final String CVS_HEADER = "$Header: $ : $Name: $"; 33: 34: /** 35: * get the Scheduler property 36: */ 37: public Scheduler getScheduler(){ 38: return mScheduler; 39: } 40: 41: /** 42: * set the Scheduler property 43: */ 44: public void setScheduler( Scheduler pScheduler){ 45: if (pScheduler != mScheduler){ 46: mScheduler = pScheduler; 47: } 48: } 49: 50: /** 51: * set the time to wait between executions of this job 52: * the service needs to be restarted to recognize a new time 53: */ 54: public void setTimeBetween( long pTimeBetween){ 55: mTimeBetween = pTimeBetween; 56: } 57: 58: /** 59: * get the time to wait between executions of this job 60: */ 61: public long getTimeBetween(){ 62: return mTimeBetween; 63: } 64: 65: /** 66: * The default constructor 67: */ 68: public MyScheduledTask() { 69: } 70: 71: /** 72: * Override this method to add this object to the Dynamo Scheduler 73: */ 74: public void doStartService() throws ServiceException{ 75: mJobId = mScheduler.addScheduledJob( 76: new ScheduledJob( "MyScheduledTask", "Prints Hello", 77: this.getAbsoluteName(), new PeriodicSchedule( mTimeBetween ), 78: this, ScheduledJob.REUSED_THREAD ) ); 79: } 80: 81: /** 82: * Remove this object from the scheduler 83: */ 84: public void doStopService() throws ServiceException{ 85: mScheduler.removeScheduledJob( mJobId ); 86: } 87: 88: /** 89: * This method gets fired by the Dynamo Scheduler. 90: * Include in the body of this method the stuff that you want to do 91: */ 92: 93: public void performScheduledTask(Scheduler pScheduler, ScheduledJob pJob){ 94: System.out.println( "Hello, World!" ); 95: } 96: 97:}