Search in sources :

Example 1 with ChannelOutboundBuffer

use of io.netty.channel.ChannelOutboundBuffer in project netty by netty.

the class IdleStateHandler method hasOutputChanged.

/**
     * Returns {@code true} if and only if the {@link IdleStateHandler} was constructed
     * with {@link #observeOutput} enabled and there has been an observed change in the
     * {@link ChannelOutboundBuffer} between two consecutive calls of this method.
     *
     * https://github.com/netty/netty/issues/6150
     */
private boolean hasOutputChanged(ChannelHandlerContext ctx, boolean first) {
    if (observeOutput) {
        // problem and idleness is least of their concerns.
        if (lastChangeCheckTimeStamp != lastWriteTime) {
            lastChangeCheckTimeStamp = lastWriteTime;
            // But this applies only if it's the non-first call.
            if (!first) {
                return true;
            }
        }
        Channel channel = ctx.channel();
        Unsafe unsafe = channel.unsafe();
        ChannelOutboundBuffer buf = unsafe.outboundBuffer();
        if (buf != null) {
            int messageHashCode = System.identityHashCode(buf.current());
            long pendingWriteBytes = buf.totalPendingWriteBytes();
            if (messageHashCode != lastMessageHashCode || pendingWriteBytes != lastPendingWriteBytes) {
                lastMessageHashCode = messageHashCode;
                lastPendingWriteBytes = pendingWriteBytes;
                if (!first) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Channel(io.netty.channel.Channel) Unsafe(io.netty.channel.Channel.Unsafe) ChannelOutboundBuffer(io.netty.channel.ChannelOutboundBuffer)

Example 2 with ChannelOutboundBuffer

use of io.netty.channel.ChannelOutboundBuffer in project netty by netty.

the class IdleStateHandler method initOutputChanged.

/**
     * @see #hasOutputChanged(ChannelHandlerContext, boolean)
     */
private void initOutputChanged(ChannelHandlerContext ctx) {
    if (observeOutput) {
        Channel channel = ctx.channel();
        Unsafe unsafe = channel.unsafe();
        ChannelOutboundBuffer buf = unsafe.outboundBuffer();
        if (buf != null) {
            lastMessageHashCode = System.identityHashCode(buf.current());
            lastPendingWriteBytes = buf.totalPendingWriteBytes();
        }
    }
}
Also used : Channel(io.netty.channel.Channel) Unsafe(io.netty.channel.Channel.Unsafe) ChannelOutboundBuffer(io.netty.channel.ChannelOutboundBuffer)

Aggregations

Channel (io.netty.channel.Channel)2 Unsafe (io.netty.channel.Channel.Unsafe)2 ChannelOutboundBuffer (io.netty.channel.ChannelOutboundBuffer)2