Giovanni Caporaletti
Giovanni Caporaletti

Reputation: 5556

Netty 4.0.0.Beta1 ChannelHandlerContext.readable(boolean) gone, need replacement

in netty 4.0.0.AlphaX there was the ChannelHandlerContext.readable(boolean) method to suspend incoming traffic. The new documentation for 4.0.0.Beta1 still says:

In 4.0, each ChannelHandler is given with its own boolean flag called 'readable' in its ChannelHandlerContext. The flag tells if the handler wants Netty to read inbound traffic or not.

The problem: The readable(boolean) method is gone, and now I can only find a ChannelHandlerContext.fireChannelReadSuspended() method. What about resuming traffic?

Does anyone know how to suspend/resume incoming traffic on netty 4 pipelines after Beta1 upgrade?

Thank you.

N.B.: The "proxy" example still has a TODO:

// TODO: Suspend incoming traffic until connected to the remote host.
//       Currently, we just keep the inbound traffic in the client channel's outbound buffer.

Upvotes: 1

Views: 300

Answers (1)

Norman Maurer
Norman Maurer

Reputation: 23567

You can now use the ChannelOption.AUTO_READ for this. Just set it to false on the ChannelConfig of the Channel if you want to suspend and set it back to true once you want to start read again automatically.

You can even go further now by trigger the reads from hand all the time which can help to keep the memory foot-print to a minimum when writing for a example a proxy. I just updated the proxy example[1] this morning to show this in action.

[1] https://github.com/netty/netty/tree/master/example/src/main/java/io/netty/example/proxy

Upvotes: 1

Related Questions