Harikrishnan
Harikrishnan

Reputation: 3822

Where is Channel.setInterestOps in Netty 4x

I am using netty for developing my server. I am looking for setting the setInterestOps for a channel. In netty 3 there is a method call setInterestOps in Channel class. But in netty 4 I can't find it. Can anybody tell me where it is?

Thank you

Upvotes: 0

Views: 200

Answers (2)

trustin
trustin

Reputation: 12351

Channel.setInterestOps() in Netty 3 was used to suspend or resume the read operation of a Netty Channel. Its name and mechanic were unnecessarily low-level, so we changed how we deal with the suspension and resumption of the inbound traffic.

First, we added a new outbound operation called read(). When read() is invoked, Netty will read inbound traffic once, and it will trigger at least one channelRead() event and a single channelReadComplete() event. Usually, you continue to read by calling ctx.read() in channelReadComplete().

However, because having to call ctx.read() for every channelReadComplete() is not very interesting, Netty has an option called autoRead, which is turned on by default. When autoRead is on, Netty will automatically trigger a read() operation on every channelReadComplete().

Therefore, If you want to suspend the inbound traffic, all you need to do is to turn the autoRead option off. To resume, turn it back on.

Upvotes: 2

Norman Maurer
Norman Maurer

Reputation: 23567

Use Channel.config().setAutoRead(true/false);

Upvotes: 1

Related Questions