1 package org.jfox.ejb.timer; 2 3 import javax.ejb.EJBException ; 4 import javax.ejb.NoSuchObjectLocalException ; 5 import javax.ejb.Timer ; 6 import javax.ejb.TimerHandle ; 7 8 import org.jfox.ejb.connector.EJBContainerImpl; 9 import org.jfox.ioc.ComponentName; 10 import org.jfox.ioc.Registry; 11 import org.jfox.ioc.connector.Container; 12 13 16 17 public class EJBTimerHandler implements TimerHandle { 18 private String ejbName; 19 private String identity; 20 21 public EJBTimerHandler(String ejbName, String identity) { 22 this.ejbName = ejbName; 23 this.identity = identity; 24 } 25 26 32 public Timer getTimer() throws IllegalStateException , NoSuchObjectLocalException , EJBException { 33 try { 34 EJBTimerService timerService = (EJBTimerService) ((EJBContainerImpl) Registry.getInstance().getComponentInstance(ComponentName.parseString(Container.class.getName() + "@EJB"))).getBucket(ejbName).getTimerService(); 35 return timerService.getTimer(identity); 36 } 37 catch(Exception e){ 38 e.printStackTrace(); 39 return null; 40 } 41 } 42 43 44 public String toString() { 45 return "EJBTimerHandler{" + 46 "ejbName='" + ejbName + "'" + 47 ", identity='" + identity + "'" + 48 "}"; 49 } 50 51 public static void main(String [] args) { 52 53 } 54 } 55 56 | Popular Tags |