【Mina】IoBuffer

Mina中采用Iobuffer,而不是Nio中的 ByteBuffer,说主要是以下2个原因:

 

  • It doesn't provide useful getters and putters such as fill, get/putString, and get/putAsciiInt() .
  • It is difficult to write variable-length data due to its fixed capacity

 

但是在3.0中要有所改变:说是用扩展的buffer其实是一个坏的决定;有很多其他的解决方式存在

1. 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:

如定义一个依赖于Nio buffers的包装类,,来代替copy已经有的bugger到一个更大的buffer中去,只是因为想扩展buffer容量

2.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...

也可以采用一个InputStream,在filter中代替byte buffer,它不指定存储的数据格式

3.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.

再一次,不是最后一个,当前的实现方法违反了一个原则: 0拷贝策略

 

------------------------------------------------------------------------

不管怎么样子,在这个版本中,还是要使用IoBuffer的

 

Iobuffer(abstractor class)的分配:

用allocate方法,2个参数:

1. capacity:buffer的大小,单位字节

2. direct :  type of buffer. true to get direct buffer, false to get heap buffer

 

IoBuffer的setAutoExpand,可以自动扩展buffer大小

setAutoShrink,可以通过shrink函数,把buffer自动收缩到当初设定的最小尺寸

------------------------------------------------------------------------


IoBufferAllocater:一个buffer相关的接口,

现在已有2个实现:

SimplebufferAllocator(default)

CachedbufferAllocator

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值