package org.jfox.ejb;
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.Handle;
import javax.ejb.RemoveException;
import javax.ejb.EnterpriseBean;
import javax.ejb.SessionContext;
public class StatelessSessionBulk extends SessionBulk {
private StatelessSessionObjectPool instancePool = null;
private ObjectId beanObjectId = null;
private SessionContext ejbConext = null;
public StatelessSessionBulk(BulkMetaData meta) {
super(meta);
}
public Object invokeHome(Invocation invocation) throws Exception {
logger.debug("invokeHome " + invocation.getMethod().getName());
return StatelessInvokerChain.getInstance().invokeHome(this,invocation);
}
public Object invokeBean(Invocation invocation) throws Exception {
logger.debug("invokeBean " + invocation.getMethod().getName());
return StatelessInvokerChain.getInstance().invokeBean(this,invocation);
}
public void remove(Handle handle) throws RemoteException, RemoveException {
try {
EJBPoolableObject pobj = (EJBPoolableObject)instancePool.retrieveObject();
remove(pobj.getBeanInstance());
}
catch(Exception e) {
throw new RemoveException(e.getMessage());
}
}
public void remove(EnterpriseBean bean) throws RemoteException, RemoveException {
ejbRemove((SessionBean)bean);
}
public boolean isIdentical(ObjectId thisObjectId, ObjectId thatObjectId) throws RemoteException {
return true;
}
public EJBPoolableObject retrieveBean(Object key) throws Exception {
StatelessEJBPoolableObject pobj = (StatelessEJBPoolableObject)instancePool.retrieveObject();
if(pobj.isFresh()) { SessionBean bean = (SessionBean)pobj.getBeanInstance();
setSessionContext(bean, ejbConext);
ejbCreate(bean,"create",null);
pobj.notFresh();
}
return pobj;
}
public void restoreBean(Object key, EJBPoolableObject pobj) {
instancePool.restoreObject(pobj);
}
public ObjectId createBean(Invocation invocation) throws Exception {
if(beanObjectId == null) { beanObjectId = oidGenerator.nextBeanObjectId();
ejbConext = new SessionContextImpl(beanObjectId,bulkMeta);
}
StatelessEJBPoolableObject pobj = (StatelessEJBPoolableObject)instancePool.createObject();
if(pobj.isFresh()) { SessionBean bean = (SessionBean)pobj.getBeanInstance();
setSessionContext(bean, ejbConext);
ejbCreate(bean,"create",null);
pobj.notFresh();
}
this.restoreBean(invocation.getObjectId(),pobj);
return beanObjectId;
}
protected void doInit() throws Exception {
instancePool = new StatelessSessionObjectPool(this,new EJBObjectFactory(StatelessEJBPoolableObject.class,bulkMeta.getBeanClass()));
instancePool.init();
super.doInit();
}
protected void doDestroy() throws Exception {
super.doDestroy();
instancePool.destroy();
}
}