mina学习笔记六:补刀
补充一些可能没讲到的细节。
1.WriteRequest
- private IoSessionDataStructureFactory sessionDataStructureFactory = new DefaultIoSessionDataStructureFactory();
这个参数就包括了两个鸟不得的结构体,一个就是attribute的map,另一个就是我们可爱的WriteRequestQueue了。
2.IoBuffer
- Buffer没有提供实用的工具型getter和setter方法,比如fill, get/putString, and get/putAsciiInt() 。
- 原生的Buffer是固定长度的,非常不利于用于操作可变长度的数据。
This will change in MINA 3. The main reason why MINA has its own wrapper on top of nio ByteBuffer is to have extensible buffers. This was a very bad decision. Buffers are just buffers : a temporary place to store temporary data, before it is used. Many other solutions exist, like defining a wrapper which relies on a list of NIO ByteBuffers, instead of copying the existing buffer to a bigger one just because we want to extend the buffer capacity.It might also be more comfortable to use an InputStream instead of a byte buffer all along the filters, as it does not imply anything about the nature of the stored data : it can be a byte array, strings, messages...Last, not least, the current implementation defeat one of the target : zero-copy strategy (ie, once we have read the data from the socket, we want to avoid a copy being done later). As we use extensible byte buffers, we will most certainly copy those data if we have to manage big messages. Assuming that the MINA ByteBuffer is just a wrapper on top of NIO ByteBuffer, this can be a real problem when using direct buffers.
3.用到的设计模式
3.1抽象工厂ProtocolCodecFactory
3.2 建造者模式
3.3 适配器模式
3.4 装饰者模式
3.5 外观模式
3.6 桥接模式
3.7 组合模式
3.8 享元模式
3.9 模板方法
3.10 观察者模式
3.11 策略模式
3.12 责任链模式
3.13 命令模式
4.为什么NioDatagramAcceptor不使用SimpleIoProcessorPool
- AbstractPollingConnectionlessIoAcceptor.newSessionWithoutLock( SocketAddress remoteAddress, SocketAddress localAddress ) throws Exception
- {
- H handle = boundHandles.get( localAddress );
- if ( handle == null )
- {
- throw new IllegalArgumentException( "Unknown local address: " + localAddress );
- }
- IoSession session;
- synchronized ( sessionRecycler )
- {
- session = sessionRecycler.recycle( remoteAddress );
- if ( session != null )
- {
- return session;
- }
- // If a new session needs to be created.
- S newSession = newSession( this, handle, remoteAddress );
- getSessionRecycler().put( newSession );
- session = newSession;
- }
- initSession( session, null, null );
- try
- {
- this.getFilterChainBuilder().buildFilterChain( session.getFilterChain() );
- getListeners().fireSessionCreated( session );
- }
- catch ( Throwable t )
- {
- ExceptionMonitor.getInstance().exceptionCaught( t );
- }
- return session;
- }
究其原因,应该是NioDatagramAcceptor对于会话的维护不需要付出NioSocketAcceptor那么大的代价。NioDatagramAcceptor只用了一个Selector去监听会话请求,而NioSocketAcceptor用了1个监听连接、CPU+1个去监听不同的session,可见一斑。
结语
mina学习笔记六:补刀相关推荐
- Ethernet/IP 学习笔记六
Ethernet/IP 学习笔记六 EtherNet/IP defines two primary types of communications: explicit and implicit (Ta ...
- 吴恩达《机器学习》学习笔记六——过拟合与正则化
吴恩达<机器学习>学习笔记六--过拟合与正则化 一. 过拟合问题 1.线性回归过拟合问题 2.逻辑回归过拟合问题 3.过拟合的解决 二. 正则化后的代价函数 1.正则化思想 2.实际使用的 ...
- ROS学习笔记六:理解ROS服务和参数
ROS学习笔记六:理解ROS服务和参数 主要介绍ROS服务和参数,同时使用命令行工具rosservice和rosparam. ROS service service是节点之间互相通信的另一种方式,se ...
- opencv 手选roi区域_【opencv学习笔记六】图像的ROI区域选择与复制
图像的数据量还是比较大的,对整张图片进行处理会影响我们的处理效率,因此常常只对图像中我们需要的部分进行处理,也就是感兴趣区域ROI.今天我们来看一下如何设置图像的感兴趣区域ROI.以及对ROI区域图像 ...
- JS学习笔记六:js中的DOM操作
1. JS学习笔记六:js中的DOM操作 文章目录 1. JS学习笔记六:js中的DOM操作 1.1. 获取Dom节点 1.2. 元素属性的操作方式 1.3. DOM节点的创建.插入和删除 1.4. ...
- Python学习笔记六——画小猪佩奇
目录 Python学习笔记六--画小猪佩奇 画布 画笔 属性设置 操纵命令 运动命令 画笔控制命令 全局控制命令 其他命令 Python学习笔记六--画小猪佩奇 使用Python的turtle库可以绘 ...
- Learning ROS for Robotics Programming Second Edition学习笔记(六) indigo xtion pro live
中文译著已经出版,详情请参考:http://blog.csdn.net/ZhangRelay/article/category/6506865 Learning ROS for Robotics Pr ...
- Polyworks脚本开发学习笔记(六)-比较运算、数学运算、逻辑运算及流程控制
Polyworks脚本开发学习笔记(六)-比较运算.数学运算.逻辑运算及流程控制 前言 比较运算.逻辑运算及流程控制是编程的基本语法,Polyworks的语法规则与VB/C#/Python等并没有很大 ...
- 【K210】K210学习笔记六——MaixHub在线模型训练识别数字
[K210]K210学习笔记六--MaixHub在线模型训练识别数字 前言 K210准备工作 数据的获取 MaixHub如何在线训练模型 训练模型在K210上的测试 小结 前言 本人大四学生,电赛生涯 ...
最新文章
- 突发!美国最大输油管道遭网络攻击关闭!美媒:为其基础设施的脆弱堪忧
- Ubuntu配置jdk环境变量
- python跟java-还在纠结选Python还是Java?看完就有数了
- Hexo错误_FATAL missed comma between flow collection entries at line
- WinAPI: Ellipse - 绘制椭圆
- C#多线程开发-使用并发集合
- Python监听键盘和鼠标事件,并发送内容至邮箱!
- bash资源监控_10个资源成为更好的Bash用户
- 高等学校计算机房使用章程,普通高等学校设置暂行条例.DOC
- ie9 jscript7 内存不足 页面无响应
- nyoj 8 一种排序(用vector,sort,不用set)
- HP LaserJet 1010 安装方法
- BLE_BQB Test_Carrier frequency offset and drift, LE Coded (S=8)_RF-PHY/TRM/BV-14-C
- 问题 H: LZY碎大石
- 树莓派之火焰传感器模块
- 《计算机系统与维护》— CPU的主要技术指标
- 单片机关于推挽输出和开漏输出
- 使用C#进行图像处理
- 物联通信安全需求如何实现
- 寒假的时候,小明同学要去拜访很多朋友,恰巧他所有朋友的家都处在坐标平面的X轴上。小明可以任意选择一个朋友的家开始访问,但是每次访问后他都必须回到出发点,然后才能去访问下一个朋友。
热门文章
- UI自动化+web测试基础3-2,京东流程
- 软件测试都学什么技能?软件测试职业方向在哪里?
- 46个健康生活小常识
- NLP 中文形近字相似度算法开源实现
- 世界上最遥远的距离,不是生与死,而是我心与你心之间的距离。
- spring基于5.3.0GA版本-笔记
- linux中main数据手册,linux中main()函数中参数来源.doc
- 基于java网上租贸系统计算机毕业设计源码+系统+lw文档+mysql数据库+调试部署
- Java 在线运行编译【运行 Java 代码工具推荐】
- Android中的RxJava