} catch (Exception e) {
LOG.warn(AgentI18NResourceKeys.CANNOT_SWITCH_TO_INVALID_SERVER, server, ThrowableUtil.getAllMessages(e));
return false;
}
RemoteCommunicator comm;
try {
comm = getClientCommandSender().getRemoteCommunicator();
if (comm == null) {
throw new IllegalStateException(); // i don't think this will ever happen, but just in case
}
} catch (Exception e) {
LOG.warn(AgentI18NResourceKeys.CANNOT_SWITCH_NULL_COMMUNICATOR, server, ThrowableUtil.getAllMessages(e));
return false;
}
// remember this in case we fail - we have to revert back to the original server we were talking to
String originalServerEndpoint = comm.getRemoteEndpoint();
// need to synch on last failover time so we don't clash with the real failover stuff
synchronized (m_lastFailoverTime) {
boolean ok = switchCommServer(comm, newServer.namePort, newServer.transport, newServer.transportParams);
if (!ok) {
try {
// we are switching back to the original server because our switch failed
comm.setRemoteEndpoint(originalServerEndpoint);
config.setServerLocatorUri(currentServerTransport, currentServerAddress, currentServerPort,
currentServerTransportParams);
} catch (Exception e) {
// this should never happen
LOG.warn(AgentI18NResourceKeys.CANNOT_SWITCH_TO_INVALID_SERVER, originalServerEndpoint, e);