private void updateWrittenBytesCounter(ChannelHandlerContext ctx) {
        ChannelTrafficShapingHandler handler = (ChannelTrafficShapingHandler) ctx.channel().pipeline().get(TRAFFIC_HANDLER_NAME);
        if (handler != null) {
            long currentBytes = handler.trafficCounter().lastWrittenBytes();
            Long prevBytes = ctx.channel().attr(WRITTEN_BYTES).get();
            long delta;
            if (prevBytes == null) {
                delta = currentBytes;
            } else {
                delta = currentBytes - prevBytes;
            }
            ctx.channel().attr(WRITTEN_BYTES).set(currentBytes);
            ServerTrafficCounter.incrementOutgoingCounter(delta);
        }
    }
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