use of com.sun.ejb.containers.EJBObjectImpl in project Payara by payara.
the class ActiveTxCache method getEJBObjectStub.
// called from postFind, getEJBObjectForPrimaryKey,
// EntityContextImpl.getEJBObject()
EJBObject getEJBObjectStub(Object primaryKey, byte[] streamKey) {
// check if the EJBObject exists in the store.
try {
EJBObjectImpl ejbObjImpl = (EJBObjectImpl) ejbObjectStore.get(primaryKey);
if ((ejbObjImpl != null) && (ejbObjImpl.getStub() != null)) {
return (EJBObject) ejbObjImpl.getStub();
}
// create a new stub without creating the EJBObject itself
if (streamKey == null) {
streamKey = EJBUtils.serializeObject(primaryKey, false);
}
EJBObject ejbStub = (EJBObject) remoteHomeRefFactory.createRemoteReference(streamKey);
return ejbStub;
} catch (Exception ex) {
_logger.log(Level.FINE, "", ex);
throw new EJBException(ex);
}
}
use of com.sun.ejb.containers.EJBObjectImpl in project Payara by payara.
the class ActiveTxCache method activateEJBFromPool.
/**
* Called from getContext and getEJBWithIncompleteTx
* Get an EJB in the ready state (i.e. which is not doing any
* invocations and doesnt have any incomplete Tx), for the
* ejbObject provided in the EjbInvocation.
* Concurrent invocations should get *different* instances.
*/
protected EntityContextImpl activateEJBFromPool(Object primaryKey, EjbInvocation inv) {
EntityContextImpl context = null;
// get a pooled EJB and activate it.
context = getPooledEJB();
// set EJBObject/LocalObject for the context
if (inv.isLocal) {
EJBLocalObjectImpl localObjImpl = internalGetEJBLocalObjectImpl(primaryKey, true);
containerStateManager.attachObject(inv, context, null, localObjImpl);
// No need to create/set EJBObject if this EJB isRemote too.
// This saves remote object creation overhead.
// The EJBObject and stub will get created lazily if needed
// when EntityContext.getEJBObjectImpl is called.
} else {
// remote EjbInvocation
EJBObjectImpl ejbObjImpl = internalGetEJBObjectImpl(primaryKey, null, true);
containerStateManager.attachObject(inv, context, ejbObjImpl, null);
if (isLocal) {
// Create EJBLocalObject so EntityContext methods work
containerStateManager.attachObject(inv, context, null, internalGetEJBLocalObjectImpl(primaryKey, true));
}
}
context.setState(BeanState.READY);
EntityBean ejb = (EntityBean) context.getEJB();
EjbInvocation inv2 = super.createEjbInvocation(ejb, context);
inv2.method = ejbActivateMethod;
invocationManager.preInvoke(inv2);
try {
ejb.ejbActivate();
// Note: ejbLoad will be called during preInvokeTx
// since this EJB instance is being associated with
// a Tx for the first time.
} catch (Exception ex) {
// Error during ejbActivate, discard bean: EJB2.0 18.3.3
forceDestroyBean(context);
throw new EJBException(ex);
} finally {
invocationManager.postInvoke(inv2);
}
context.setNewlyActivated(true);
// recycler.initSoftRef(context);
afterNewlyActivated(context);
return context;
}
use of com.sun.ejb.containers.EJBObjectImpl in project Payara by payara.
the class ActiveTxCache method internalGetEJBObjectImpl.
// called from getEJBObject, postCreate, postFind,
// getEJBObjectForPrimaryKey, removeBean
private EJBObjectImpl internalGetEJBObjectImpl(Object primaryKey, byte[] streamKey, boolean incrementRefCount, boolean cacheEJBO) {
// check if the EJBContext/EJBObject exists in the store.
try {
EJBObjectImpl ejbObjImpl = (EJBObjectImpl) ejbObjectStore.get(primaryKey, incrementRefCount);
if ((ejbObjImpl != null) && (ejbObjImpl.getStub() != null)) {
return ejbObjImpl;
}
// check if the EJBContext/EJBObject exists in threadlocal
// This happens if ejbo is in the process of being created.
// This is necessary to prevent infinite recursion
// because PRO.narrow calls is_a which calls the
// ProtocolMgr which calls getEJBObject.
ejbObjImpl = (EJBObjectImpl) ejbServant.get();
if (ejbObjImpl != null) {
return ejbObjImpl;
}
// set ejbo in thread local to help recursive calls find the ejbo
ejbServant.set(ejbObjImpl);
if (streamKey == null) {
streamKey = EJBUtils.serializeObject(primaryKey, false);
}
EJBObject ejbStub = (EJBObject) remoteHomeRefFactory.createRemoteReference(streamKey);
// create the EJBObject and associate it with the stub
// and the primary key
ejbObjImpl = instantiateEJBObjectImpl(ejbStub, primaryKey);
ejbServant.set(null);
if ((incrementRefCount || cacheEJBO)) {
EJBObjectImpl ejbo1 = (EJBObjectImpl) ejbObjectStore.put(primaryKey, ejbObjImpl, incrementRefCount);
if ((ejbo1 != null) && (ejbo1 != ejbObjImpl)) {
remoteHomeRefFactory.destroyReference(ejbObjImpl.getStub(), ejbObjImpl);
ejbObjImpl = ejbo1;
}
}
return ejbObjImpl;
} catch (Exception ex) {
_logger.log(Level.FINE, "entitybean.container.get_ejb_context_exception", logParams);
_logger.log(Level.FINE, "", ex);
throw new EJBException(ex);
}
}
use of com.sun.ejb.containers.EJBObjectImpl in project Payara by payara.
the class ActiveTxCache method doConcreteContainerShutdown.
protected void doConcreteContainerShutdown(boolean appBeingUndeployed) {
String ejbName = ejbDescriptor.getName();
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "[EntityContainer]: Undeploying " + ejbName + " ...");
}
try {
Iterator elements = ejbObjectStore.values();
while (elements.hasNext()) {
EJBObjectImpl ejbObjImpl = (EJBObjectImpl) elements.next();
try {
if (isRemote) {
remoteHomeRefFactory.destroyReference(ejbObjImpl.getStub(), ejbObjImpl.getEJBObject());
}
} catch (Exception ex) {
_logger.log(Level.FINE, "Exception in undeploy()", ex);
}
}
// store must set the listern to null
ejbObjectStore.destroy();
ejbObjectStore = null;
// store must set the listern to null
ejbLocalObjectStore.destroy();
ejbLocalObjectStore = null;
// destroy all EJB instances in readyStore
// cache must set the listern to null
destroyReadyStoreOnUndeploy();
entityCtxPool.close();
poolProbeListener.unregister();
if (cacheProbeListener != null) {
cacheProbeListener.unregister();
}
// does not remove the task from the timer's queue
if (idleBeansPassivator != null) {
try {
idleBeansPassivator.cancel();
} catch (Exception e) {
_logger.log(Level.FINE, "[EntityContainer] cancelTimerTask: ", e);
}
this.idleBeansPassivator.cache = null;
}
cancelTimerTasks();
} finally {
// helps garbage collection
this.ejbObjectStore = null;
this.ejbLocalObjectStore = null;
this.passivationCandidates = null;
this.readyStore = null;
this.entityCtxPool = null;
this.iased = null;
this.beanCacheDes = null;
this.beanPoolDes = null;
this.ejbContainer = null;
this.cacheProp = null;
this.poolProp = null;
this.asyncTaskSemaphore = null;
this.idleBeansPassivator = null;
}
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, " [EntityContainer]: Successfully Undeployed " + ejbName);
}
}
use of com.sun.ejb.containers.EJBObjectImpl in project Payara by payara.
the class ActiveTxCache method postCreate.
/**
* This is called from the generated "HelloEJBHomeImpl" create* method,
* after ejb.ejbCreate() has been called and before ejb.ejbPostCreate()
* is called.
* Note: postCreate will not be called if ejbCreate throws an exception
*/
public void postCreate(EjbInvocation inv, Object primaryKey) throws CreateException {
if (primaryKey == null)
throw new EJBException("Null primary key returned by ejbCreate method");
if ((isRemote) && (!inv.isLocal)) {
// remote EjbInvocation: create EJBObject
EJBObjectImpl ejbObjImpl = internalGetEJBObjectImpl(primaryKey, null, true);
// associate the context with the ejbObject
containerStateManager.attachObject(inv, (EJBContextImpl) inv.context, ejbObjImpl, null);
}
if (isLocal) {
// create EJBLocalObject irrespective of local/remote EjbInvocation
// this is necessary to make EntityContext.getPrimaryKey and
// EntityContext.getEJBObject work.
EJBLocalObjectImpl localObjImpl = internalGetEJBLocalObjectImpl(primaryKey, true);
// associate the context with the ejbLocalObject
containerStateManager.attachObject(inv, (EJBContextImpl) inv.context, null, localObjImpl);
}
EntityContextImpl context = (EntityContextImpl) inv.context;
if (context.getTransaction() != null) {
// Add EJB to INCOMPLETE_TX table so that concurrent/loopback
// invocations will be correctly handled
addIncompleteTxEJB(context);
}
// ejbPostCreate could modify state
context.setDirty(true);
}
Aggregations