@Override
        public void run() {
            Log.debug("Start for {}", domainPair);
            LocalOutgoingServerSession channel;
            try {
                channel = establishConnection();
            } catch (Exception e) {
                Log.debug("An exception occurred while trying to establish a connection for {}", domainPair, e);
                channel = null;
            }

            // After the connection has been established (or failed), process all queued stanzas. Ensure that no more
            // stanzas are queued while we process the queue, by first synchronizing on the same mutex that should be
            // used to guards #queue(). That will cause to-be-queued stanzas to be sent directly over the now
            // established connection after we've finished processing all queued stanzas below.
            synchronized (getMutex(domainPair)) {
                Log.trace("Purging queue for {}", domainPair);
                Packet packet;
                while ((packet = packetQueue.poll()) != null) {
                    if (channel != null) {
                        // A connection to the remote server was created so get the route and purge the packet queue.
                        try {
                            Log.trace("Routing queued stanza: {}", packet);
                            channel.process(packet);
                        } catch (Exception e) {
                            Log.debug("Error sending packet to domain '{}': {}", domainPair.getRemote(), packet, e);
                            returnErrorToSender(packet);
                        }
                    } else {
                        // A connection to the remote server failed. Return an error for all queued stanzas.
                        Log.trace("Bouncing queued stanza: {}", packet);
                        returnErrorToSender(packet);
                    }
                }

                // Remove the processor to ensure that it cannot accept new stanzas to be queued.
                packetsProcessors.remove(domainPair);
            }
            Log.trace("Finished processing {}", 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