Search in sources :

Example 6 with NoSuchObjectException

use of java.rmi.NoSuchObjectException in project wildfly by wildfly.

the class AnnotationHomeTestCase method testStatefulLocalHome.

@Test
public void testStatefulLocalHome() throws Exception {
    final String message = "Bean Message";
    final SimpleStatefulHome home = (SimpleStatefulHome) iniCtx.lookup("java:module/SimpleStatefulBean!" + SimpleStatefulHome.class.getName());
    SimpleInterface ejbInstance = home.createSimple(message);
    Assert.assertEquals(message, ejbInstance.sayHello());
    ejbInstance = home.createComplex("hello", "world");
    Assert.assertEquals("hello world", ejbInstance.sayHello());
    ejbInstance.remove();
    try {
        ejbInstance.sayHello();
        fail("Expected bean to be removed");
    } catch (NoSuchObjectException expected) {
    }
}
Also used : NoSuchObjectException(java.rmi.NoSuchObjectException) SimpleInterface(org.jboss.as.test.integration.ejb.home.remotehome.SimpleInterface) SimpleStatefulHome(org.jboss.as.test.integration.ejb.home.remotehome.SimpleStatefulHome) Test(org.junit.Test)

Example 7 with NoSuchObjectException

use of java.rmi.NoSuchObjectException in project wildfly by wildfly.

the class RemoveMethodUnitTestCase method testEjbRemoveInvokedOnRemoval.

/**
     * Test that ejbRemove() method was invoked on the bean when the remove() is invoked on the EJBObject
     * of an EJB2.x view of a bean
     *
     * @throws Exception
     */
@Test
public void testEjbRemoveInvokedOnRemoval() throws Exception {
    // Obtain stub
    Object obj = ctx.lookup("java:app/" + DD_BASED_MODULE_NAME + "/" + Ejb21ViewDDBean.class.getSimpleName() + "!" + Ejb21ViewHome.class.getName());
    Ejb21ViewHome home = (Ejb21ViewHome) PortableRemoteObject.narrow(obj, Ejb21ViewHome.class);
    Ejb21View bean = home.create();
    // Ensure EJBObject
    Assert.assertTrue(bean instanceof EJBObject);
    String result = bean.test();
    bean.remove();
    try {
        bean.test();
        Assert.fail("Invocation on a removed bean was expected to fail");
    } catch (NoSuchObjectException e) {
    // expected
    }
    final RemoveMethodInvocationTracker ejbRemoveMethodInvocationTracker = (RemoveMethodInvocationTracker) ctx.lookup("java:app/" + ANNOTATION_BASED_MODULE_NAME + "/" + RemoveMethodInvocationTrackerBean.class.getSimpleName() + "!" + RemoveMethodInvocationTracker.class.getName());
    Assert.assertTrue("ejbRemove() method was not invoked after bean removal", ejbRemoveMethodInvocationTracker.wasEjbRemoveCallbackInvoked());
}
Also used : EJBObject(javax.ejb.EJBObject) EJBObject(javax.ejb.EJBObject) PortableRemoteObject(javax.rmi.PortableRemoteObject) NoSuchObjectException(java.rmi.NoSuchObjectException) Test(org.junit.Test)

Example 8 with NoSuchObjectException

use of java.rmi.NoSuchObjectException in project jdk8u_jdk by JetBrains.

the class ActivationGroupImpl method inactiveObject.

/**
    * The group's <code>inactiveObject</code> method is called
    * indirectly via a call to the <code>Activatable.inactive</code>
    * method. A remote object implementation must call
    * <code>Activatable</code>'s <code>inactive</code> method when
    * that object deactivates (the object deems that it is no longer
    * active). If the object does not call
    * <code>Activatable.inactive</code> when it deactivates, the
    * object will never be garbage collected since the group keeps
    * strong references to the objects it creates. <p>
    *
    * The group's <code>inactiveObject</code> method
    * unexports the remote object from the RMI runtime so that the
    * object can no longer receive incoming RMI calls. This call will
    * only succeed if the object has no pending/executing calls. If
    * the object does have pending/executing RMI calls, then false
    * will be returned.
    *
    * If the object has no pending/executing calls, the object is
    * removed from the RMI runtime and the group informs its
    * <code>ActivationMonitor</code> (via the monitor's
    * <code>inactiveObject</code> method) that the remote object is
    * not currently active so that the remote object will be
    * re-activated by the activator upon a subsequent activation
    * request.
    *
    * @param id the object's activation identifier
    * @returns true if the operation succeeds (the operation will
    * succeed if the object in currently known to be active and is
    * either already unexported or is currently exported and has no
    * pending/executing calls); false is returned if the object has
    * pending/executing calls in which case it cannot be deactivated
    * @exception UnknownObjectException if object is unknown (may already
    * be inactive)
    * @exception RemoteException if call informing monitor fails
    */
