@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
boolean release = true;
try {
if (acceptInboundMessage(msg)) {
@SuppressWarnings("unchecked")
I imsg = (I) msg;
channelRead0(ctx, imsg);
} else {
release = false;
ctx.fireChannelRead(msg);
}
} finally {
if (autoRelease && release) {
ReferenceCountUtil.release(msg);
}
}
}
/**
* Returns {@code true} if the given message should be handled. If {@code false} it will be passed to the next
* {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
*/
public boolean acceptInboundMessage(Object msg) throws Exception {
return matcher.match(msg);
}
本文探讨了Netty框架中Inbound消息的处理流程,详细解析了channelRead方法的实现,包括消息匹配与传递机制。重点介绍了acceptInboundMessage方法的作用,即决定消息是否由当前处理器处理还是传递给下一个处理器。
2153

被折叠的 条评论
为什么被折叠?



