1 25 package org.objectweb.easybeans.tests.common.resources; 26 27 import javax.annotation.Resource; 28 import javax.ejb.Timer ; 29 import javax.ejb.TimerService ; 30 import javax.naming.Context ; 31 import javax.naming.InitialContext ; 32 33 34 40 public class TimerServiceTester { 41 42 45 public static final int TIMER_DURATION = 500000; 46 49 @Resource 50 private TimerService tServ; 51 52 55 public TimerServiceTester(){ 56 } 57 58 62 protected void access00() throws Exception { 63 checkInstance(tServ); 64 } 65 66 71 public static void checkInstance(final TimerService ts) throws Exception { 72 Timer t = ts.createTimer(TIMER_DURATION, "Timer Created"); 74 t.getTimeRemaining(); 76 77 if(ts.getTimers().size() < 1){ 79 throw new IllegalStateException ("The Timers Collection must have at least one timer. It was created in this method."); 80 } 81 t.cancel(); 83 } 84 85 89 public static void checkJNDI() throws Exception { 90 Context ctx = new InitialContext (); 91 92 TimerService ts = (TimerService ) ctx.lookup("java:comp/TimerService"); 93 if (ts == null){ 94 throw new Exception ("TimerService reference obtained using JNDI API is null."); 95 } 96 } 97 } 98 | Popular Tags |