public void startTLS(boolean clientMode, boolean directTLS) throws Exception {

        final EncryptionArtifactFactory factory = new EncryptionArtifactFactory( configuration );

        final SslHandler sslHandler;
        if (clientMode) {
            final SslContext sslContext = factory.createClientModeSslContext();

            // OF-2738: Send along the XMPP domain that's needed for SNI
            final NettyOutboundConnectionHandler handler = channelHandlerContext.channel().pipeline().get(NettyOutboundConnectionHandler.class);

            sslHandler = sslContext.newHandler(channelHandlerContext.alloc(), handler.getDomainPair().getRemote(), handler.getPort());
        } else {
            final SslContext sslContext = factory.createServerModeSslContext(directTLS);
            sslHandler = sslContext.newHandler(channelHandlerContext.alloc());
        }

        channelHandlerContext.pipeline().addFirst(SSL_HANDLER_NAME, sslHandler);

        if ( !clientMode && !directTLS ) {
            // Indicate the client that the server is ready to negotiate TLS
            deliverRawText( "<proceed xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>" );
        }
    }
Updates the system counter of written bytes. This information is used by the "outgoing bytes" statistic.

@param ctx the context for the channel writing bytes
xmppserver/src/main/java/org/jivesoftware/openfire/nio/NettyConnection.java