IoFilter
IoFilter is one of the MINA core constructs that serves a very important role. It filters all I/O events and requests between IoService and IoHandler. If you have an experience with web application programming, you can safely think that it's a cousin of Servlet filter. Many out-of-the-box filters are provided to accelerate network application development pace by simplifying typical cross-cutting concerns using the out-of-the-box filters such as:
IoFilter是MINA核心构造之一,扮演非常重要的角色。它过滤所有的I/O事件和请求,这些事件和请求由IoService最终到达IoHandler。假如你有web应用编程的经验,你确实可以把它比作Servlet filter。许多具有独特创意的filters被开发出来以加速网络应用的开发速度,简单、典型、横切关注点地使用这些filters,例如:
- LoggingFilter logs all events and requests.
LoggingFilter日志记录所有的事件和请求。
- ProtocolCodecFilter converts an incoming ByteBuffer into message POJO and vice versa.
ProtocolCodecFilter将接收的字节流转换为消息POJO等等。
- CompressionFilter compresses all data.
CompressionFilter压缩所有的数据。
- SSLFilter adds SSL - TLS - StartTLS support.
SSLFilter加入SSL-TLS-StartTLS支持。
- and many more!
还有很多!
It's easy to implement an IoFilter in general, but you might also need to know specifics of MINA internals. Any related internal properties will be explained here.
通常,实现一个IoFilter还是很容易的,但是你可能需要了解MINA的内部细节,以下介绍所有相关的内部内容。
Overriding Events Selectively
You can extend IoAdapter instead of implementing IoFilter directly. Unless overriden, any received events will be forward to the next filter immediately:
除了直接实现IoFilter,你也可以扩展IoAdapter。除了重载了的事件,任何接收事件都将立即转发到下一个filter。
Transforming a Write Request
If you are going to transform an incoming write request via IoSession.write(), things can get pretty tricky. For example, let's assume your filter transforms HighLevelMessage to LowLevelMessage when IoSession.write() is invoked with a HighLevelMessage object. You could insert appropriate transformation code to your filter's filterWrite() method and think that's all. However, you have to note that you also need to take care of messageSent event because an IoHandler or any filters next to yours will expect messageSent() method is called with HighLevelMessage as a parameter, because it's irrational for the caller to get notified that LowLevelMessage is sent when the caller actually wrote HighLevelMessage. Consequently, you have to implement both filterWrite() and messageSent() if your filter performs transformation.
Please also note that you still need to implement similar mechanism even if the types of the input object and the output object are identical (e.g. CompressionFilter) because the caller of IoSession.write() will expect exactly what he wrote in his or her messageSent() handler method.
分享到:
相关推荐
Apache Mina Server 2.0中文参考手册V1.0,Apache Mina2.0学习笔记(修订版)Apache Mina Server 2.0中文参考手册V1.0,Apache Mina2.0学习笔记(修订版)
本库是对我在项目中使用的Mina和长连接的一个封装,亲测有效,在网络良好的情况下,几乎能够保证100%的连接和通讯;
mina socket 的一个简单示例!
java mina 服务端,socket客服端传信息,客服端上传消息
mina2学习笔记
通过Mina与Socket实现通信,其包含客户端与服务端的实现代码
Apache mina socket通信源代码,版本为2.0.7
真的是学习MIna很好的资源,找了好久才找到的,看了很多相关的知识书籍,这本书真的不错。
这是一个关于mina框架非常全的自学文档
mina简单示例,Apache Mina Server 是一个网络通信应用框架,也就是说,它主要是对基于TCP/IP、UDP/IP协议栈的通信框架(当然,也可以提供JAVA 对象的序列化服务、虚拟机管道通信服务等),Mina 可以帮助我们快速...
Mina学习笔记。作者:李少华
1.mina socket客户度工程相关类,添加mina jar包后可独立运行。 2.mina若有空闲连接则使用已有连接,若无则新建mina连接; 3.mina空闲连接超过保活时间25分钟后,自动删除; 4.mina发送指令后,接收指定时长内收到的...
Apache_Mina_Server_ 深入教程V1.0Apache_Mina_Server_ 深入教程V1.0Apache_Mina_Server_ 深入教程V1.0Apache_Mina_Server_ 深入教程V1.0Apache_Mina_Server_ 深入教程V1.0
mina学习笔记,记录所有API,mina学习笔记,记录所有API
Apache的Mina(Multipurpose Infrastructure Networked Applications)是一个网络应用框架,可以帮助用户开发高性能和高扩展性的网络应用程序;它提供了一个抽象的、事件驱动的异步API,使Java NIO在各种传输协议...
基于Mina架构开发的可配置的Socket Server,后台采用MySql数据库,可以独立app部署或Tomcat Servlet部署,包括Socket Server全部实现代码,后台MySql数据备份文件,Java测试代码,android端测试代码和iOS端测试代码...
最近使用Mina开发一个Java的NIO服务端程序,因此也特意学习了Apache的这个Mina框架。 引言 1 一. Mina入门 2 第一步.下载使用的Jar包 2 第二步.工程创建配置 2 第三步.服务端程序 3 第四步.客户端程序 6 第五步.长...
这个是我学的apache mina2.0学习笔记的实例
NULL 博文链接:https://tangmingjie2009.iteye.com/blog/2036903
有关mina TCP Server 及协议报文结构解码器