Netty的ByteToMessageDecoder/LengthFieldBasedFrameDecoder
2024-10-19 22:28:20
是个inbound handler,channelRead方法里面,用一个bytebuf(cumulation)来把下一个数据包和当前这一个拼在一起,以免同一个请求被拆包。然后callDecode,里面调用decode这个方法
decode是被子类重写的方法,像rocketMq的NettyDecoder其实主要的逻辑还是在它继承的LengthFieldBasedFrameDecoder中,而LengthFieldBasedFrameDecoder又继承了ByteToMessageDecoder。
所以LengthFieldBasedFrameDecoder就是一种解决粘包的方案:在报文头中用固定长度字段表示当前报文长度。
super(FRAME_MAX_LENGTH, 0, 4, 0, 4);
/**
* Creates a new instance.
*
* @param maxFrameLength-----------最大帧长,Integer.parseInt(System.getProperty("com.rocketmq.remoting.frameMaxLength", "16777216"));
* the maximum length of the frame. If the length of the frame is
* greater than this value, {@link TooLongFrameException} will be
* thrown.
* @param lengthFieldOffset----------描述当前帧长的第一个字节的起始位置,因为有时候信息并不是直接以帧长开头,有可能前面还有别的信息
* the offset of the length field
* @param lengthFieldLength----------描述当前帧长的字节的个数
* the length of the length field
* @param lengthAdjustment----------比如实际帧长是40,描述帧长的字节是4,如果你的lengthFieldLength的值是44(有的人会把描述的数据本身长度也算进去),那么就得有4的调整,才准确
* the compensation value to add to the value of the length field
* @param initialBytesToStrip----------解析时候需要跳过的字节长,这个是干啥?
* the number of first bytes to strip out from the decoded frame
*/
callDecode调用decode传入三个参数: context, bytebuf, out, 第三个out是一个list,里面放的是解决了拆包粘包问题之后解析出来的完整的一个请求,然后for循环发起channelread,RocktMq server的源码里是封装成一个
command对象,然后发起链式的处理
最新文章
- 【JUC】JUC集合框架综述
- hdu2874 LCA在线算法
- 对象转型 casting
- 使用Merge Into 语句实现 Insert/Update
- ListView 使用详解
- Oracle 闪回特性(FLASHBACK DATABASE)
- 跟着Android官网学习Activity
- HTML5 Canvas核心技术—图形、动画与游戏开发.pdf3
- Android 关于 OnScrollListener 事件顺序次数的简要分析
- Kmeans算法与KNN算法的区别
- 【xsy2140】计数
- Web Api 过滤器之 ExceptionFilter 异常过滤器
- 构造方法为private与类修饰符为final
- 比起Windows,怎样解读Linux的文件系统与目录结构?
- python机器学习-sklearn挖掘乳腺癌细胞(四)
- 【转】RESTful Webservice创建
- Oracle 口令文件:即 oracle密码文件
- mysql恢复ibd文件
- Testng用例失败重新运行
- 停止学习框架(Stop Learning Frameworks)
热门文章
- Flask最强攻略 - 跟DragonFire学Flask - 第十五篇 Flask-Script
- CSS——对position定位和margin-top的理解
- Spring 集成 Swagger UI
- hisi 生产固件生成
- Docker Swarm redis 集群搭建
- inotify+rsync架构实现实时同步
- UI自动化(五)dom
- webpack搭建项目时出现的报错“Module build failed (from ./node_modules/css-loader/dist/cjs.js) CssSyntaxError”
- 详解java中的byte类型
- 洛谷 P1273 【有线电视网】