1 6 7 package org.jfox.ejb; 8 9 import java.rmi.RemoteException ; 10 import javax.ejb.EnterpriseBean ; 11 import javax.ejb.Handle ; 12 import javax.ejb.RemoveException ; 13 import javax.ejb.SessionBean ; 14 import javax.ejb.SessionContext ; 15 16 import org.jfox.ejb.connector.EJBInvocation; 17 import org.jfox.ioc.ComponentName; 18 import org.jfox.ioc.depend.DependencyPack; 19 import org.jfox.ioc.depend.ObjectDependency; 20 21 26 27 public class StatelessBucket extends SessionBucket { 28 29 private StatelessObjectPool instancePool = null; 30 33 private EJBObjectId beanObjectId = null; 34 private SessionContext ejbConext = null; 35 36 public StatelessBucket() { 37 38 } 39 40 public void remove(Handle handle) throws RemoteException , RemoveException { 42 try { 43 EJBPoolableObject pobj = (EJBPoolableObject) instancePool.retrieveObject(); 44 remove(pobj.getBeanInstance()); 45 } 46 catch(Exception e) { 47 throw new RemoveException (e.getMessage()); 48 } 49 } 50 51 public void remove(EnterpriseBean bean) throws RemoteException , RemoveException { 52 ejbRemove((SessionBean ) bean); 53 } 54 55 public boolean isIdentical(EJBObjectId thisObjectId, EJBObjectId thatObjectId) throws RemoteException { 57 return true; 58 } 59 60 public EJBPoolableObject retrieveBean(Object key) throws Exception { 61 StatelessPoolableObject pobj = (StatelessPoolableObject) instancePool.retrieveObject(); 62 if(!pobj.isEjbCreated()) { SessionBean bean = (SessionBean ) pobj.getBeanInstance(); 64 setContext(bean, ejbConext); 65 ejbCreate(bean, "create", null); 66 pobj.ejbCreated(); 67 } 68 return pobj; 69 } 70 71 public void restoreBean(Object key, EJBPoolableObject pobj) { 72 instancePool.restoreObject(pobj); 73 } 74 75 public EJBObjectId createBean(EJBInvocation invocation) throws Exception { 76 if(beanObjectId == null) { beanObjectId = nextObjectId(); 78 ejbConext = new SessionContextImpl(beanObjectId, bucketMeta); 79 } 80 StatelessPoolableObject pobj = (StatelessPoolableObject) instancePool.createObject(); 81 if(!pobj.isEjbCreated()) { SessionBean bean = (SessionBean ) pobj.getBeanInstance(); 83 setContext(bean, ejbConext); 84 ejbCreate(bean, "create", null); 86 pobj.ejbCreated(); 87 } 88 this.restoreBean(invocation.getObjectId(), pobj); 89 return beanObjectId; 90 } 91 92 public void syncBean(EJBInvocation invocation) { 93 112 } 113 114 protected void doInit() throws Exception { 115 super.doInit(); 116 instancePool = (StatelessObjectPool)context.getRegistry().getComponentInstance( 117 ComponentName.newInstance(StatelessObjectPool.class), 118 new DependencyPack[]{ 119 new DependencyPack("EJBObjectFactory", 120 new ObjectDependency(new StatelessObjectFactory(StatelessPoolableObject.class, this)))}); 121 } 122 123 protected void doDestroy() throws Exception { 124 super.doDestroy(); 125 instancePool.destroy(); 126 } 127 } | Popular Tags |