1 package org.jfox.ejb.timer; 2 3 import java.io.Serializable ; 4 import java.util.TimerTask ; 5 import javax.ejb.EJBException ; 6 import javax.ejb.TimedObject ; 7 import javax.ejb.Timer ; 8 9 import org.jfox.ejb.Bucket; 10 import org.jfox.ejb.EJBObjectId; 11 import org.jfox.ejb.connector.EJBContainerImpl; 12 import org.jfox.ejb.connector.EJBInvocation; 13 import org.jfox.ioc.ComponentName; 14 import org.jfox.ioc.Registry; 15 import org.jfox.ioc.connector.ConnectorRemote; 16 import org.jfox.ioc.connector.Container; 17 import org.jfox.ioc.connector.local.LOCALConnectorRemote; 18 import org.jfox.ioc.util.Methods; 19 20 23 24 public class EJBTimerTask extends TimerTask { 25 26 private EJBTimerService timerService; 27 private EJBTimer timer; 28 29 30 public EJBTimerTask(EJBTimerService timerService, Serializable info) { 31 this.timerService = timerService; 32 timer = new EJBTimer(this, info); 33 } 34 35 public Timer getTimer() { 36 return timer; 37 } 38 39 public void run() { 40 String ejbName = timerService.getEjbName(); 41 42 try { 43 Bucket bucket = ((EJBContainerImpl) Registry.getInstance().getComponentInstance(ComponentName.parseString(Container.class.getName() + "@EJB"))).getBucket(ejbName); 44 45 if(!TimedObject .class.isAssignableFrom(bucket.getBeanClass())) { 46 throw new EJBException ("ejb " + ejbName + " not implements " + TimedObject .class.getName()); 47 } 48 EJBObjectId objectId = bucket.nextObjectId(); 50 EJBInvocation invocation = new EJBInvocation(objectId, "" + Methods.getMethodHash(TimedObjectMethod.TimeOut), new Object []{timer}); 51 52 ConnectorRemote local = LOCALConnectorRemote.getInstance(); 56 local.invoke(invocation); 57 } 58 catch(Exception e) { 59 e.printStackTrace(); 60 } 61 } 62 63 public boolean cancel() { 64 timerService.cancel(this); 65 return super.cancel(); 66 } 67 68 EJBTimerService getTimerService() { 69 return timerService; 70 } 71 72 public static void main(String [] args) { 73 74 } 75 } 76 77 | Popular Tags |