if(!addresses.isEmpty()) {
for(ResolvedAddress address : addresses) {
LOG.info("Connecting to XMPP server {} at {}", otherServer, address.getAddress());
connector = createConnector(authenticatedLatch);
ConnectFuture connectFuture = connector.connect(address.getAddress());
if(connectFuture.awaitUninterruptibly(connectTimeout) && connectFuture.isConnected()) {
// success on the TCP/IP level, now wait for the XMPP handshake
try {
if(authenticatedLatch.await(xmppHandshakeTimeout, TimeUnit.MILLISECONDS)) {
// success, break out of connect loop
successfullyConnected = true;
break;
} else {
// attempt next
LOG.warn("XMPP handshake with {} at () timed out", otherServer, address.getAddress());
}
} catch (InterruptedException e) {
throw new RemoteServerTimeoutException("Connection to " + otherServer + " was interrupted", e);
}
}
lastException = connectFuture.getException();
LOG.warn("Failed connecting to XMPP server " + otherServer + " at " + address.getAddress(), connectFuture.getException());
connector.dispose();
connector = null;
}
} else {
// should never happen