if (ejbContainer instanceof ServiceContainer || ejbContainer instanceof MessagingContainer)
{
return invocation.invokeNext();
}
final SessionSpecContainer sessionContainer = (SessionSpecContainer) EJBContainer.getEJBContainer(advisor);
final AsyncInvocationMap currentInvocations = sessionContainer.getCurrentAsyncInvocations();
// Put the current ID into the Map
if (id != null)
{
currentInvocations.put(id, false);
}
// Mark the Thread
CurrentAsyncInvocation.markCurrentInvocationOnThread(id);
// Now invoke
Object returnValue;
try
{
returnValue = invocation.invokeNext();
// If this is a Future
if (returnValue instanceof Future)
{
// Cast
final Future<?> future = (Future<?>) returnValue;
// If not Serializable
if (!(returnValue instanceof Serializable))
{
// Make it so
returnValue = new SerializableFuture<Object>(future.get());
}
}
return returnValue;
}
catch(final Throwable t)
{
// Only propagate this back if the return type is not void, else swallow the exception
final MethodInvocation mi = (MethodInvocation) invocation;
final Method m = mi.getActualMethod();
final Class<?> returnType = m.getReturnType();
if (void.class.equals(returnType))
{
log.debug("Received Throwable on @Asynchronous invocation " + m + ", not returning to the client:", t);
return null;
}
throw t;
}
finally
{
// Remove the invocation from the Map of those currently-executed
if (id != null)
{
currentInvocations.remove(id);
}
// Unmark the Thread
CurrentAsyncInvocation.unmarkCurrentInvocationFromThread();
}