netty基础知识讲解

Reactor线程模型分为单线程模型,多线程模型,主从线程模型

netty线程模型一般采用Reactor主从线程模型

EventLoopGroup表示线程池,EventLoop表示线程,channel表示客户端和服务端的连接通道

EventLoopGroup包含EventLoop,一个EventLoop包含一个Selector,一个Selector可以处理多个channel

new NioEventLoopGroup() 默认创建的线程池线程数量是系统cpu核数*2

ServerBootstrap  引导类 

.group( ) 设置线程组,

.channel( ) 设置通道类型  Nioserversocketchannel

.option( )  设置每一个新建立的channel中Tcp连接参数,比如已经成功三次握手的请求队列的长度,是否关闭Nagle算法等

.childOption( ) 作用于被acceptor之后的连接

.childHandler( ) 对每个通道的数据的处理 

Channel表示客户端和服务端的连接通道,是对socket的包装

Channel的生命周期,ChannelRegisterd  ====》 ChannelActive ====> ChannelInactive ===》ChannelUnregistered

ChannelRegisterd   注册表示将channel和EventLoop中的Selector绑定

ChannelActive   激活表示可以发送和接受数据

ChannelHandler和ChannelPipeline

ChannelHandler对通道中的数据进行处理

ChannelPipeline是对ChannelHandler进行管理的管道,可以添加ChannelHandler和删除ChannelHandler等

一个channel对应一个ChannelPipeline,一个ChannelPipeline管理多个ChannelHandler

ChannelHandlerContext表示的是ChannelHandler和ChannelPipeline之间的桥梁

猜你喜欢

转载自www.cnblogs.com/moris5013/p/12113364.html