当前位置: 首页 > news >正文

netty之ChannelPipeline和ChannelHandler

简介

ChannelPipeline作为处理流水线,ChannelHandler作为流水线上的一个处理器,其会先包装成ChannelHandlerContext添加到ChannelPipeline

组成

主要介绍相关的抽象

«interface»
ChannelInboundInvoker
«interface»
ChannelOutboundInvoker
«interface»
ChannelPipeline
«interface»
ChannelHandler
«interface»
ChannelHandlerContext
«interface»
ChannelInboundHandler
«interface»
ChannelOutboundHandler

ChannelHandler只提供handler的添加完,删除完,捕获异常方法

void handlerAdded(ChannelHandlerContext ctx) ;
void handlerRemoved(ChannelHandlerContext ctx);
void exceptionCaught(ChannelHandlerContext ctx, Throwable cause);

ChannelInboundHandler提供io线程内channel的事件处理方法

void channelRegistered(ChannelHandlerContext ctx);
void channelUnregistered(ChannelHandlerContext ctx);
void channelActive(ChannelHandlerContext ctx);
void channelInactive(ChannelHandlerContext ctx);
void channelRead(ChannelHandlerContext ctx, Object msg);
void channelReadComplete(ChannelHandlerContext ctx);
void userEventTriggered(ChannelHandlerContext ctx, Object evt);
void channelWritabilityChanged(ChannelHandlerContext ctx);
void exceptionCaught(ChannelHandlerContext ctx, Throwable cause);

ChannelOutboundHandler提供业务线程发起的绑定、连接、断开连接、读写,注销、关闭事件处理

void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise);
void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress,SocketAddress localAddress, ChannelPromise promise);
void disconnect(ChannelHandlerContext ctx, ChannelPromise promise);
void close(ChannelHandlerContext ctx, ChannelPromise promise);
void deregister(ChannelHandlerContext ctx, ChannelPromise promise);
void read(ChannelHandlerContext ctx);
void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise);
void flush(ChannelHandlerContext ctx);

ChannelInboundInvoker发起ChannelInboundHandler相关的事件

ChannelInboundInvoker fireChannelRegistered();
ChannelInboundInvoker fireChannelUnregistered();
ChannelInboundInvoker fireChannelActive();
ChannelInboundInvoker fireChannelInactive();
ChannelInboundInvoker fireExceptionCaught(Throwable cause);
ChannelInboundInvoker fireUserEventTriggered(Object event);
ChannelInboundInvoker fireChannelRead(Object msg);
ChannelInboundInvoker fireChannelReadComplete();
ChannelInboundInvoker fireChannelWritabilityChanged();

ChannelOutboundInvoker发起ChannelOutboundHandler相关事件,包含不需要结果和需要结果两类

ChannelFuture bind(SocketAddress localAddress);
ChannelFuture connect(SocketAddress remoteAddress);
ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress);
ChannelFuture disconnect();
ChannelFuture close();
ChannelFuture deregister();
ChannelFuture bind(SocketAddress localAddress, ChannelPromise promise);
ChannelFuture connect(SocketAddress remoteAddress, ChannelPromise promise);
ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise);
ChannelFuture disconnect(ChannelPromise promise);
ChannelFuture close(ChannelPromise promise);
ChannelFuture deregister(ChannelPromise promise);
ChannelOutboundInvoker read();
ChannelFuture write(Object msg);
ChannelFuture write(Object msg, ChannelPromise promise);
ChannelOutboundInvoker flush();
ChannelFuture writeAndFlush(Object msg, ChannelPromise promise);
ChannelFuture writeAndFlush(Object msg);
ChannelPromise newPromise();
ChannelProgressivePromise newProgressivePromise();
ChannelFuture newSucceededFuture();
ChannelFuture newFailedFuture(Throwable cause);
ChannelPromise voidPromise();

ChannelPipeline:主要是管理ChannelHandler的注册,注销以及事件的触发处理,在inbound和outbound流上传播,会交由ChannelHandlerContext来传播


http://www.mrgr.cn/news/57210.html

相关文章:

  • Unity加载界面制作
  • 1.QT概述及C++基础
  • 【ruoyi-vue】ruoyi-vue 去掉数据库和redis
  • git 下载慢
  • SLAM评估工具evo学习
  • 《神经网络:智能时代的核心技术》
  • 【网络】HTTP协议(下)
  • 深信服超融合HCI6.8.0R2滚动热升级至HCI6.9.1
  • 京东 北京 java 中级: 哪些情况下的对象会被垃圾回收机制处理掉? 哪些对象可以被看做是 GC Roots 呢?对象不可达,一定会被垃圾收集器回收么?
  • 列表、元组、集合、字典和 pandas 数据框(DataFrame)之间的数据转换
  • JavaScript(操作元素属性:样式style,className,classList,表单元素,自定义属性,间歇函数)注册用户协议同意倒计时
  • 【C++篇】探索STL之美:熟悉使用String类
  • 【AIGC】AI时代降临,AI文案写作、AI绘画、AI数据处理
  • 时空智友企业流程化管控系统uploadStudioFile接口存在任意文件上传漏洞
  • static、 静态导入、成员变量的初始化、单例模式、final 常量(Content)
  • 【Python系列】poetry安装依赖
  • 并行计算的未来:大型模型的训练与优化
  • H5的Canvas绘图——使用fabricjs绘制一个可多选的随机9宫格
  • class 9: vue.js 3 组件化基础(2)父子组件间通信
  • vscode使用socks5代理ssh-remote
  • 李沐_动手学深度学习_模型选择
  • 算法学习5
  • 【Linux】磁盘文件系统(inode)、软硬链接
  • js面试问题笔记(一)
  • HTTPS讲解
  • 基于Springboot的在线考试与学习交流平台的设计与实现