1 17 package org.apache.servicemix.bpe.timer; 18 19 import java.util.Date ; 20 import java.util.Timer ; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 import org.apache.ode.bpe.event.ITimerEvent; 26 import org.apache.ode.bpe.timerservice.IBPETimer; 27 import org.apache.ode.bpe.timerservice.IBPETimerService; 28 import org.apache.ode.bpe.util.BPEProperties; 29 import org.apache.ode.bpe.util.BPException; 30 import org.apache.servicemix.bpe.BPEEndpoint; 31 32 public class BPETimerServiceJdk implements IBPETimerService { 33 34 private static final Log log = LogFactory.getLog(BPETimerServiceJdk.class); 35 private static Timer timer; 36 37 public BPETimerServiceJdk() { 38 super(); 39 } 40 41 public IBPETimer createTimer(long startDuration, ITimerEvent timerEvent) throws BPException { 42 if (log.isDebugEnabled()) { 43 log.debug("Schedule timer " + timerEvent + " for " + startDuration); 44 } 45 BPETimerJdk tt = new BPETimerJdk(timerEvent, BPEEndpoint.getCurrent()); 46 timer.schedule(tt, startDuration); 47 return tt; 48 } 49 50 public IBPETimer createTimer(Date startTime, ITimerEvent timerEvent) throws BPException { 51 if (log.isDebugEnabled()) { 52 log.debug("Schedule timer " + timerEvent + " at " + startTime); 53 } 54 BPETimerJdk tt = new BPETimerJdk(timerEvent, BPEEndpoint.getCurrent()); 55 timer.schedule(tt, startTime); 56 return tt; 57 } 58 59 public void removeTimer(IBPETimer timer) throws BPException { 60 if (log.isDebugEnabled()) { 61 log.debug("Timer " + timer.getTimerEvent() + " cancelled"); 62 } 63 ((BPETimerJdk) timer).cancel(); 64 65 } 66 67 public void init(BPEProperties props) throws BPException { 68 synchronized (BPETimerServiceJdk.class) { 69 if (timer == null) { 70 timer = new Timer (); 71 } 72 } 73 } 74 75 } 76 | Popular Tags |