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) {
}
}
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());
}
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;
}
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;
}
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;
}
Aggregations