Netty架构图
2021-04-26 19:03:26   0  举报             
     
         
 Netty架构图
    作者其他创作
 大纲/内容
 设置感兴趣的事件OP_ACCEPT
  服务器写操作
  RecvByteBufAllocator动态缓冲分配组件
  ctx.write(msg);
  使用线程工厂创建一个线程,并执行
  ByteBuf
  ch.write(msg)
    发送数据给服务器
  ChannelFactory
  ctx.flush();
  此处会负责接收所有的连接请求,并将NioSocketChannel设置为OP_READ后缓存起来
  将自定义的ChannelInitializer放到中
  初始化
  Unsafe
  ChannelHandlerContext
  添加用户自定义的ChannelInitializer
  用户自定义的InBoundHandler
  代码调用
  selector
  指定创建1个即可
  option、attr
  创建cpu core * 2数量的
  设置
  NioServerSocketChannel
  ctx.writeAndFlush(msg);
  Bootstrap
  ChannelBuffer
  NioEventLoop
  返回响应给客户端
  配置成非阻塞模式
  根据传入的NioSocketChannel.class创建
  使用SelectorProvider创建
  注册到NioEventLoop中的Selector上
  NioSocketChannel.class
  SingleThreadEventExecutor.this.run();不断轮巡事件
  连接建立后设置
  交给pipeline中的handler处理
  NioEventLoopGroup(parentGroup)
  NioEventLoopGroup(group)
  finishConnect后依次执行pipeline中的handler
  NioSocketChannel
  根据传入的NioServerSocketChannel.class创建
  客户端的写请求(服务器的读请求),以及服务器返回给客户端的写请求会在此处执行
  msg缓存到
  取出缓存的消息
  监听的端口
  添加Netty自定义的ChannelInitializer
  ChannelPipeline
  NioServerSocketChannel.class
  1、建立连接2、finishConnect
  数据读取到
  将缓存的NioSocketChannel 取出来,并设置先前传入的option、attr等信息,然后注册到childGroup中的NioEventLoop中的Selector上
  ServerBootstrap
  用户自定义的OutBoundhandler
  等childGroup接手后就会一次执行Pipeline中的handler
  设置感兴趣的事件OP_CONNECT
  NioEventLoopGroup(childGroup)
  是两者的组合,不过步骤都是一样的
   
 
 
 
 
  0 条评论
 下一页
  
   
   
   
   
  
  
  
  
  
  
  
  
 