public Connection getConnection(boolean startAckReaderThread) throws GatewaySenderException {
    if (processor.isStopped()) {
      stop();
      return null;
    }
    // IF the connection is null
    // OR the connection's ServerLocation doesn't match with the one stored in sender
    // THEN initialize the connection
    if (!sender.isParallel()) {
      boolean needToReconnect = false;
      getConnectionLifeCycleLock().readLock().lock();
      try {
        needToReconnect = connection == null || connection.isDestroyed()
            || connection.getServer() == null
            || !connection.getServer().equals(sender.getServerLocation());
      } finally {
        getConnectionLifeCycleLock().readLock().unlock();
      }
      if (needToReconnect) {
        if (logger.isDebugEnabled()) {
          logger.debug(
              "Initializing new connection as serverLocation of old connection is : {} and the serverLocation to connect is {}",
              ((connection == null) ? "null" : connection.getServer()),
              sender.getServerLocation());
        }
        // Initialize the connection
        initializeConnection();
      }
    } else {
      if (connection == null || connection.isDestroyed()) {
        initializeConnection();
      }
    }

    // Here we might wait on a connection to another server if I was secondary
    // so don't start waiting until I am primary
    InternalCache cache = sender.getCache();
    if (cache != null && !cache.isClosed()) {
      if (sender.isPrimary() && (connection != null)) {
        if (ackReaderThread == null || !ackReaderThread.isRunning()) {
          ackReaderThread = new AckReaderThread(sender, processor);
          ackReaderThread.start();
          ackReaderThread.waitForRunningAckReaderThreadRunningState();
        }
      }
    }
    return connection;
  }
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