Connection retryInitializeConnection(Connection con) {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    String connectedServerId = con.getEndpoint().getMemberId().getUniqueId();
    String expectedServerId = processor.getExpectedReceiverUniqueId();

    if (expectedServerId.equals("")) {
      if (isDebugEnabled) {
        logger.debug("First dispatcher connected to server " + connectedServerId);
      }
      processor.setExpectedReceiverUniqueId(connectedServerId);
      return con;
    }

    int attempt = 0;
    final int attemptsPerServer = 5;
    int maxAttempts = attemptsPerServer;
    Vector<String> notExpectedServerIds = new Vector<>();
    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();
      sender.getProxy().returnConnection(con);
      con = 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;
  }
Acquires or adds a new <code>Connection</code> to the corresponding <code>Gateway</code>

@return the <code>Connection</code>
geode-wan/src/main/java/org/apache/geode/cache/wan/internal/GatewaySenderEventRemoteDispatcher.java