1. Channel组件
核心的针对BIO/NIO提供的抽象的网络通道,支持读,写,连接和绑定。
Channel
A nexus to a network socket or a component which is capable of I/O operations such as read, write, connect, and bind.
ChannelFactoryCreates a Channel
associated with a certain communication entity such as a network socket.
2. ChannelPipeline组件
可以理解为ChannelHandler的容器,主要负责通道的可读,可写,连接和绑定等事件在管道化的一系列ChannelHandler中的流转。所有ChannelHandler都必须注册到ChannelPipeline中按顺序组织起来。
ChannelPipeline
A list of ChannelHandler
s which handles or interceptsChannelEvent
s of aChannel
.
ChannelPipelineFactory
Creates a new ChannelPipeline
for a newChannel
.
3. ChannelHandler组件
提供针对通道的可读,可写,连接和绑定等事件的处理接口,主要负责实际与网络IO无关的业务逻辑的处理。
ChannelHandler
Handles or intercepts a ChannelEvent
, and sends aChannelEvent
to the next handler in aChannelPipeline
.
ChannelHandlerContext
Enables a ChannelHandler
to interact with itsChannelPipeline
and other handlers.
4. ChannelFuture组件
针对通道的读,写,连接和绑定等异步IO操作的抽象,类似于JDK中提供的Future。一个ChannelFuture对象代表了一个尚未发生的I/O操作。这意味着,任何已请求的操作都可能是没有被立即执行的,因为在Netty内部所有的操作都是异步的。
ChannelFuture
The result of an asynchronous Channel
I/O operation.
ChannelFutureListener
Listens to the result of a ChannelFuture
.
5. ChannelBuffer组件
Netty中的buffer是完全重新实现的,与NIO ByteBuffer完全不同。如果要说NIO的Buffer和Netty的ChannelBuffer最大的区别的话,就是前者仅仅是传输上的Buffer,而后者其实是传输Buffer和抽象后的逻辑Buffer的结合。
A random and sequential accessible sequence of zero or more bytes (octets). This interface provides an abstract view for one or more primitive byte arrays (byte[]
) andNIO buffers.
6. ChannelEvent组件
ChannelEvent是数据或者状态的载体,当对Channel进行操作时,会产生一个ChannelEvent,并发送到ChannelPipeline。
ChannelEvent
An I/O event or I/O request associated with a Channel
.
A ChannelEvent
is handled by a series of ChannelHandler
s in a ChannelPipeline
.