} else {
method = serverClass.getMethod(m.getName(),m.getParameterTypes());
}
if (method == null) {
throw new EmsConnectException("Unsupported operation [" + m.getName() + "]");
}
ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
try {
roundTrips++;
// Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
boolean isJBossConnection = (this.provider instanceof JBossConnectionProvider);
if (isJBossConnection) {
JBossConnectionProvider jbossProvider = (JBossConnectionProvider) this.provider;
// See https://jira.jboss.org/jira/browse/JOPR-9 for an explanation of why we have to re-set the
// PrincipalInfo prior to every JBoss JMX call.
//jbossProvider.resetPrincipalInfo();
// Login via JAAS before making the call...
jbossProvider.login();
}
Object returnValue;
try {
returnValue = method.invoke(this.remoteServer, args);
} finally {
if (isJBossConnection) {
JBossConnectionProvider jbossProvider = (JBossConnectionProvider) this.provider;
// Logout via JAAS before returning...
jbossProvider.logout();
}
}
return returnValue;
} catch(InvocationTargetException e) {
failures++;
if (e.getCause() != null) {
Throwable t = e.getCause();
if (t instanceof java.rmi.ConnectException) {
throw new EmsConnectException(t);
} else if (t instanceof NoSuchObjectException) {
// This happens when the server comes back up and the stub is stale
// try to reconnect if this provider supports it (if it told the proxy what the provider was)
if (provider != null && !reconnecting) {
try {
log.info("Reestablishing RMI stub " + this.provider.getConnectionSettings().getServerUrl());
reconnecting = true;
provider.connect();
// Retry the request once
return this.invoke(proxy, m, args);
} catch(Exception f) {
log.warn("Unable to reestablish RMI stub to restarted server.",f);
} finally{ reconnecting = false; }
}
// The reconnect failed, throw the original exception
// If the retry fails, it will throw its own exception
throw new EmsConnectException(t);
} else if (t instanceof java.io.IOException) {
throw new EmsConnectException(t);
} else if (t instanceof NotSerializableException) {
throw new EmsUnsupportedTypeException("Value was not serializable " + t.getLocalizedMessage(),t);
} else {
throw new EmsConnectException("Connection failure " + t.getLocalizedMessage(), t);
}
} else {
throw e;
}
} catch (Exception e) {