Mina文档 - 图文(3)

2019-03-04 13:23

TextLineEncoder(Charset charset) 创建一个带有字符编码的实例 TextLineEncoder(Charset charset, delimiter) 创建一个带有字符编码和分隔符的实例 LineDelimiter TextLineEncoder(LineDelimiter delimiter) 创建一个带有分隔符的实例 新增方法 int getMaxLineLength() Returns the allowed maximum size of the encoded line. 返回每行的最大限制。 void setMaxLineLength(int maxLineLength) Sets the allowed maximum size of the encoded line. 设置每行的最大限制。

协议解码器(ProtocolDecoder)将二进制或特殊协议数据解码成高级的信息对象。MINA会对读出的数据调用decode函数,然后解码器会将经过解码处理过的消息通过ProtocolDecoderOutput函数送出,到达过滤器链中的下个过滤器。

ProtocolDecoder中的方法 void decode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) 将二进制或特殊的协议数据解码成高级的消息对象。 void dispose(IoSession session) 释放与这个解码器相关的所有资源。 void finishDecode(IoSession session, ProtocolDecoderOutput out) 当指定session回话关闭时调用此方法 ProtocolDecoder的实现类 NettyDecoder 该解码器通过使用指定MessageRecognizer可以将字节缓存解码成Netty2信息。 构造方法 NettyDecoder(net.gleamynode.netty2.MessageRecognizer recognizer) 创建一个带有指定MessageRecognizer的实例。 ObjectSerializationDecoder 该编码器通过ByteBuffer.getObject(Object)可以解码普通的java类 构造方法 ObjectSerializationDecoder() Creates a new instance with the ClassLoader of the current thread. 创建一个新的实例,使用当前线程的ClassLoader ObjectSerializationDecoder(ClassLoader classLoader) Creates a new instance with the specified ClassLoader. 创建一个带有指定ClassLoader的实例。 新增方法 int getMaxObjectSize() Returns the allowed maximum size of the encoded object. 返回允许被解码的Object的最大限制 void setMaxObjectSize(int axObjectSize) Sets the allowed maximum size of the encoded object. 设置允许被解码的Object的最大限制 ProtocolDecoderAdapter ProtoclDecoder适配器。 SynchronizedProtocolDecoder, 线程方面的。 TextLineDecoder 该解码器可以将一行一行的文本解码成字符串。 构造方法 TextLineDecoder() TextLineDecoder(Charset charset) 创建一个带有字符编码的实例 TextLineDecoder(Charset charset, LineDelimiter delimiter) 创建一个带有字符编码和分隔符的实例 TextLineDecoder(LineDelimiter delimiter) 创建一个带有分隔符的实例 新增方法 int getMaxLineLength() Returns the allowed maximum size of the encoded line. 返回每行的最大限制。 void setMaxLineLength(int maxLineLength) Sets the allowed maximum size of the encoded line. 设置每行的最大限制。 CumulativeProtocolDecoder 累计解码器,该解码器可以根据协议来解析当前数据是否为完整的数据,如果不完整的话,解码器会将当前数据保存到buffer中,然后等待后续的数据,知道所有的数据都到达后才将完整的数据一并送出。 示例程序: 协议编解码工厂(ProtocolCodecFactory)提供编码解码器,可以实现字节与高级信息之间的相互转换。

方法 ProtocolDecoder getDecoder() 获取一个解码器 ProtocolEncoder getEncoder() 获取一个编码器 ProtocolCodecFactory的实现类 DemuxingProtocolCodecFactory NettyCodecFactory 提供基于Netty2信息的编解码器 ObjectSerializationCodecFactory 用来处理Object的编解码器。 TextLineCodecFactory 用来处理字符串的编解码器。 消息编码器(MessageEncoder)编码指定类型的消息。

Method Summary void encode(IoSession session, Object message, ProtocolEncoderOutput out) Encodes higher-level message objects into binary or protocol-specific data. 将高级信息编码成字节活特殊协议数据。 Set> getMessageTypes() Returns the set of message classes this encoder can encode. 获取这个编码器能够编码的消息类型

消息解码器(MessageDecoder)解码指定类型的消息

Field Summary Static NEED_DATA MessageDecoderResult 描述decodable(IoSession, ByteBuffer) 和 decode(IoSession, ByteBuffer, ProtocolDecoderOutput)的返回值 Static NOT_OK MessageDecoderResult 描述decodable(IoSession, ByteBuffer) 和 decode(IoSession, ByteBuffer, ProtocolDecoderOutput)的返回值 Static OK MessageDecoderResult 描述decodable(IoSession, ByteBuffer) 和 decode(IoSession, ByteBuffer, ProtocolDecoderOutput)的返回值

方法 MessageDecoderResult decodable(IoSession session, ByteBuffer in) 检查指定的buffer是否能被此解码器解码。 MessageDecoderResult decode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) 将字节或特殊协议内容解码成高级消息对象。 void finishDecode(IoSession session, ProtocolDecoderOutput out) Invoked when the specified session is closed while this decoder was parsing the data. 当指定Session回话关闭时调用此方法。

CompressionFilter(数据压缩过滤器) SSLFilter(SSL过滤器)

ExecutorFilter(线程执行过滤器)

ReferenceCountingIoFilter()具体叫什么名字翻译不上来,该过滤器的作用就是管理所有的过滤器,在某个过滤器不处于过滤器链中时调用disdroy()方法来销毁该过滤器,

以释放其占用的资源。在某个过滤器被添加到过滤器链时,调用init()方法来初始化该过滤器,为其分配资源。

StreamWriteFilter(输入流过滤器)使用此过滤器后可以通过IoSession.write(Object)直接向远程写InputStream。当一个输入流写入到session中后这个过滤器会从这个输入流中读取字节,放到ByteBuffer中,然后将这个ByteBuffer写入到下个过滤器中。当输入流被读完后,过滤器会调用NextFilter#messageSent(IoSession, Object)将原始的输入流写入到session,然后通过原始的IoFilter.WriteRequest通知WriteFuture。这个过滤器会忽略那些不是输入流的信息,这样的信息会直接被转送到下个过滤器。

应当注意的是这个过滤器不负责关闭输入流,我们应当在IoHandler.messageSent()的回调函数中关闭它。

程序见附件:

3.7 IoServiceListener监听器

IoServiceListener监听器的作用是监听其对应的IoService(IoAcceptor和IoConnector)中的事件。

Method Summary void serviceActivated(IoService service, SocketAddress serviceAddress, IoHandler handler, IoServiceConfig config) Invoked when a new service is activated by an IoService. 当一个新的service被激活时调用此方法 void serviceDeactivated(IoService service, SocketAddress IoHandler handler, IoServiceConfig config) Invoked when a service is deactivated by an IoService. 当一个service被销毁解除时调用此方法 serviceAddress, void sessionCreated(IoSession session) Invoked when a new session is created by an IoService. 当一个新的session建立时调用此方法 void sessionDestroyed(IoSession session) Invoked when a session is being destroyed by an IoService. 当一个session被销毁时调用此方法。 IoFutureListener监听器的作用是用来监听指定的IoFuture.


Mina文档 - 图文(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:C语言期末笔试2009年1月A

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: