Netty 源码(一)Netty 组件简介

Netty 组件简介

Netty 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html)

1. Netty 架构

  • Core:核心部分,是底层的⽹网络通⽤用抽象和部分实现。
    • Extensible Event Model :可拓拓展的事件模型。Netty 是基于事件模型的⽹网络应⽤用框架。
    • Universal Communication API :通⽤用的通信 API 层。Netty 定义了了⼀一套抽象的通⽤用通信
      层的 API 。
    • Zero-Copy-Capable Rich Byte Buffer :⽀支持零拷⻉贝特性的 Byte Buffer 实现。
  • Transport Services:传输( 通信 )服务,具体的⽹网络传输的定义与实现。
    • Socket & Datagram :TCP 和 UDP 的传输实现。
    • HTTP Tunnel :HTTP 通道的传输实现。
    • In-VM Piple :JVM 内部的传输实现。
  • Protocol Support :协议支持。Netty 对于一些通用协议的编解码实现。例如:HTTP、Redis、DNS 等等。

2. Netty 核心组件

Netty 有如下几个核⼼心组件:

  • Bootstrap & ServerBootstrap
  • Channel
  • ChannelFuture
  • EventLoop & EventLoopGroup
  • ChannelHandler
  • ChannelPipeline

下图是 Channel、EventLoop、Thread、EventLoopGroup 之间的关系。

  • 一个 EventLoopGroup 包含一个或多个 EventLoop。
  • 一个 EventLoop 在它的生命周期内只能与一个 Thread 绑定。
  • 所有有 EnventLoop 处理的 I/O 事件都将在它专有的 Thread 上被处理。
  • 一个 Channel 在它的生命周期内只能注册与一个 EventLoop。
  • 一个EventLoop 可被分配至一个或多个 Channel 。

当一个连接到达时,Netty 就会注册一个 Channel,然后从 EventLoopGroup 中分配一个 EventLoop 绑定到这个 Channel 上,在该 Channel 的整个生命周期中都是有这个绑定的 EventLoop 来服务的。


每天用心记录一点点。内容也许不重要,但习惯很重要!

原文地址:https://www.cnblogs.com/binarylei/p/10136304.html