我是靠谱客的博主 炙热苗条,最近开发中收集的这篇文章主要介绍Apache Mina 学习笔记(4) - Filters,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

IoFilter是MINA的另外一个核心部分,他为IoService 和 IoHandler filters所有的I/O事件和请求,类似于web中的servlet filter.

在本教程中,我们会开发一个实际例子中的IoFilter,通常它很容易实现,但是你可能需要了解一些MINA内部的细节。


下面是一些已经存在着的Filter:


Filter class Description
BlacklistBlacklistFilterBlocks connections from blacklisted remote addresses
Buffered WriteBufferedWriteFilterBuffers outgoing requests like the BufferedOutputStream does
CompressionCompressionFilter 
ConnectionThrottleConnectionThrottleFilter 
ErrorGeneratingErrorGeneratingFilter 
ExecutorExecutorFilter 
FileRegionWriteFileRegionWriteFilter 
KeepAliveKeepAliveFilter 
LoggingLoggingFilterLogs event messages, like MessageReceived, MessageSent, SessionOpened, ...
MDC InjectionMdcInjectionFilterInject key IoSession properties into the MDC
NoopNoopFilterA filter that does nothing. Useful for tests.
ProfilerProfilerTimerFilterProfile event messages, like MessageReceived, MessageSent, SessionOpened, ...
ProtocolCodecProtocolCodecFilterA filter in charge of encoding and decoding messages
ProxyProxyFilter 
Reference countingReferenceCountingFilterKeeps track of the number of usages of this filter
RequestResponseRequestResponseFilter 
SessionAttributeInitializingSessionAttributeInitializingFilter 
StreamWriteStreamWriteFilter 
SslFilterSslFilter 
WriteRequestWriteRequestFilter 

你可以继承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所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(41)

评论列表共有 0 条评论

立即
投稿
返回
顶部