下面的是ServerBootstrap 的内部类 ServerBootstrapAcceptor extends ChannelInboundHandlerAdapter 的方法
这里其实卡住了我很长时间,为啥AbastracHandlerContext的handler()方法,返回的会是ServerBootstrapAcceptor 的对象呢?
先看handler方法,这是个重写的方法,会在子类里实现,到底是哪个子类实现的?往上看,调用handler的方法参数,从上面传进来的是一个 在 pipeline里面 叫 head的属性,
在new 一个defaultPipeline的时候, head 和 tail
也就是说,pipeline里面保存一个handlercontext的链表,从head一直执行到tail,那么被添加到pipeline里面的handler都会执行。
而 serverbootstrap的init()方法,最后有这样的逻辑:添加一个new ServerBootstrapAcceptor 到pipeline中
添加了两个handler,第一个是serverbootstrap中的传入的handler,第二个是new的一个 acceptor,什么时候启动的initchannel方法呢?