private LocalOutgoingServerSession establishConnection() throws Exception {
            Log.debug("Start establishing a connection for {}", domainPair);
            // Create a connection to the remote server from the domain where the packet has been sent
            boolean created;
            // Make sure that only one cluster node is creating the outgoing connection
            final Lock lock = serversCache.getLock(domainPair);
            lock.lock();
            try {
                created = LocalOutgoingServerSession.authenticateDomain(domainPair);
            } finally {
                lock.unlock();
            }
            if (created) {
                final OutgoingServerSession serverRoute = routingTable.getServerRoute(domainPair);
                if (serverRoute == null) {
                    throw new Exception("Route created for " + domainPair + " but not found in routing table! This is likely a concurrency issue within Openfire.");
                } else if (!(serverRoute instanceof LocalOutgoingServerSession)) {
                    throw new Exception("Route created for " + domainPair + " but was not of the expected type " + LocalOutgoingServerSession.class + ", but of " + serverRoute.getClass() + "! This is likely a concurrency issue within Openfire.");
                } else {
                    return (LocalOutgoingServerSession) serverRoute;
                }
            }
            else {
                throw new Exception("Failed to create connection to remote server: " + domainPair);
            }
        }
Checks if an outgoing session is in process of being created, which includes both establishment of the (possibly
authenticated) connection as well as delivery of all queued stanzas.

@param domainPair The connection to check.
@return true if an outgoing session is currently being created, otherwise false.
xmppserver/src/main/java/org/jivesoftware/openfire/server/OutgoingSessionPromise.java