I have a question in Netty4, An I/O event is handled by either a ChannelInboundHandler
or a ChannelOutboundHandler
ChannelOutboundHandler
? read()
method in the fireChannelReadComplete()
? What is the design philosophy?@Override
public ChannelPipeline fireChannelReadComplete() {
head.fireChannelReadComplete();
if (channel.config().isAutoRead()) {
read();
}
return this;
}
Inbound handlers are supposed to handle inbound events. Events are triggered by external stimuli such as data received from a socket.
Outbound handlers are supposed to intercept the operations issued by your application.
Re: Q1) read()
is an operation you can issue to tell Netty to continue reading the inbound data from the socket, and that's why it's in an outbound handler.
Re: Q2) You don't usually issue a read()
operation because Netty does that for you automatically if autoRead
property is set to true
. Typical flow when autoRead
is on:
channelActive
when socket is connected, and then issues a read()
request to itself (see DefaultChannelPipeline.fireChannelActive()
)read()
request.channelRead()
.channelReadComplete()
read()
request to continue reading from the socket.If autoRead
is off, you have to issue a read()
request manually. It's sometimes useful to turn autoRead
off. For example, you might want to implement a backpressure mechanism by keeping the received data in the kernel space.
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