Search in sources :

Example 46 with EJBObject

use of javax.ejb.EJBObject in project Payara by payara.

the class AsynchronousTask method createEJBObjectImpl.

/**
 * This is called from the generated "HelloEJBHomeImpl" create method
 * via EJBHomeImpl.createEJBObject.
 * Note: for stateful beans, the HelloEJBHomeImpl.create calls
 * ejbCreate on the new bean after createEJBObject() returns.
 * Return the EJBObject for the bean.
 */
@Override
protected EJBObjectImpl createEJBObjectImpl() throws CreateException, RemoteException {
    try {
        SessionContextImpl context = createBeanInstance();
        EJBObjectImpl ejbObjImpl = createEJBObjectImpl(context);
        afterInstanceCreation(context);
        return ejbObjImpl;
    } catch (Exception ex) {
        _logger.log(Level.WARNING, CREATE_EJBOBJECT_EXCEPTION, new Object[] { ejbDescriptor.getName(), ex });
        if (ex instanceof EJBException) {
            throw (EJBException) ex;
        }
        CreateException ce = new CreateException("ERROR creating stateful SessionBean");
        ce.initCause(ex);
        throw ce;
    }
}
Also used : EJBObject(javax.ejb.EJBObject) EJBException(javax.ejb.EJBException) CreateException(javax.ejb.CreateException) 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)

Example 47 with EJBObject

use of javax.ejb.EJBObject in project Payara by payara.

the class AsynchronousTask method passivateEJB.

