Search in sources :

Example 21 with NoSuchObjectException

use of java.rmi.NoSuchObjectException in project tomee by apache.

the class ManagedContainer method obtainInstance.

private Instance obtainInstance(final Object primaryKey, final ThreadContext callContext) throws OpenEJBException {
    if (primaryKey == null) {
        throw new SystemException(new NullPointerException("Cannot obtain an instance of the stateful session bean with a null session id"));
    }
    final Transaction currentTransaction = getTransaction(callContext);
    // Find the instance
    Instance instance = checkedOutInstances.get(primaryKey);
    if (instance == null) {
        try {
            instance = cache.checkOut(primaryKey);
        } catch (final OpenEJBException e) {
            throw e;
        } catch (final Exception e) {
            throw new SystemException("Unexpected load exception", e);
        }
        // Did we find the instance?
        if (instance == null) {
            throw new InvalidateReferenceException(new NoSuchObjectException("Not Found"));
        }
        // remember instance until it is returned to the cache
        checkedOutInstances.put(primaryKey, instance);
    }
    synchronized (this) {
        if (instance.isInUse()) {
            // the bean is already being invoked; the only reentrant/concurrent operations allowed are Session synchronization callbacks
            final Operation currentOperation = callContext.getCurrentOperation();
            if (currentOperation != Operation.AFTER_COMPLETION && currentOperation != Operation.BEFORE_COMPLETION) {
                throw new ApplicationException(new RemoteException("Concurrent calls not allowed."));
            }
        }
        if (instance.getTransaction() != null) {
            if (!instance.getTransaction().equals(currentTransaction) && !instance.getLock().tryLock()) {
                throw new ApplicationException(new RemoteException("Instance is in a transaction and cannot be invoked outside that transaction.  See EJB 3.0 Section 4.4.4"));
            }
        } else {
            instance.setTransaction(currentTransaction);
        }
        // Mark the instance in use so we can detect reentrant calls
        instance.setInUse(true);
        return instance;
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) InvalidateReferenceException(org.apache.openejb.InvalidateReferenceException) ApplicationException(org.apache.openejb.ApplicationException) SystemException(org.apache.openejb.SystemException) Transaction(javax.transaction.Transaction) SuspendedTransaction(org.apache.openejb.core.transaction.BeanTransactionPolicy.SuspendedTransaction) EjbUserTransaction(org.apache.openejb.core.transaction.EjbUserTransaction) SystemInstance(org.apache.openejb.loader.SystemInstance) NoSuchObjectException(java.rmi.NoSuchObjectException) Operation(org.apache.openejb.core.Operation) RemoteException(java.rmi.RemoteException) NamingException(javax.naming.NamingException) InvalidateReferenceException(org.apache.openejb.InvalidateReferenceException) EJBAccessException(javax.ejb.EJBAccessException) RemoveException(javax.ejb.RemoveException) OpenEJBException(org.apache.openejb.OpenEJBException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) SystemException(org.apache.openejb.SystemException) NoSuchObjectException(java.rmi.NoSuchObjectException) EntityManagerAlreadyRegisteredException(org.apache.openejb.persistence.EntityManagerAlreadyRegisteredException) ApplicationException(org.apache.openejb.ApplicationException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

Example 22 with NoSuchObjectException

use of java.rmi.NoSuchObjectException in project tomee by apache.

the class CmpContainer method removeEJBObject.

private void removeEJBObject(final Method callMethod, final ThreadContext callContext, final InterfaceType interfaceType) throws OpenEJBException {
    final BeanContext beanContext = callContext.getBeanContext();
    final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);
    try {
        final EntityBean entityBean = (EntityBean) cmpEngine.loadBean(callContext, callContext.getPrimaryKey());
        if (entityBean == null) {
            throw new NoSuchObjectException(callContext.getBeanContext().getDeploymentID() + " " + callContext.getPrimaryKey());
        }
        ejbRemove(entityBean);
        cmpEngine.removeBean(callContext);
    } catch (final NoSuchObjectException e) {
        handleApplicationException(txPolicy, e, false);
    } catch (final Throwable e) {
        // handle reflection exception
        handleSystemException(txPolicy, e, callContext);
    } finally {
        afterInvoke(txPolicy, callContext);
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) EntityBean(javax.ejb.EntityBean) TransactionPolicy(org.apache.openejb.core.transaction.TransactionPolicy) EjbTransactionUtil.createTransactionPolicy(org.apache.openejb.core.transaction.EjbTransactionUtil.createTransactionPolicy) NoSuchObjectException(java.rmi.NoSuchObjectException)

Aggregations

NoSuchObjectException (java.rmi.NoSuchObjectException)22 Test (org.junit.Test)8 PortableRemoteObject (javax.rmi.PortableRemoteObject)7 RemoteException (java.rmi.RemoteException)5 InitialContext (javax.naming.InitialContext)5 IOException (java.io.IOException)4 Properties (java.util.Properties)4 EJBObject (javax.ejb.EJBObject)4 EJBAccessException (javax.ejb.EJBAccessException)3 ApplicationException (org.apache.openejb.ApplicationException)3 BeanContext (org.apache.openejb.BeanContext)3 OpenEJBException (org.apache.openejb.OpenEJBException)3 SystemException (org.apache.openejb.SystemException)3 EjbTransactionUtil.createTransactionPolicy (org.apache.openejb.core.transaction.EjbTransactionUtil.createTransactionPolicy)3 TransactionPolicy (org.apache.openejb.core.transaction.TransactionPolicy)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Remote (java.rmi.Remote)2 ActivationException (java.rmi.activation.ActivationException)2 EJBException (javax.ejb.EJBException)2 EntityBean (javax.ejb.EntityBean)2