6.3 状态模型
6.3状态模型Netty有一个简单但功能强大的状态模型,可以完美地映射到ChannelInboundHandler方法。我们将在本章的后面部分讨论ChannelInboundHandler。如表6.5所示,有四种状态。

Channel的状态在其生命周期中都会发生变化,所以会触发状态更改。Channel的生命周期有四种状态改变。

在更高级别的场景中,你或许会看到额外的状态改变。这是因为允许用户手动从EventLoop中注销该通道,以暂停该通道的事件执行,然后再重新注册它。
在这种情况下,您将看到多个channelRegistered和channelUnregistered状态更改。您只能对channelActive和channelInactive进行一次状态更改,因为一个通道只能用于一个连接生命周期;此后需要回收。如果要重新连接,则需要创建另一个。
Figure 6.6 shows the state changes if a user deregisters a channel from an EventLoop and later reregisters it.

Youll learn more about the operations that can be executed on a ByteBuf in a later section; for now, keep this in mind while we review the different types of ByteBuf that youll most likely use.
最后更新于
这有帮助吗?