1 17 18 package org.apache.james.util.watchdog; 19 20 import org.apache.avalon.cornerstone.services.scheduler.PeriodicTimeTrigger; 21 import org.apache.avalon.cornerstone.services.scheduler.Target; 22 import org.apache.avalon.cornerstone.services.scheduler.TimeScheduler; 23 24 54 public class SchedulerWatchdogFactory implements WatchdogFactory { 55 56 59 private TimeScheduler myTimeScheduler; 60 61 private long timeout = -1; 62 63 71 public SchedulerWatchdogFactory(TimeScheduler theTimeScheduler, long timeout) { 72 this.timeout = timeout; 73 myTimeScheduler = theTimeScheduler; 74 } 75 76 79 public Watchdog getWatchdog(WatchdogTarget theTarget) { 80 return new SchedulerWatchdog(theTarget); 81 } 82 83 87 private class SchedulerWatchdog implements Watchdog { 88 89 92 private String triggerID = null; 93 94 98 private WatchdogTarget theWatchdogTarget; 99 100 105 SchedulerWatchdog(WatchdogTarget theTarget) { 106 triggerID = this.toString(); 109 theWatchdogTarget = theTarget; 110 } 111 112 116 public void start() { 117 PeriodicTimeTrigger theTrigger = new PeriodicTimeTrigger((int)SchedulerWatchdogFactory.this.timeout, -1); 118 Target theTarget = new Target() { 119 public void targetTriggered(String targetID) { 120 theWatchdogTarget.execute(); 121 } 122 }; 123 SchedulerWatchdogFactory.this.myTimeScheduler.addTrigger(triggerID, theTrigger, theTarget); 124 } 125 126 130 public void reset() { 131 SchedulerWatchdogFactory.this.myTimeScheduler.resetTrigger(triggerID); 132 } 133 134 138 public void stop() { 139 SchedulerWatchdogFactory.this.myTimeScheduler.removeTrigger(triggerID); 140 } 141 } 142 143 } 144 | Popular Tags |