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