Netty原理示图

1. AWT事件驱动

2. Websocket协议

3. 基于多个反应器的多线程模式

4. Netty Reactor 工作架构图

5. Bootstrap引导过程

Channel
Channel是Java NIO的基础。它表示一个开放的连接,进行IO操作。基本的 I/O 操作( bind() 、 connect() 、 read() 和 write() )依赖于底层网络传输所提供的原语。在基于 Java 的网络编程中,其基本的构造是 class Socket 。Netty 的 Channel 接口所提供的 API,大大地降低了直接使用 Socket 类的复杂性。

EventLoop
EventLoop 定义了 Netty 的核心抽象,用于处理连接的生命周期中所发生的事件。

6. ServerBootstrap引导过程

7. Selector处理逻辑

8. Channel 、 EventLoop 和 EventLoopGroup关系

9. 具有2个EventLoopGroup的服务器

与 ServerChannel 相关联的 EventLoopGroup 将分配一个负责为传入连接请求创建 Channel 的 EventLoop 。一旦连接被接受,第二个 EventLoopGroup 就会给它的 Channel 分配一个 EventLoop 。

10. 用于非阻塞传输(如 NIO 和 AIO)的EventLoop分配方式

11. EventLoop 执行逻辑

12. ChannelPipeline

13. Channel、ChannelPipeline、ChannelHandler 以及 ChannelHandlerContext 之间的关系

14. 通过Channel或ChannelPipeline进行事件传播

15. 通过ChannelHandlerContext触发的操作的事件流

16. Execution-logic of Netty3

1 The I/O thread that handles all the I/O events of a channel
2 Data gets ready from the socket
3 Gets processed in the worker, which is bound to the I/O thread
4 The data / event is passed through all the ChannelHandlers of the Channel . This still happens within the IO thread of the Channel.
5 Any thread from which an outbound operation is triggered. This may be the IO / thread or any other thread.
6 Something is passed to the Channel.write(…)
7 The write operation will generate an event that will get passed to the ChannelHandlers of the channel
8 The event gets passed through all the ChannelHandlers of the channel This happens in the same thread as from which the write operation was triggerd.
09 Once processing of the even via the ChannelHandlers is done, it will hand over the event to the worker thread
10 The data is finally written to the remote peer by the worker thread

17. channel

18. Pipleline中Handler的调用链

本文链接:https://my.lmcjl.com/post/7541.html

展开阅读全文

4 评论

留下您的评论.