I have a scenario where I need to keep writing to a Channel
. In case it is unable to take further data ( because of the buffers being full etc ) , I need to stop writing , but need to resume as soon as the channel becomes writable again. How do I determine this instant when a channel becomes writable again ? Is there a callback event that is fired which I can override ? I am extending SimpleChannelUpstreamHandler
in my business handler - this has a method channelInterestChanged()
- but not sure if this is correct hook to tap into ?
I was hoping to avoid using primitive thread-based wait mechanisms like wait-notify as these will involve context switching. Any non-blocking way to achieve this wait ?
Netty Channel Channel is a component providing users a ways to process I/O operations, such as read and write. A ChannelPipeline encapsulates a series of ChannelHandler instances as two-way linked list. Inbound and outbound events that flow through a channel can be intercepted by the ChannelPipeline.
A Bootstrap that makes it easy to bootstrap a Channel to use for clients. The AbstractBootstrap. bind() methods are useful in combination with connectionless transports such as datagram (UDP).
You can override the channelInterestChanged()
method.
Something like that:
public class MyHandler extends SimpleChannelUpstreamHandler {
....
@Override
public void channelInterestChanged(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
if (e.getChannel().isWritable() {
.....
}
}
}
This should do the job
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With