final SessionID sessionID = statefulEJBLocator.getSessionId();
return statefulSessionComponent.getCache().getWeakAffinity(sessionID);
}
private Object invokeMethod(final short invocationId, 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.putPrivateData(Component.class, componentView.getComponent());
interceptorContext.putPrivateData(ComponentView.class, componentView);
interceptorContext.putPrivateData(InvocationType.class, InvocationType.REMOTE);
// setup the contextData on the (spec specified) InvocationContext
final Map<String, Object> invocationContextData = new HashMap<String, Object>();
interceptorContext.setContextData(invocationContextData);
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();
// these are private to JBoss EJB implementation and not meant to be visible to the
// application, so add these attachments to the privateData of the InterceptorContext
if (EJBClientInvocationContext.PRIVATE_ATTACHMENTS_KEY.equals(key)) {
final Map<Object, Object> privateAttachments = (Map<Object, Object>) value;
for (final Map.Entry<Object, Object> privateAttachment : privateAttachments.entrySet()) {
interceptorContext.putPrivateData(privateAttachment.getKey(), privateAttachment.getValue());
}
} else {
// add it to the InvocationContext which will be visible to the target bean and the
// application specific interceptors
invocationContextData.put(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)) {
EjbLogger.ROOT_LOGGER.asyncMethodSupportedOnlyForSessionBeans(component.getComponentClass(), method);
// just invoke normally
return componentView.invoke(interceptorContext);
}
final CancellationFlag asyncInvocationCancellationFlag = new CancellationFlag();
interceptorContext.putPrivateData(CancellationFlag.class, asyncInvocationCancellationFlag);
// keep track of the cancellation flag for this invocation
this.remoteAsyncInvocationCancelStatus.registerAsyncInvocation(invocationId, asyncInvocationCancellationFlag);
try {
final Object result = componentView.invoke(interceptorContext);
return result == null ? null : ((Future) result).get();