}
}
private Object invokeMethod(final ComponentView componentView, final Method method, final Object[] args, final EJBLocator ejbLocator, final RemotingAttachments attachments) throws Throwable {
final InterceptorContext interceptorContext = new InterceptorContext();
interceptorContext.setParameters(args);
interceptorContext.setMethod(method);
interceptorContext.setContextData(new HashMap<String, Object>());
interceptorContext.putPrivateData(Component.class, componentView.getComponent());
interceptorContext.putPrivateData(ComponentView.class, componentView);
if (attachments != null) {
// attach the RemotingAttachments
interceptorContext.putPrivateData(RemotingAttachments.class, attachments);
}
// add the session id to the interceptor context, if it's a stateful ejb locator
if (ejbLocator instanceof StatefulEJBLocator) {
interceptorContext.putPrivateData(SessionID.SESSION_ID_KEY, ((StatefulEJBLocator) ejbLocator).getSessionId());
} else if (ejbLocator instanceof EntityEJBLocator) {
final Object primaryKey = ((EntityEJBLocator) ejbLocator).getPrimaryKey();
interceptorContext.putPrivateData(EntityBeanComponent.PRIMARY_KEY_CONTEXT_KEY, primaryKey);
}
if (componentView.isAsynchronous(method)) {
final Component component = componentView.getComponent();
if (!(component instanceof SessionBeanComponent)) {
logger.warn("Asynchronous invocations are only supported on session beans. Bean class " + component.getComponentClass()
+ " is not a session bean, invocation on method " + method + " will have no asynchronous semantics");
// just invoke normally
return componentView.invoke(interceptorContext);
}
// it's really a async method invocation on a session bean. So treat it accordingly
final SessionBeanComponent sessionBeanComponent = (SessionBeanComponent) componentView.getComponent();
final CancellationFlag cancellationFlag = new CancellationFlag();
// add the cancellation flag to the interceptor context
interceptorContext.putPrivateData(CancellationFlag.class, cancellationFlag);
final AsyncInvocationTask asyncInvocationTask = new AsyncInvocationTask(cancellationFlag) {
@Override
protected Object runInvocation() throws Exception {
return componentView.invoke(interceptorContext);