use of javax.ejb.EJBException in project Payara by payara.
the class ActiveTxCache method removeBean.
/**
* container.preInvoke() must already be done.
* So this will be called with the proper Tx context.
* @exception RemoveException if an error occurs while removing the bean
*/
protected void removeBean(EjbInvocation inv) throws RemoveException {
try {
ejbProbeNotifier.ejbBeanDestroyedEvent(getContainerId(), containerInfo.appName, containerInfo.modName, containerInfo.ejbName);
// Note: if there are concurrent invocations/transactions in
// progress for this ejbObject, they will be serialized along with
// this remove by the database. So we optimistically do ejbRemove.
// call ejbRemove on the EJB
// the EJB is allowed to veto the remove by throwing RemoveException
EntityBean ejb = (EntityBean) inv.ejb;
EntityContextImpl context = (EntityContextImpl) inv.context;
callEJBRemove(ejb, context);
// inv.ejbObject could be a EJBObject or a EJBLocalObject
Object primaryKey = getInvocationKey(inv);
if (isRemote) {
removeEJBObjectFromStore(primaryKey);
}
if (isLocal) {
// Remove the EJBLocalObject from ejbLocalObjectStore
ejbLocalObjectStore.remove(primaryKey);
}
// Mark EJB as removed. Now releaseContext will add bean to pool
containerStateManager.markObjectRemoved(context, true);
// Remove any timers for this entity bean identity.
cancelTimers(primaryKey);
} catch (RemoveException ex) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "entitybean.container.local_remove_exception", logParams);
_logger.log(Level.FINE, "", ex);
}
throw ex;
} catch (Exception ex) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "entitybean.container.remove_bean_exception", logParams);
_logger.log(Level.FINE, "", ex);
}
throw new EJBException(ex);
}
}
use of javax.ejb.EJBException in project Payara by payara.
the class ActiveTxCache method _getContext.
/**
* Called from BaseContainer.preInvoke which is called from the EJBObject
* for local and remote invocations, and from the EJBHome for create/find.
*/
protected ComponentContext _getContext(EjbInvocation inv) {
if (inv.invocationInfo.isCreateHomeFinder) {
// create*, find*, home methods
// Note: even though CMP finders dont need an instance,
// we still return a pooled instance, so that the Tx demarcation
// in BaseContainer.pre+postInvoke can work.
// get any pooled EJB
EntityContextImpl context = getPooledEJB();
// we're sure that no concurrent thread can be using this
// context, so no need to synchronize.
context.setState(BeanState.INVOKING);
if (inv.invocationInfo.startsWithCreate)
preCreate(inv, context);
else if (inv.invocationInfo.startsWithFind)
preFind(inv, context);
context.setLastTransactionStatus(-1);
context.incrementCalls();
return context;
}
// If we came here, it means this is a business method
// and there is an EJBObject/LocalObject.
// If we would invoke the EJB with the client's Tx,
// try to get an EJB with that incomplete Tx.
EntityContextImpl context = null;
if (willInvokeWithClientTx(inv))
context = getEJBWithIncompleteTx(inv);
if (context == null)
context = getReadyEJB(inv);
synchronized (context) {
if (context.isInState(BeanState.INVOKING) && !isReentrant)
throw new EJBException("EJB is already executing another request");
if (context.isInState(BeanState.POOLED) || context.isInState(BeanState.DESTROYED)) {
// this is an internal error.
throw new EJBException("Internal error: unknown EJB state");
}
context.setState(BeanState.INVOKING);
}
context.setLastTransactionStatus(-1);
context.incrementCalls();
// A business method may modify the bean's state
context.setDirty(true);
return context;
}
use of javax.ejb.EJBException 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 javax.ejb.EJBException 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 javax.ejb.EJBException in project Payara by payara.
the class ReadOnlyBeanContainer method forceDestroyBean.
protected void forceDestroyBean(EJBContextImpl context) {
try {
ReadOnlyContextImpl readOnlyCtx = (ReadOnlyContextImpl) context;
if (readOnlyCtx.getReadOnlyBeanInfo() != null) {
readOnlyCtx.setReadOnlyBeanInfo(null);
robCache.remove(readOnlyCtx.getPrimaryKey(), true);
}
} catch (Exception ex) {
_logger.log(Level.SEVERE, "entitybean.container.forceDestroyBean", ex);
EJBException ejbEx = new EJBException();
ejbEx.initCause(ex);
throw ejbEx;
} finally {
super.forceDestroyBean(context);
}
}
Aggregations