*/
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
String[] paramSig = createParamSignature(method.getParameterTypes());
NameBasedInvocation invocation = new NameBasedInvocation(methodName, args, paramSig);
RemotePojoInvocationCommandResponse response = null;
Throwable throwable = null;
RemotePojoInvocationCommand cmd = new RemotePojoInvocationCommand();
cmd.setNameBasedInvocation(invocation);
cmd.setTargetInterfaceName(m_targetInterfaceName);
boolean async_mode_enabled = determineAsynchronous(method);
Long timeout = determineTimeout(method);
boolean guaranteed_delivery = determineGuaranteedDelivery(method);
boolean send_throttle_enabled = determineSendThrottling(method);
if (send_throttle_enabled) {
cmd.getConfiguration().setProperty(ClientCommandSender.CMDCONFIG_PROP_SEND_THROTTLE,
Boolean.toString(true));
}
if (timeout != null) {
cmd.getConfiguration().setProperty(ClientCommandSender.CMDCONFIG_PROP_TIMEOUT, timeout.toString());
}
try {
if (async_mode_enabled) {
if (guaranteed_delivery) {
m_clientCommandSender.sendAsynchGuaranteed(cmd, m_proxyHandlerAsyncCallback);
} else {
m_clientCommandSender.sendAsynch(cmd, m_proxyHandlerAsyncCallback);
}
} else {
CommandResponse sendsync_response = m_clientCommandSender.sendSynch(cmd);
response = new RemotePojoInvocationCommandResponse(sendsync_response);
// throw the exception if one occurred
if (response.getException() != null) {
throw response.getException();
}
}
} catch (CannotConnectException cce) {
// we can perform some retry or failover mechanism here - see JBoss/Remoting TransporterClient for an example
throwable = cce;
} catch (InvocationTargetException ite) {
Throwable root = ite.getCause();
throwable = (root == null) ? ite : root;
} catch (Throwable e) {
throwable = e;
}
// if some failure occured, we need to do different things depending on the enablement of the async mode.
// if async mode is enabled, let's create a command response to indicate the error and notify the callback
// if async mode is disabled (i.e. we are in sync mode), then just throw the exception.
// TODO [mazz]: do we want this behavior - the callback will get the failure response and that same response
// will be returned not sure if we just want to throw the exception no matter what
if (throwable != null) {
LOG.debug(CommI18NResourceKeys.CLIENT_REMOTE_POJO_INVOKER_EXECUTION_FAILURE, methodName, ThrowableUtil
.getAllMessages(throwable, true));
if (async_mode_enabled) {
response = new RemotePojoInvocationCommandResponse(cmd, throwable);
if (m_proxyHandlerAsyncCallback != null) {
m_proxyHandlerAsyncCallback.commandSent(response);
}
} else {
throw throwable;
}
}
Object invoke_return = null;
if (response != null) {
invoke_return = response.getResults();
// if the returned object is a remote stream, we need to tell it how to request stream data
// by giving it the client command sender that will be used to send those requests
if (invoke_return instanceof RemoteInputStream) {
((RemoteInputStream) invoke_return).setClientCommandSender(m_clientCommandSender);