@Override
    public void deliverRawText(String text) {
        if (!isClosed()) {
            Log.trace("Sending: {}", text);
            channelHandlerContext.writeAndFlush(text).addListener(l ->
                updateWrittenBytesCounter(channelHandlerContext)
            );
            // TODO - handle errors more specifically
            // Currently errors are handled by the default exceptionCaught method (log error, close channel)
            // We can add a new listener to the ChannelFuture f for more specific error handling.
        } else {
            Log.debug("Cannot send data to as connection is already closed: " + this);
        }
    }
Flag that specifies if the connection should be considered closed. Closing a NIO connection
is an asynchronous operation so instead of waiting for the connection to be actually closed just
keep this flag to avoid using the connection between #close was used and the socket is actually
closed.
xmppserver/src/main/java/org/jivesoftware/openfire/nio/NettyConnection.java