// called asynchronously from the Recycler
@Override
public boolean passivateEJB(ComponentContext context) {
    SessionContextImpl sc = (SessionContextImpl) context;
    boolean success = false;
    try {
        if (ejbDescriptor.getApplication().getKeepStateResolved() == false) {
            if (containerState != CONTAINER_STARTED && containerState != CONTAINER_STOPPED) {
                _logger.log(Level.WARNING, PASSIVATE_EJB_RETURNING_BECAUSE_CONTAINER_STATE, containerState);
                return false;
            }
        }
        if (sc.getState() == BeanState.DESTROYED) {
            return false;
        }
        if (_logger.isLoggable(FINE)) {
            _logger.log(FINE, // 
            traceInfoPrefix + "Passivating context " + // 
            sc.getInstanceKey() + "; current-state = " + convertCtxStateToString(sc));
        }
        Object ejb = sc.getEJB();
        EjbInvocation ejbInv = createEjbInvocation(ejb, sc);
        invocationManager.preInvoke(ejbInv);
        success = false;
        boolean needToDoPostInvokeTx = false;
        boolean destroyBean = false;
        synchronized (sc) {
            try {
                // for this instance.
                if (!sc.canBePassivated()) {
                    return false;
                }
                Serializable instanceKey = (Serializable) sc.getInstanceKey();
                if (sessionBeanCache.eligibleForRemovalFromCache(sc, instanceKey)) {
                    // remove the EJB since removal-timeout has elapsed
                    sc.setState(BeanState.DESTROYED);
                    needToDoPostInvokeTx = callLifecycleCallbackInTxIfUsed(ejbInv, sc, preDestroyInvInfo, CallbackType.PRE_DESTROY);
                    sessionBeanCache.remove(instanceKey, sc.existsInStore());
                } else {
                    // passivate the EJB
                    sc.setState(BeanState.PASSIVATED);
                    decrementMethodReadyStat();
                    needToDoPostInvokeTx = callLifecycleCallbackInTxIfUsed(ejbInv, sc, prePassivateInvInfo, CallbackType.PRE_PASSIVATE);
                    sc.setLastPersistedAt(System.currentTimeMillis());
                    boolean saved = false;
                    try {
                        saved = sessionBeanCache.passivateEJB(sc, instanceKey);
                    } catch (EMNotSerializableException emNotSerEx) {
                        _logger.log(Level.WARNING, EXTENDED_EM_NOT_SERIALIZABLE, emNotSerEx);
                        _logger.log(Level.FINE, "Extended EM not serializable", emNotSerEx);
                        saved = false;
                    }
                    if (!saved) {
                        // TODO - add a flag to reactivate in the same tx
                        // Complete previous tx
                        completeLifecycleCallbackTxIfUsed(ejbInv, sc, needToDoPostInvokeTx);
                        needToDoPostInvokeTx = callLifecycleCallbackInTxIfUsed(ejbInv, sc, postActivateInvInfo, CallbackType.POST_ACTIVATE);
                        sc.setState(BeanState.READY);
                        incrementMethodReadyStat();
                        return false;
                    }
                }
                // V2: sfsbStoreMonitor.incrementPassivationCount(true);
                // 
                cacheProbeNotifier.ejbBeanPassivatedEvent(getContainerId(), containerInfo.appName, containerInfo.modName, containerInfo.ejbName, true);
                transactionManager.componentDestroyed(sc);
                decrementRefCountsForEEMs(sc);
                if (isRemote) {
                    if (hasRemoteHomeView) {
                        // disconnect the EJBObject from the EJB
                        EJBObjectImpl ejbObjImpl = sc.getEJBObjectImpl();
                        ejbObjImpl.clearContext();
                        sc.setEJBObjectImpl(null);
                        // disconnect the EJBObject from ProtocolManager
                        // so that no state is held by ProtocolManager
                        remoteHomeRefFactory.destroyReference(ejbObjImpl.getStub(), ejbObjImpl.getEJBObject());
                    }
                    if (hasRemoteBusinessView) {
                        // disconnect the EJBObject from the EJB
                        EJBObjectImpl ejbBusinessObjImpl = sc.getEJBRemoteBusinessObjectImpl();
                        ejbBusinessObjImpl.clearContext();
                        sc.setEJBRemoteBusinessObjectImpl(null);
                        for (RemoteBusinessIntfInfo next : remoteBusinessIntfInfo.values()) {
                            // 
                            next.referenceFactory.destroyReference(// 
                            ejbBusinessObjImpl.getStub(), ejbBusinessObjImpl.getEJBObject(next.generatedRemoteIntf.getName()));
                        }
                    }
                }
                if (isLocal) {
                    long version = sc.getVersion();
                    if (hasLocalHomeView) {
                        // disconnect the EJBLocalObject from the EJB
                        EJBLocalObjectImpl localObjImpl = sc.getEJBLocalObjectImpl();
                        localObjImpl.setSfsbClientVersion(version);
                        localObjImpl.clearContext();
                        sc.setEJBLocalObjectImpl(null);
                    }
                    if (hasLocalBusinessView) {
                        EJBLocalObjectImpl localBusinessObjImpl = sc.getEJBLocalBusinessObjectImpl();
                        localBusinessObjImpl.setSfsbClientVersion(version);
                        localBusinessObjImpl.clearContext();
                        sc.setEJBLocalBusinessObjectImpl(null);
                    }
                    if (hasOptionalLocalBusinessView) {
                        EJBLocalObjectImpl optLocalBusObjImpl = sc.getOptionalEJBLocalBusinessObjectImpl();
                        optLocalBusObjImpl.setSfsbClientVersion(version);
                        optLocalBusObjImpl.clearContext();
                        sc.setOptionalEJBLocalBusinessObjectImpl(null);
                    }
                }
                logTraceInfo(sc, "Successfully passivated");
            } catch (NotSerializableException nsEx) {
                // V2: sfsbStoreMonitor.incrementPassivationCount(false);
                // 
                cacheProbeNotifier.ejbBeanPassivatedEvent(// 
                getContainerId(), containerInfo.appName, containerInfo.modName, containerInfo.ejbName, false);
                _logger.log(Level.WARNING, ERROR_DURING_PASSIVATION, new Object[] { sc, nsEx });
                _logger.log(Level.FINE, "sfsb passivation error", nsEx);
                // Error during passivate, so discard bean: EJB2.0 18.3.3
                destroyBean = true;
            } catch (Throwable ex) {
                // V2: sfsbStoreMonitor.incrementPassivationCount(false);
                // 
                cacheProbeNotifier.ejbBeanPassivatedEvent(// 
                getContainerId(), containerInfo.appName, containerInfo.modName, containerInfo.ejbName, false);
                _logger.log(Level.WARNING, PASSIVATION_ERROR_1PARAM, new Object[] { ejbDescriptor.getName() + " <==> " + sc });
                _logger.log(Level.WARNING, SFSB_PASSIVATION_ERROR_1PARAM, new Object[] { sc.getInstanceKey(), ex });
                // Error during passivate, so discard bean: EJB2.0 18.3.3
                destroyBean = true;
            } finally {
                invocationManager.postInvoke(ejbInv);
                completeLifecycleCallbackTxIfUsed(ejbInv, sc, needToDoPostInvokeTx);
                if (destroyBean) {
                    try {
                        forceDestroyBean(sc);
                    } catch (Exception e) {
                        _logger.log(Level.FINE, "error destroying bean", e);
                    }
                }
            }
        }
    // synchronized
    } catch (Exception ex) {
        _logger.log(Level.WARNING, PASSIVATION_ERROR_1PARAM, new Object[] { ejbDescriptor.getName(), ex });
    }
    return success;
}
Also used : Serializable(java.io.Serializable) IndirectlySerializable(com.sun.enterprise.container.common.spi.util.IndirectlySerializable) 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) NotSerializableException(java.io.NotSerializableException) EJBObject(javax.ejb.EJBObject)

