概述
IoFilter是MINA的另外一个核心部分,他为IoService 和 IoHandler filters所有的I/O事件和请求,类似于web中的servlet filter.
在本教程中,我们会开发一个实际例子中的IoFilter,通常它很容易实现,但是你可能需要了解一些MINA内部的细节。
下面是一些已经存在着的Filter:
Filter | class | Description |
---|---|---|
Blacklist | BlacklistFilter | Blocks connections from blacklisted remote addresses |
Buffered Write | BufferedWriteFilter | Buffers outgoing requests like the BufferedOutputStream does |
Compression | CompressionFilter | |
ConnectionThrottle | ConnectionThrottleFilter | |
ErrorGenerating | ErrorGeneratingFilter | |
Executor | ExecutorFilter | |
FileRegionWrite | FileRegionWriteFilter | |
KeepAlive | KeepAliveFilter | |
Logging | LoggingFilter | Logs event messages, like MessageReceived, MessageSent, SessionOpened, ... |
MDC Injection | MdcInjectionFilter | Inject key IoSession properties into the MDC |
Noop | NoopFilter | A filter that does nothing. Useful for tests. |
Profiler | ProfilerTimerFilter | Profile event messages, like MessageReceived, MessageSent, SessionOpened, ... |
ProtocolCodec | ProtocolCodecFilter | A filter in charge of encoding and decoding messages |
Proxy | ProxyFilter | |
Reference counting | ReferenceCountingFilter | Keeps track of the number of usages of this filter |
RequestResponse | RequestResponseFilter | |
SessionAttributeInitializing | SessionAttributeInitializingFilter | |
StreamWrite | StreamWriteFilter | |
SslFilter | SslFilter | |
WriteRequest | WriteRequestFilter |
你可以继承IoAdapter代替直接实现的IoFilter,除非重写,否则任何接受到的事件都会被通过下面的filter:
public class MyFilter extends IoFilterAdapter {
@Override
public void sessionOpened(NextFilter nextFilter, IoSession session) throws Exception {
// Some logic here...
nextFilter.sessionOpened(session);
// Some other logic here...
}
}
Transforming a Write Request
Be Careful When Filtering sessionCreated Event
Watch out the Empty Buffers!
最后
以上就是炙热苗条为你收集整理的Apache Mina 学习笔记(4) - Filters的全部内容,希望文章能够帮你解决Apache Mina 学习笔记(4) - Filters所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复