public boolean inactiveObject(ActivationID id) throws ActivationException, UnknownObjectException, RemoteException {
    try {
        acquireLock(id);
        synchronized (this) {
            if (groupInactive == true)
                throw new ActivationException("group is inactive");
        }
        ActiveEntry entry = active.get(id);
        if (entry == null) {
            // REMIND: should this be silent?
            throw new UnknownObjectException("object not active");
        }
        try {
            if (Activatable.unexportObject(entry.impl, false) == false)
                return false;
        } catch (NoSuchObjectException allowUnexportedObjects) {
        }
        try {
            super.inactiveObject(id);
        } catch (UnknownObjectException allowUnregisteredObjects) {
        }
        active.remove(id);
    } finally {
        releaseLock(id);
        checkInactiveGroup();
    }
    return true;
}
Also used : ActivationException(java.rmi.activation.ActivationException) NoSuchObjectException(java.rmi.NoSuchObjectException) UnknownObjectException(java.rmi.activation.UnknownObjectException)

Example 9 with NoSuchObjectException

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

the class CmpContainer method businessMethod.

private Object businessMethod(final Method callMethod, final Method runMethod, final Object[] args, final ThreadContext callContext, final InterfaceType interfaceType) throws OpenEJBException {
    final BeanContext beanContext = callContext.getBeanContext();
    final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);
    final EntityBean bean;
    Object returnValue = null;
    entrancyTracker.enter(beanContext, callContext.getPrimaryKey());
    try {
        bean = (EntityBean) cmpEngine.loadBean(callContext, callContext.getPrimaryKey());
        if (bean == null) {
            throw new NoSuchObjectException(beanContext.getDeploymentID() + " : " + callContext.getPrimaryKey());
        }
        returnValue = runMethod.invoke(bean, args);
        // when there is not transaction, merge the data from the bean back into the cmp engine
        cmpEngine.storeBeanIfNoTx(callContext, bean);
    } catch (final NoSuchObjectException e) {
        handleApplicationException(txPolicy, e, false);
    } catch (Throwable e) {
        if (e instanceof InvocationTargetException) {
            e = ((InvocationTargetException) e).getTargetException();
        }
        final ExceptionType type = callContext.getBeanContext().getExceptionType(e);
        if (type == ExceptionType.SYSTEM) {
            /* System Exception ****************************/
            handleSystemException(txPolicy, e, callContext);
        } else {
            /* Application Exception ***********************/
            handleApplicationException(txPolicy, e, type == ExceptionType.APPLICATION_ROLLBACK);
        }
    } finally {
        entrancyTracker.exit(beanContext, callContext.getPrimaryKey());
        afterInvoke(txPolicy, callContext);
    }
    return returnValue;
}
Also used : BeanContext(org.apache.openejb.BeanContext) ExceptionType(org.apache.openejb.core.ExceptionType) EntityBean(javax.ejb.EntityBean) TransactionPolicy(org.apache.openejb.core.transaction.TransactionPolicy) EjbTransactionUtil.createTransactionPolicy(org.apache.openejb.core.transaction.EjbTransactionUtil.createTransactionPolicy) EJBLocalObject(javax.ejb.EJBLocalObject) EJBObject(javax.ejb.EJBObject) NoSuchObjectException(java.rmi.NoSuchObjectException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 10 with NoSuchObjectException

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

the class StatefulContainer method obtainInstance.

@SuppressWarnings("LockAcquiredButNotSafelyReleased")
private Instance obtainInstance(final Object primaryKey, final ThreadContext callContext, final Method callMethod, final boolean checkOutIfNecessary) 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;
    synchronized (this) {
        instance = checkedOutInstances.get(primaryKey);
        if (instance == null) {
            // no need to check for extended persistence contexts it shouldn't happen
            try {
                instance = cache.checkOut(primaryKey, checkOutIfNecessary);
            } 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);
        }
    }
    final Duration accessTimeout = getAccessTimeout(instance.beanContext, callMethod);
    final LockFactory.StatefulLock currLock = instance.getLock();
    final boolean lockAcquired;
    if (accessTimeout == null || accessTimeout.getTime() < 0) {
        // wait indefinitely for a lock
        currLock.lock();
        lockAcquired = true;
    } else if (accessTimeout.getTime() == 0) {
        // concurrent calls are not allowed, lock only once
        lockAcquired = currLock.tryLock();
    } else {
        // try to get a lock within the specified period.
        try {
            lockAcquired = currLock.tryLock(accessTimeout.getTime(), accessTimeout.getUnit());
        } catch (final InterruptedException e) {
            throw new ApplicationException("Unable to get lock.", e);
        }
    }
    // Did we acquire the lock to the current execution?
    if (!lockAcquired) {
        throw new ApplicationException(new ConcurrentAccessTimeoutException("Unable to get lock."));
    }
    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) SystemInstance(org.apache.openejb.loader.SystemInstance) Duration(org.apache.openejb.util.Duration) LoginException(javax.security.auth.login.LoginException) NamingException(javax.naming.NamingException) InvalidateReferenceException(org.apache.openejb.InvalidateReferenceException) EJBAccessException(javax.ejb.EJBAccessException) RemoveException(javax.ejb.RemoveException) ConcurrentAccessTimeoutException(javax.ejb.ConcurrentAccessTimeoutException) 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) 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) NoSuchObjectException(java.rmi.NoSuchObjectException) ConcurrentAccessTimeoutException(javax.ejb.ConcurrentAccessTimeoutException) RemoteException(java.rmi.RemoteException)

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