}
public Object invoke(Invocation invocation) throws Throwable
{
EJBContainerInvocation<StatelessContainer, StatelessBeanContext> ejb = (EJBContainerInvocation<StatelessContainer, StatelessBeanContext>) invocation;
EJBContainer container = getEJBContainer(invocation);
Pool pool = container.getPool();
BeanContext<?> ctx = pool.get();
assert ctx != null : "pool returned null instance";
//ejb.setTargetObject(ctx.getInstance());
ejb.setBeanContext(ctx);
container.pushContext(ctx);
boolean discard = false;
try
{
return ejb.invokeNext();
}
catch (Exception ex)
{
discard = (ex instanceof EJBException) ||
((ex instanceof RuntimeException || ex instanceof RemoteException) && !StatefulRemoveInterceptor.isApplicationException(ex, (MethodInvocation)invocation));
throw ex;
}
catch (final Throwable t)
{
discard = true;
throw t;
}
finally
{
container.popContext();
//ejb.setTargetObject(null);
ejb.setBeanContext(null);
if (discard) pool.discard(ctx);
else pool.release(ctx);
}