Search in sources :

Example 96 with EJBObject

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());
    }
}
Also used : EJBObject(javax.ejb.EJBObject)

Example 97 with EJBObject

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);
    }
}
Also used : JavaEETransaction(com.sun.enterprise.transaction.api.JavaEETransaction) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) EJBObject(javax.ejb.EJBObject) EJBException(javax.ejb.EJBException)

Example 98 with EJBObject

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);
    }
}
Also used : BackingStoreException(org.glassfish.ha.store.api.BackingStoreException) IllegalLoopbackException(javax.ejb.IllegalLoopbackException) ConcurrentAccessException(javax.ejb.ConcurrentAccessException) RemoveException(javax.ejb.RemoveException) ConcurrentAccessTimeoutException(javax.ejb.ConcurrentAccessTimeoutException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) BackingStoreException(org.glassfish.ha.store.api.BackingStoreException) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) SystemException(javax.transaction.SystemException) CreateException(javax.ejb.CreateException) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) EjbInvocation(com.sun.ejb.EjbInvocation) EJBObject(javax.ejb.EJBObject) EJBObject(javax.ejb.EJBObject) EJBException(javax.ejb.EJBException)

Example 99 with EJBObject

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;
}
Also used : EJBObject(javax.ejb.EJBObject) EJBObject(javax.ejb.EJBObject)

Example 100 with EJBObject

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);
}
Also used : EJBObject(javax.ejb.EJBObject) EJBObject(javax.ejb.EJBObject) PortableRemoteObject(javax.rmi.PortableRemoteObject)

Aggregations

EJBObject (javax.ejb.EJBObject)104 RemoteException (java.rmi.RemoteException)41 Handle (javax.ejb.Handle)28 ObjectGraph (org.apache.openejb.test.object.ObjectGraph)12 EJBLocalObject (javax.ejb.EJBLocalObject)8 EJBException (javax.ejb.EJBException)7 EncCmpObject (org.apache.openejb.test.entity.cmp.EncCmpObject)7 RmiIiopCmpObject (org.apache.openejb.test.entity.cmp.RmiIiopCmpObject)7 MarshalledObject (java.rmi.MarshalledObject)6 EncCmpHome (org.apache.openejb.test.entity.cmp.EncCmpHome)6 Test (org.junit.Test)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 NoSuchObjectException (java.rmi.NoSuchObjectException)4 RemoveException (javax.ejb.RemoveException)4 SystemException (javax.transaction.SystemException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 NotSerializableException (java.io.NotSerializableException)3 ObjectInputStream (java.io.ObjectInputStream)3