use of javax.ejb.EJBObject in project tomee by apache.
the class UnknownHandleTests method test01_getEJBObject.
// =================================
// Test handle methods
//
public void test01_getEJBObject() {
try {
final EJBObject object = ejbHandle.getEJBObject();
assertNotNull("The EJBObject is null", object);
// Wait until isIdentical is working.
// assertTrue("EJBObjects are not identical", object.isIdentical(ejbObject));
} catch (final Exception e) {
fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
}
use of javax.ejb.EJBObject in project Payara by payara.
the class AsynchronousTask method forceDestroyBean.
/**
* Force destroy the EJB and rollback any Tx it was associated with
* Called from removeBean, timeoutBean and BaseContainer.postInvokeTx.
* Note: EJB2.0 section 18.3.1 says that discarding an EJB
* means that no methods other than finalize() should be invoked on it.
*/
@Override
protected void forceDestroyBean(EJBContextImpl ctx) {
SessionContextImpl sc = (SessionContextImpl) ctx;
synchronized (sc) {
if (sc.getState() == EJBContextImpl.BeanState.DESTROYED) {
return;
}
// mark context as destroyed so no more invocations happen on it
sc.setState(BeanState.DESTROYED);
cleanupInstance(ctx);
_logger.log(FINE, () -> "[SFSBContainer] (Force)Destroying session: " + sc.getInstanceKey());
Transaction prevTx = sc.getTransaction();
try {
if (prevTx != null && prevTx.getStatus() != Status.STATUS_NO_TRANSACTION) {
prevTx.setRollbackOnly();
}
} catch (SystemException ex) {
throw new EJBException(ex);
} catch (IllegalStateException ex) {
throw new EJBException(ex);
}
// remove the bean from the session store
Object sessionKey = sc.getInstanceKey();
sessionBeanCache.remove(sessionKey, sc.existsInStore());
if (isRemote) {
if (hasRemoteHomeView) {
// disconnect the EJBObject from the context and vice versa
EJBObjectImpl ejbObjImpl = sc.getEJBObjectImpl();
ejbObjImpl.clearContext();
ejbObjImpl.setRemoved(true);
sc.setEJBObjectImpl(null);
// disconnect the EJBObject from the ProtocolManager
// so that no remote invocations can reach the EJBObject
remoteHomeRefFactory.destroyReference(ejbObjImpl.getStub(), ejbObjImpl.getEJBObject());
}
if (hasRemoteBusinessView) {
EJBObjectImpl ejbBusinessObjImpl = sc.getEJBRemoteBusinessObjectImpl();
ejbBusinessObjImpl.clearContext();
ejbBusinessObjImpl.setRemoved(true);
sc.setEJBRemoteBusinessObjectImpl(null);
for (RemoteBusinessIntfInfo next : remoteBusinessIntfInfo.values()) {
// disconnect from the ProtocolManager
// so that no remote invocations can get through
next.referenceFactory.destroyReference(ejbBusinessObjImpl.getStub(next.generatedRemoteIntf.getName()), ejbBusinessObjImpl.getEJBObject(next.generatedRemoteIntf.getName()));
}
}
}
if (isLocal) {
if (hasLocalHomeView) {
// disconnect the EJBLocalObject from the context
// and vice versa
EJBLocalObjectImpl localObjImpl = sc.getEJBLocalObjectImpl();
localObjImpl.clearContext();
localObjImpl.setRemoved(true);
sc.setEJBLocalObjectImpl(null);
}
if (hasLocalBusinessView) {
// disconnect the EJBLocalObject from the context
// and vice versa
EJBLocalObjectImpl localBusinessObjImpl = sc.getEJBLocalBusinessObjectImpl();
localBusinessObjImpl.clearContext();
localBusinessObjImpl.setRemoved(true);
sc.setEJBLocalBusinessObjectImpl(null);
}
if (hasOptionalLocalBusinessView) {
EJBLocalObjectImpl optionalLocalBusinessObjImpl = sc.getOptionalEJBLocalBusinessObjectImpl();
optionalLocalBusinessObjImpl.clearContext();
optionalLocalBusinessObjImpl.setRemoved(true);
sc.setOptionalEJBLocalBusinessObjectImpl(null);
}
}
destroyExtendedEMsForContext(sc);
// tell the TM to release resources held by the bean
transactionManager.componentDestroyed(sc);
}
}
use of javax.ejb.EJBObject in project Payara by payara.
the class AsynchronousTask method activateEJB.
// called from StatefulSessionStore
@Override
public void activateEJB(Object sessionKey, StatefulEJBContext sfsbCtx, Object cookie) {
SessionContextImpl context = (SessionContextImpl) sfsbCtx.getSessionContext();
logTraceInfo(context, "Attempting to activate");
EJBLocalRemoteObject ejbObject = (EJBLocalRemoteObject) cookie;
Object ejb = context.getEJB();
EjbInvocation ejbInv = createEjbInvocation(ejb, context);
invocationManager.preInvoke(ejbInv);
boolean needToDoPostInvokeTx = false;
try {
// we're sure that no concurrent thread can be using this bean
// so no need to synchronize.
// No need to call enlistComponentResources here because
// ejbActivate executes in unspecified tx context (spec 6.6.1)
// Set the timestamp here, else Recycler might remove this bean!
context.touch();
context.setContainer(this);
context.setState(BeanState.READY);
incrementMethodReadyStat();
context.setInstanceKey(sessionKey);
context.setExistsInStore(true);
context.initializeStatefulWriteLock();
if (ejbObject == null) {
// This MUST be a remote invocation
if (hasRemoteHomeView) {
createEJBObjectImpl(context);
} else {
createRemoteBusinessObjectImpl(context);
}
} else if (ejbObject instanceof EJBObjectImpl) {
EJBObjectImpl eo = (EJBObjectImpl) ejbObject;
ejbObject.setContext(context);
ejbObject.setKey(sessionKey);
byte[] sessionOID = uuidGenerator.keyToByteArray(sessionKey);
if (eo.isRemoteHomeView()) {
// introduce context and EJBObject to each other
context.setEJBObjectImpl(eo);
EJBObject ejbStub = (EJBObject) remoteHomeRefFactory.createRemoteReference(sessionOID);
eo.setStub(ejbStub);
context.setEJBStub(ejbStub);
if (hasRemoteBusinessView) {
createRemoteBusinessObjectImpl(context);
}
} else {
context.setEJBRemoteBusinessObjectImpl(eo);
for (RemoteBusinessIntfInfo next : remoteBusinessIntfInfo.values()) {
java.rmi.Remote stub = next.referenceFactory.createRemoteReference(sessionOID);
eo.setStub(next.generatedRemoteIntf.getName(), stub);
}
if (hasRemoteHomeView) {
createEJBObjectImpl(context);
}
}
if (isLocal) {
// create localObj too
if (hasLocalHomeView) {
createEJBLocalObjectImpl(context);
}
if (hasLocalBusinessView) {
createEJBLocalBusinessObjectImpl(context);
}
if (hasOptionalLocalBusinessView) {
createOptionalEJBLocalBusinessObjectImpl(context);
}
}
} else if (ejbObject instanceof EJBLocalObjectImpl) {
EJBLocalObjectImpl elo = (EJBLocalObjectImpl) ejbObject;
ejbObject.setContext(context);
ejbObject.setKey(sessionKey);
if (elo.isLocalHomeView()) {
context.setEJBLocalObjectImpl(elo);
if (hasLocalBusinessView) {
createEJBLocalBusinessObjectImpl(context);
}
if (hasOptionalLocalBusinessView) {
createOptionalEJBLocalBusinessObjectImpl(context);
}
} else if (elo.isOptionalLocalBusinessView()) {
context.setOptionalEJBLocalBusinessObjectImpl(elo);
if (hasLocalBusinessView) {
createEJBLocalBusinessObjectImpl(context);
}
if (hasLocalHomeView) {
createEJBLocalObjectImpl(context);
}
} else {
context.setEJBLocalBusinessObjectImpl(elo);
if (hasLocalHomeView) {
createEJBLocalObjectImpl(context);
}
if (hasOptionalLocalBusinessView) {
createOptionalEJBLocalBusinessObjectImpl(context);
}
}
if (hasRemoteHomeView) {
// create remote obj too
createEJBObjectImpl(context);
}
if (hasRemoteBusinessView) {
createRemoteBusinessObjectImpl(context);
}
}
// Now populate the EEM maps in this context
repopulateEEMMapsInContext(sessionKey, context);
try {
needToDoPostInvokeTx = callLifecycleCallbackInTxIfUsed(ejbInv, context, postActivateInvInfo, CallbackType.POST_ACTIVATE);
} catch (Throwable th) {
throw (EJBException) new EJBException("Error during activation" + sessionKey).initCause(th);
}
long now = System.currentTimeMillis();
try {
backingStore.updateTimestamp((Serializable) sessionKey, now);
context.setLastPersistedAt(now);
} catch (BackingStoreException sfsbEx) {
_logger.log(Level.WARNING, COULDNT_UPDATE_TIMESTAMP_FOR_EXCEPTION, new Object[] { sessionKey, sfsbEx });
_logger.log(Level.FINE, "Couldn't update timestamp for: " + sessionKey, sfsbEx);
}
logTraceInfo(context, "Successfully activated");
_logger.log(Level.FINE, () -> "Activated: " + sessionKey);
} catch (Exception ex) {
logTraceInfo(context, "Failed to activate");
_logger.log(Level.SEVERE, SFSB_ACTIVATION_ERROR, new Object[] { sessionKey, ex });
_logger.log(Level.SEVERE, "", ex);
throw new EJBException("Unable to activate EJB for key: " + sessionKey, ex);
} finally {
invocationManager.postInvoke(ejbInv);
completeLifecycleCallbackTxIfUsed(ejbInv, context, needToDoPostInvokeTx);
}
}
use of javax.ejb.EJBObject in project Payara by payara.
the class AsynchronousTask method createEJBObjectImpl.
// called from createEJBObject and activateEJB and createEJBLocalObjectImpl
private EJBObjectImpl createEJBObjectImpl(SessionContextImpl context) throws Exception {
if (context.getEJBObjectImpl() != null) {
return context.getEJBObjectImpl();
}
// create EJBObject and associate it with the key
Object sessionKey = context.getInstanceKey();
EJBObjectImpl ejbObjImpl = instantiateEJBObjectImpl(null, sessionKey);
// introduce context and EJBObject to each other
context.setEJBObjectImpl(ejbObjImpl);
ejbObjImpl.setContext(context);
// connect the EJBObject to the ProtocolManager
// (creates the client-side stub too)
byte[] sessionOID = uuidGenerator.keyToByteArray(sessionKey);
EJBObject ejbStub = (EJBObject) remoteHomeRefFactory.createRemoteReference(sessionOID);
context.setEJBStub(ejbStub);
ejbObjImpl.setStub(ejbStub);
if (hasRemoteBusinessView) {
createRemoteBusinessObjectImpl(context);
}
if (isLocal) {
if (hasLocalHomeView) {
// enable local home invocations too
createEJBLocalObjectImpl(context);
}
if (hasLocalBusinessView) {
// enable local business invocations too
createEJBLocalBusinessObjectImpl(context);
}
if (hasOptionalLocalBusinessView) {
createOptionalEJBLocalBusinessObjectImpl(context);
}
}
return ejbObjImpl;
}
use of javax.ejb.EJBObject in project wildfly by wildfly.
the class HandleDelegateImpl method readEJBObject.
public EJBObject readEJBObject(final ObjectInputStream oistream) throws IOException, ClassNotFoundException {
final Object ejbObject = proxy.read(oistream);
reconnect(ejbObject);
return (EJBObject) PortableRemoteObject.narrow(ejbObject, EJBObject.class);
}
Aggregations