Source:
Connection retryInitializeConnection(Connection con) { final boolean isDebugEnabled = logger.isDebugEnabled(); ServerLocation server = this.sender.getServerLocation(); String connectedServerId = con.getEndpoint().getMemberId().getUniqueId(); String expectedServerId = this.processor.getExpectedReceiverUniqueId(); boolean connectedToExpectedReceiver = connectedServerId.equals(expectedServerId); if (expectedServerId.equals("")) { if (isDebugEnabled) { logger.debug("First dispatcher connected to endpoint " + connectedServerId); } this.processor.setExpectedReceiverUniqueId(connectedServerId); connectedToExpectedReceiver = true; } int attempt = 0; final int maxAttempts = 5; while (!connectedToExpectedReceiver) { if (connectedServerId.equals(expectedServerId)) { if (isDebugEnabled) { logger.debug("Dispatcher connected to expected endpoint " + connectedServerId); } connectedToExpectedReceiver = true; } else { if (isDebugEnabled) { logger.debug("Expected connection to [" + expectedServerId + "] but got connection to [" + connectedServerId + "]"); } attempt++; this.sender.getProxy().returnConnection(con); if (attempt >= maxAttempts) { throw new ServerConnectivityException("Cannot get connection to [" + expectedServerId + "] after " + maxAttempts + " attempts."); } if (server != null) { con = this.sender.getProxy().acquireConnection(server); } else { con = this.sender.getProxy().acquireConnection(); } connectedServerId = con.getEndpoint().getMemberId().getUniqueId(); } } return con; }

Target:
Connection retryInitializeConnection(Connection con) { final boolean isDebugEnabled = logger.isDebugEnabled(); ServerLocation server = this.sender.getServerLocation(); String connectedServerId = con.getEndpoint().getMemberId().getUniqueId(); String expectedServerId = this.processor.getExpectedReceiverUniqueId(); if (expectedServerId.equals("")) { if (isDebugEnabled) { logger.debug("First dispatcher connected to server " + connectedServerId); } this.processor.setExpectedReceiverUniqueId(connectedServerId); return con; } int attempt = 0; final int attemptsPerServer = 5; int maxAttempts = attemptsPerServer; Vector<String> notExpectedServerIds = new Vector<String>(); boolean connectedToExpectedReceiver = connectedServerId.equals(expectedServerId); while (!connectedToExpectedReceiver) { if (isDebugEnabled) { logger.debug("Dispatcher wants to connect to [" + expectedServerId + "] but got connection to [" + connectedServerId + "]"); } attempt++; if (!notExpectedServerIds.contains(connectedServerId)) { if (isDebugEnabled) { logger.debug( "Increasing dispatcher connection max retries number due to connection to unknown server (" + connectedServerId + ")"); } notExpectedServerIds.add(connectedServerId); maxAttempts += attemptsPerServer; } if (attempt >= maxAttempts) { throw new ServerConnectivityException(maxAttemptsReachedConnectingServerIdExceptionMessage + " [" + expectedServerId + "] (" + maxAttempts + " attempts)."); } con.destroy(); this.sender.getProxy().returnConnection(con); con = this.sender.getProxy().acquireConnection(); connectedServerId = con.getEndpoint().getMemberId().getUniqueId(); if (connectedServerId.equals(expectedServerId)) { connectedToExpectedReceiver = true; } } if (isDebugEnabled) { logger.debug("Dispatcher connected to expected endpoint " + connectedServerId + " after " + attempt + " retries."); } return con; }