if (!ejbDeploymentInformation.getViewNames().contains(viewClassName)) {
this.writeNoSuchEJBFailureMessage(channel, invocationId, appName, moduleName, distinctName, beanName, viewClassName);
return;
}
// TODO: Add a check for remote view
final ComponentView componentView = ejbDeploymentInformation.getView(viewClassName);
final Method invokedMethod = this.findMethod(componentView, methodName, methodParamTypes);
if (invokedMethod == null) {
this.writeNoSuchEJBMethodFailureMessage(channel, invocationId, appName, moduleName, distinctName, beanName, viewClassName, methodName, methodParamTypes);
return;
}
final Object[] methodParams = new Object[methodParamTypes.length];
// un-marshall the method arguments
if (methodParamTypes.length > 0) {
for (int i = 0; i < methodParamTypes.length; i++) {
try {
methodParams[i] = unmarshaller.readObject();
} catch (ClassNotFoundException cnfe) {
// TODO: Write out invocation failure to channel outstream
throw new RuntimeException(cnfe);
}
}
}
// read the attachments
final Map<String, Object> attachments;
try {
attachments = this.readAttachments(unmarshaller);
} catch (ClassNotFoundException cnfe) {
// TODO: Write out invocation failure to channel outstream
throw new RuntimeException(cnfe);
}
// done with unmarshalling
unmarshaller.finish();
runnable = new Runnable() {
@Override
public void run() {
// check if it's async. If yes, then notify the client that's it's async method (so that
// it can unblock if necessary)
if (componentView.isAsynchronous(invokedMethod)) {
try {
MethodInvocationMessageHandler.this.writeAsyncMethodNotification(channel, invocationId);
} catch (Throwable t) {
// catch Throwable, so that we don't skip invoking the method, just because we
// failed to send a notification to the client that the method is an async method
logger.warn("Method " + invokedMethod + " was a async method but the client could not be informed about the same. This will mean that the client might block till the method completes", t);
}
}
// invoke the method
Object result = null;
RemotingContext.setConnection(channel.getConnection());
try {
result = invokeMethod(componentView, invokedMethod, methodParams, locator, attachments);
} catch (Throwable throwable) {
try {
// write out the failure
MethodInvocationMessageHandler.this.writeException(channel, MethodInvocationMessageHandler.this.marshallerFactory, invocationId, throwable, attachments);
} catch (IOException ioe) {
// we couldn't write out a method invocation failure message. So let's atleast log the
// actual method invocation exception, for debugging/reference
logger.error("Error invoking method " + invokedMethod + " on bean named " + beanName
+ " for appname " + appName + " modulename " + moduleName + " distinctname " + distinctName, throwable);
// now log why we couldn't send back the method invocation failure message
logger.error("Could not write method invocation failure for method " + invokedMethod + " on bean named " + beanName
+ " for appname " + appName + " modulename " + moduleName + " distinctname " + distinctName + " due to ", ioe);
// close the channel
IoUtils.safeClose(channel);
return;
}
} finally {
RemotingContext.clear();
}
// write out the (successful) method invocation result to the channel output stream
try {
// attach any weak affinity if available
if (locator instanceof StatefulEJBLocator && componentView.getComponent() instanceof StatefulSessionComponent) {
final StatefulSessionComponent statefulSessionComponent = (StatefulSessionComponent) componentView.getComponent();
final Affinity weakAffinity = MethodInvocationMessageHandler.this.getWeakAffinity(statefulSessionComponent, (StatefulEJBLocator) locator);
if (weakAffinity != null) {
attachments.put(Affinity.WEAK_AFFINITY_CONTEXT_KEY, weakAffinity);
}
}