Source:
void reconnect() throws InterruptedException { long maxTries = options.getMaxReconnect(); long tries = 0; String lastServer = null; if (isClosed()) { return; } if (maxTries == 0) { this.close(); return; } this.writer.setReconnectMode(true); boolean doubleAuthError = false; while (!isConnected() && !isClosed() && !this.isClosing()) { List<String> serversToTry = buildServerList(); lastServer = serversToTry.get(serversToTry.size()-1); boolean shouldWait = false; for (String server : serversToTry) { if (isClosed()) { break; } connectError.set(""); if (isDisconnectingOrClosed() || this.isClosing()) { break; } if (server.equals(lastServer)) { shouldWait = true; } updateStatus(Status.RECONNECTING); tryToConnect(server, System.nanoTime()); tries++; if (maxTries > 0 && tries >= maxTries) { break; } else if (isConnected()) { this.statistics.incrementReconnects(); this.currentServer = server; break; } else { String err = connectError.get(); if (this.isAuthenticationError(err)) { if (err.equals(this.serverAuthErrors.get(server))) { doubleAuthError = true; break; } this.serverAuthErrors.put(server, err); } } } if (doubleAuthError) { break; } if (maxTries > 0 && tries >= maxTries) { break; } if (shouldWait) { this.reconnectWaiter = new CompletableFuture<>(); waitForReconnectTimeout(); } } if (!isConnected()) { this.close(); return; } this.subscribers.forEach((sid, sub) -> { if (sub.getDispatcher() == null && !sub.isDraining()) { sendSubscriptionMessage(sub.getSID(), sub.getSubject(), sub.getQueueName(), true); } }); this.dispatchers.forEach((nuid, d) -> { if (!d.isDraining()) { d.resendSubscriptions(); } }); try { this.flush(this.options.getConnectionTimeout()); } catch (Exception exp) { this.processException(exp); } this.writer.setReconnectMode(false); processConnectionEvent(Events.RESUBSCRIBED); }

Target:
void reconnect() throws InterruptedException { long maxTries = options.getMaxReconnect(); long tries = 0; String lastServer = null; if (isClosed()) { return; } if (maxTries == 0) { this.close(); return; } this.writer.setReconnectMode(true); boolean doubleAuthError = false; while (!isConnected() && !isClosed() && !this.isClosing()) { List<String> serversToTry = buildServerList(); lastServer = serversToTry.get(serversToTry.size()-1); for (String server : serversToTry) { if (isClosed()) { break; } connectError.set(""); if (isDisconnectingOrClosed() || this.isClosing()) { break; } updateStatus(Status.RECONNECTING); tryToConnect(server, System.nanoTime()); tries++; if (maxTries > 0 && tries >= maxTries) { break; } else if (isConnected()) { this.statistics.incrementReconnects(); this.currentServer = server; break; } else { String err = connectError.get(); if (this.isAuthenticationError(err)) { if (err.equals(this.serverAuthErrors.get(server))) { doubleAuthError = true; break; } this.serverAuthErrors.put(server, err); } } if (server.equals(lastServer)) { this.reconnectWaiter = new CompletableFuture<>(); waitForReconnectTimeout(); } } if (doubleAuthError) { break; } if (maxTries > 0 && tries >= maxTries) { break; } } if (!isConnected()) { this.close(); return; } this.subscribers.forEach((sid, sub) -> { if (sub.getDispatcher() == null && !sub.isDraining()) { sendSubscriptionMessage(sub.getSID(), sub.getSubject(), sub.getQueueName(), true); } }); this.dispatchers.forEach((nuid, d) -> { if (!d.isDraining()) { d.resendSubscriptions(); } }); try { this.flush(this.options.getConnectionTimeout()); } catch (Exception exp) { this.processException(exp); } this.writer.setReconnectMode(false); processConnectionEvent(Events.RESUBSCRIBED); }