1 16 17 package org.apache.axis2.deployment.scheduler; 18 19 import java.util.Date ; 20 import java.util.Timer ; 21 import java.util.TimerTask ; 22 23 public class Scheduler { 24 25 private final Timer timer = new Timer (); 26 27 public class SchedulerTimerTask extends TimerTask { 28 29 private SchedulerTask schedulerTask; 30 private DeploymentIterator iterator; 31 32 33 public SchedulerTimerTask(SchedulerTask schedulerTask, DeploymentIterator iterator) { 34 this.schedulerTask = schedulerTask; 35 this.iterator = iterator; 36 } 37 38 public void run() { 39 schedulerTask.run(); 40 reschedule(schedulerTask, iterator); 41 } 42 } 43 44 54 55 public void schedule(SchedulerTask schedulerTask, DeploymentIterator iterator) { 56 57 Date time = iterator.next(); 58 if (time == null) { 59 schedulerTask.cancel(); 60 } else { 61 synchronized (schedulerTask.lock) { 62 schedulerTask.state = SchedulerTask.SCHEDULED; 63 schedulerTask.timerTask = 64 new SchedulerTimerTask(schedulerTask, iterator); 65 timer.schedule(schedulerTask.timerTask, time); 66 } 67 } 68 } 69 70 private void reschedule(SchedulerTask schedulerTask, DeploymentIterator iterator) { 71 Date time = iterator.next(); 72 if (time == null) { 73 schedulerTask.cancel(); 74 } else { 75 synchronized (schedulerTask.lock) { 76 if (schedulerTask.state != SchedulerTask.CANCELLED) { 77 schedulerTask.timerTask = 78 new SchedulerTimerTask(schedulerTask, iterator); 79 timer.schedule(schedulerTask.timerTask, time); 80 } 81 } 82 } 83 } 84 85 } 86 | Popular Tags |