@VisibleForTesting
    static LocalOutgoingServerSession createOutgoingSession(@Nonnull final DomainPair domainPair, int port) {
        final Logger log = LoggerFactory.getLogger(Log.getName() + "[Create outgoing session for: " + domainPair + "]");

        log.debug("Creating new session...");

        ConnectionListener listener = XMPPServer
            .getInstance()
            .getConnectionManager()
            .getListener(ConnectionType.SOCKET_S2S, false);
        NettySessionInitializer sessionInitialiser = new NettySessionInitializer(domainPair, port);
        try {
            // Wait for the future to give us a session...
            // Set a read timeout so that we don't keep waiting forever
            return (LocalOutgoingServerSession) sessionInitialiser.init(listener).get(INITIALISE_TIMEOUT_SECONDS.getValue().getSeconds(), TimeUnit.SECONDS);
        } catch (NetworkEntityUnreachableException e) {
            Log.warn("Cannot connect to XMPP domain '{}' (from '{}'): Unable to create a socket connection to a host that associated " +
                "to the domain. This is typically caused by an outage (the remote server may be turned off) or a network configuration " +
                "issue (eg: missing or invalid DNS records, restrictive firewalls, etc.).", domainPair.getRemote(), domainPair.getLocal());
            sessionInitialiser.stop();
        } catch (Exception e) {
            // This might be RFC6120, section 5.4.2.2 "Failure Case" or even an unrelated problem. Handle 'normally'.
            log.warn("An exception occurred while creating a session. Closing connection.", e);
            sessionInitialiser.stop();
        }

        return null;
    }
Establishes a new outgoing session to a remote domain. If the remote domain supports TLS and SASL then the new
outgoing connection will be encrypted with TLS and authenticated using SASL. However, if TLS or SASL is not
supported by the remote domain or if an error occurred while securing or authenticating the connection using SASL
then server dialback will be used.

@param domainPair the local and remote domain for which a session is to be established.
@param port default port to use to establish the connection.
@return new outgoing session to a remote domain, or null.
xmppserver/src/main/java/org/jivesoftware/openfire/session/LocalOutgoingServerSession.java