Apache MINA 框架之Filters介绍

IoFilter是NIMA框架核心组员之一,扮演者重要角色。它过滤所有IoService和IoHandler之间的I/O事件和请求。

一些典型且经常使用的过滤器:

  • LoggingFilter 记录所有事件和请求。
  • ProtocolCodecFilter 将传入消息ByteBuffer POJO,反之亦然。
  • CompressionFilter 压缩数据。
  • SSLFilter 添加SSL - TLS - StartTLS支持。

 

已经实现的Filter接口:

FilterclassDescription
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 

 

重载事件:

通过实现IoFilter IoAdapter直接替换已有的事件实现,

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

 

 

转载于:https://www.cnblogs.com/quyongjin/archive/2013/06/14/3135835.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值