Example 48 with EJBObject

use of javax.ejb.EJBObject in project Payara by payara.

the class AsynchronousTask method createRemoteBusinessObjectImpl.

private EJBObjectImpl createRemoteBusinessObjectImpl(SessionContextImpl context) throws Exception {
    if (context.getEJBRemoteBusinessObjectImpl() != null) {
        return context.getEJBRemoteBusinessObjectImpl();
    }
    // create EJBObject
    EJBObjectImpl ejbBusinessObjImpl = instantiateRemoteBusinessObjectImpl();
    context.setEJBRemoteBusinessObjectImpl(ejbBusinessObjImpl);
    ejbBusinessObjImpl.setContext(context);
    Object sessionKey = context.getInstanceKey();
    ejbBusinessObjImpl.setKey(sessionKey);
    // connect the Remote object to the ProtocolManager
    // (creates the client-side stub too)
    byte[] sessionOID = uuidGenerator.keyToByteArray(sessionKey);
    for (RemoteBusinessIntfInfo next : remoteBusinessIntfInfo.values()) {
        java.rmi.Remote stub = next.referenceFactory.createRemoteReference(sessionOID);
        ejbBusinessObjImpl.setStub(next.generatedRemoteIntf.getName(), stub);
    }
    if (hasRemoteHomeView) {
        createEJBObjectImpl(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 ejbBusinessObjImpl;
}
Also used : EJBObject(javax.ejb.EJBObject)

Example 49 with EJBObject

use of javax.ejb.EJBObject in project Payara by payara.

the class JDOEJB11HelperImpl method convertPCToEJBObject.

/**
 * Converts persistence-capable instance to EJBObject.
 * @param pc the persistence-capable instance to be converted as an Object.
 * @param pm the associated instance of PersistenceManager.
 * @return instance of EJBObject.
 */
public EJBObject convertPCToEJBObject(Object pc, PersistenceManager pm) {
    if (pc == null)
        return null;
    Object jdoObjectId = pm.getObjectId(pc);
    Object key = convertObjectIdToPrimaryKey(jdoObjectId);
    try {
        return CMPHelper.getEJBObject(key, getContainer());
    } catch (Exception ex) {
        EJBException e = new EJBException(I18NHelper.getMessage(messages, "EXC_ConvertPCToEJBObject", key.toString()), // NOI18N
        ex);
        // NOI18N
        logger.throwing("JDOEJB11HelperImpl", "convertPCToEJBObject", e);
        throw e;
    }
}
Also used : EJBObject(javax.ejb.EJBObject) EJBException(javax.ejb.EJBException) JDOUserException(com.sun.jdo.api.persistence.support.JDOUserException) JDOFatalDataStoreException(com.sun.jdo.api.persistence.support.JDOFatalDataStoreException) JDOObjectNotFoundException(com.sun.jdo.api.persistence.support.JDOObjectNotFoundException) EJBException(javax.ejb.EJBException) JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException)

Example 50 with EJBObject

use of javax.ejb.EJBObject in project Payara by payara.

the class JDOEJB11HelperImpl method convertCollectionEJBObjectToPC.

/**
 * Converts Collection of EJBObjects to a Collection of
 * persistence-capable instances.
 * @param coll the Collection of EJBObject instances to be converted.
 * @param pm the associated instance of PersistenceManager.
 * @param validate true if the existence of the instances is to be validated.
 * @return Collection of persistence-capable instance.
 * @throws IllegalArgumentException if validate is true and at least one instance does
 * not exist in the database or is deleted.
 */
public Collection convertCollectionEJBObjectToPC(Collection coll, PersistenceManager pm, boolean validate) {
    Collection rc = new java.util.ArrayList();
    Object o = null;
    for (java.util.Iterator it = coll.iterator(); it.hasNext(); ) {
        o = convertEJBObjectToPC((EJBObject) it.next(), pm, validate);
        if (logger.isLoggable(Logger.FINEST)) {
            logger.finest(// NOI18N
            "\n---JDOEJB11HelperImpl.convertCollectionEJBObjectToPC() adding: " + o);
        }
        rc.add(o);
    }
    return rc;
}
Also used : EJBObject(javax.ejb.EJBObject) Collection(java.util.Collection) EJBObject(javax.ejb.EJBObject)

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