netty handler调用链 读取过程
select到一系列事件后,轮流发起channelRead
int size = readBuf.size();
for (int i = 0; i < size; i ++) {
readPending = false;
pipeline.fireChannelRead(readBuf.get(i));
}
readBuf.clear();
入口是调用
pipeline的fireChannelRead
往下走将回调用
AbstractChannelHandlerContext.invokeChannelRead(head, msg);
可以看出
入站读取总是从headContext开始的
然后往下才会调用ctx所持有的
handler的channelRead方法
如果需要继续往下调用
需主动调用以下方法,才能继续往下发
ctx.fireChannelRead(msg);
否则将会在此结束,这是一种过滤器模式的思想

浙公网安备 33010602011771号