1.? EventLoopGroup bossGroup =newNioEventLoopGroup() 創(chuàng)建線程組
? ? ? ?看一下 EventExecutorGroup 接口 依賴關(guān)系
? ? ? ?它的主要的方法是next 方法

看一下 newNioEventLoopGroup 依賴關(guān)系

2 創(chuàng)建newNioEventLoopGroup 它的時候方法

2.1 重點看一下 SelectProvider.provider ,同時看一下類SelectProvider 這個類的作用
2.2
看一下 這個類? KQueueSelectorImpl的解析參考的構(gòu)造方法 KQueueSelectorImpl(SelectorProvider var1)

IOUtil.makePipe(false);是一個static native方法,所以我們沒辦法查看源碼。但是我們可以知道該函數(shù)返回了一個非堵塞的管道(pipe),底層是通過Linux的pipe系統(tǒng)調(diào)用實現(xiàn)的;創(chuàng)建了一個管道pipe并返回了一個64為的long型整數(shù),該數(shù)的高32位存放了該管道讀端的文件描述符,低32位存放了該pipe的寫端的文件描述符。
3.完成Selector和Channel 綁定的在 Channel的 initAndRegister?

因為在group 中完成reactor線程模型的同事 注入了Selector 選擇器 group中的對象EventLoopGroup是包含Selector的 這就和我們的NIO模型
4 .看一下注冊事件?

5 下面看一下 AbstractCHannel的register方法

6.看到register0(promise) 很高興終于看到正真的注冊的方法了
但是還需要看doRegister();

7.看看doRegister 里面的for循環(huán)做了什么

重點說一下這個方法
將NioServerSocketChannel注冊到NioEventLoop的Selector上,this是對象NioServerSocketChannel 作為注冊的附件 attachment? 這樣終于看到了 selector ,channel ,和attachment,NioEventLoop持有Selector對象在構(gòu)造 reactor 線程模型的時候構(gòu)造的,channel 是NioServerSocketChannel 是在初始化的時候構(gòu)造的
8.接著上面的圖看看pipeline.fireChannelRegistered()做了什么?

上圖中的initChannel((C) ctx,chanel)完成了我們實際的 pipeline的注入 并且移除我們默認(rèn)的defaultChannPipeline 這個是在我們創(chuàng)建channel的時候默認(rèn)的,用了這么久現(xiàn)在可以remove,感嘆設(shè)計的優(yōu)秀呀。
到此完成了 selector? 在reactor 模型中創(chuàng)建,channel 在 bind中創(chuàng)建 實例化,在上面看到了 Channel 和Selector的綁定,現(xiàn)在有看到了 pipeline的實例化。
9,pipeline的實例化 把所有的handel按照順序放入其中。

10.構(gòu)造處理chain 鏈表結(jié)構(gòu)

到此完成實例化。
10.現(xiàn)在我要找到run 方法

11.此處的execute其實是父類的方法執(zhí)行,

12.我們看到了startExecution

13.接下來看看 executor.execute


14 調(diào)用的是SingleThreadEventExecutor.this.run 其實是調(diào)用了NioEventLoop的run

15 看到了selectNow 和select 等 接著又是runallTasks

16.看看runallTasks

17.再把 pollTak() 方法看一下

