Bhaskar
Bhaskar

Reputation: 7523

Channel.channelInterestChanged in Netty

I am working with Netty Channels and when sending lots of data across the channel , I notice that the Channel.channelInterestChanged event gets fired, which immediately results in Channel.isWritable() to return false.( there is another thread doing a Channel.write() and this thread fails immediately ). My question is : why is the Channel's interests getting changed ? or rather who is changing it ? Nothing in code that I wrote ( server or client ) changes the interests.

Upvotes: 2

Views: 1215

Answers (1)

Norman Maurer
Norman Maurer

Reputation: 23567

It gets changed because you write more data to the Channel then it can transmit in a given time. Netty queues the data for you until some treshold is hit, once it is hit Channel.isWritable() will return false.

You have to adjust the writeBufferHighWaterMark and writeBufferLowWaterMark if you want to change how many bytes are allowed to get queued/buffered before Channel.isWritable() returns false.

ServerBootstrap sb = ....
sb.setOption("writeBufferHighWaterMark", ..);
sb.setOption("writeBufferLowWaterMark", ..);

Anyway you should make sure that your code that calls Channel.write(...) does check Channel.isWritable() and only write to if it returns true. The problem you have are often seen in slow networks.

[1] http://netty.io/docs/stable/api/org/jboss/netty/channel/socket/nio/NioChannelConfig.html

Upvotes: 3

Related Questions