Source:
<code>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; <START> final int maxAttempts = 5; <END> 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; }</code><technical_language>this method is invoked, do expect call acquireConnection() result in a connection desired server, is element of randomness in server end connected to, retries? If latter, this method prove unusable for situations in chance of correct server random is low</technical_language>

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; }