EJBContainerInvocation ejb = (EJBContainerInvocation) invocation;
EJBContainer container = (EJBContainer)ejb.getAdvisor();
Pool pool = container.getPool();
BeanContext ctx = pool.get();
ejb.setTargetObject(ctx.getInstance());
ejb.setBeanContext(ctx);
boolean discard = false;
try
{
return ejb.invokeNext();
}
catch (Exception ex)
{
discard = (ex instanceof EJBException) ||
((ex instanceof RuntimeException || ex instanceof RemoteException) && !StatefulInstanceInterceptor.isApplicationException(ex.getClass(), container));
throw ex;
}
finally
{
ejb.setTargetObject(null);
ejb.setBeanContext(null);
if (discard) pool.discard(ctx);
else pool.release(ctx);
}