1 22 package org.jboss.ejb3.test.timer; 23 24 import java.util.Date ; 25 26 import javax.annotation.Resource; 27 import javax.ejb.SessionContext ; 28 import javax.ejb.Timer ; 29 import javax.ejb.TimerService ; 30 import javax.ejb.TransactionAttribute ; 31 import javax.ejb.TransactionAttributeType ; 32 33 import org.jboss.logging.Logger; 34 35 43 public abstract class BaseTimerTesterBean 44 { 45 @SuppressWarnings ("unused") 46 private static final Logger log = Logger.getLogger(BaseTimerTesterBean.class); 47 48 protected static boolean timerCalled = false; 49 50 private @Resource TimerService timerService; 51 52 protected @Resource SessionContext ctx; 53 54 private static Timer timer; 56 57 @TransactionAttribute (TransactionAttributeType.MANDATORY) 58 public void checkMandatoryTransaction() 59 { 60 61 } 62 63 private void reset() 64 { 65 timerCalled = false; 66 timer = null; 67 } 68 69 public void setTimer(Date expiration) 70 { 71 reset(); 72 System.out.println("************ set timer " + expiration); 73 timer = timerService.createTimer(expiration, "TimerSLSBean"); 74 } 75 76 public void startTimer(long pPeriod) 77 { 78 reset(); 79 System.out.println("************ startTimer"); 80 timer = timerService.createTimer(new Date (new Date ().getTime() + pPeriod), "TimerSLSBean"); 81 } 82 83 public void startTimerAndRollback(long pPeriod) 84 { 85 reset(); 86 System.out.println("************ startTimerAndRollback"); 87 timer = ctx.getTimerService().createTimer(pPeriod, "TimerSLSBean"); 88 ctx.setRollbackOnly(); 89 } 90 91 public void startTimerViaEJBContext(long pPeriod) 92 { 93 reset(); 94 System.out.println("************ startTimerViaEJBContext"); 95 timer = ctx.getTimerService().createTimer(new Date (new Date ().getTime() + pPeriod), "TimerSLSBean"); 96 } 97 98 public void accessTimer() 99 { 100 timer.getTimeRemaining(); 102 timer.getHandle(); 103 timer.getInfo(); 104 } 105 106 public boolean isTimerCalled() 107 { 108 return timerCalled; 109 } 110 } 111 | Popular Tags |