final SessionID sessionID = statefulEJBLocator.getSessionId();
return statefulSessionComponent.getCache().getWeakAffinity(sessionID);
}
private Object invokeMethod(final ComponentView componentView, final Method method, final Object[] args, final EJBLocator ejbLocator, final Map<String, Object> 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);
interceptorContext.putPrivateData(InvocationType.class, InvocationType.REMOTE);
if (attachments != null) {
// attach the attachments which were passed from the remote client
for (final Map.Entry<String, Object> attachment : attachments.entrySet()) {
if (attachment == null) {
continue;
}
final String key = attachment.getKey();
final Object value = attachment.getValue();
// add it to the context
interceptorContext.putPrivateData(key, value);
}
}
// add the session id to the interceptor context, if it's a stateful ejb locator
if (ejbLocator instanceof StatefulEJBLocator) {
interceptorContext.putPrivateData(SessionID.class, ((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);