Package org.apache.mina.common
Interface IoFilter
- All Known Implementing Classes:
BlacklistFilter,ExecutorFilter,IoFilterAdapter,LoggingFilter,ProtocolCodecFilter,ReferenceCountingIoFilter,StreamWriteFilter
public interface IoFilter
A filter which intercepts
IoHandler events like Servlet
filters. Filters can be used for these purposes:
- Event logging,
- Performance measurement,
- Authorization,
- Overload control,
- Message transformation (e.g. encryption and decryption, ...),
- and many more.
Please NEVER implement your filters to wrap
IoSessions. Users can cache the reference to the
session, which might malfunction if any filters are added or removed later.
The Life Cycle
IoFilters are activated only when they are inside IoFilterChain.
When you add an IoFilter to an IoFilterChain:
init()is invoked byReferenceCountingIoFilterif the filter is added at the first time.onPreAdd(IoFilterChain, String, NextFilter)is invoked to notify that the filter will be added to the chain.- The filter is added to the chain, and all events and I/O requests pass through the filter from now.
onPostAdd(IoFilterChain, String, NextFilter)is invoked to notify that the filter is added to the chain.- The filter is removed from the chain if
onPostAdd(IoFilterChain, String, org.apache.mina.common.IoFilter.NextFilter)threw an exception.destroy()is also invoked byReferenceCountingIoFilterif the filter is the last filter which was added toIoFilterChains.
When you remove an IoFilter from an IoFilterChain:
onPreRemove(IoFilterChain, String, NextFilter)is invoked to notify that the filter will be removed from the chain.- The filter is removed from the chain, and any events and I/O requests don't pass through the filter from now.
onPostRemove(IoFilterChain, String, NextFilter)is invoked to notify that the filter is removed from the chain.destroy()is invoked byReferenceCountingIoFilterif the removed filter was the last one.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceRepresents the nextIoFilterinIoFilterChain.static classRepresents write request fired byIoSession.write(Object). -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Invoked byReferenceCountingIoFilterwhen this filter is not used by anyIoFilterChainanymore, so you can destroy shared resources.voidexceptionCaught(IoFilter.NextFilter nextFilter, IoSession session, Throwable cause) FiltersIoHandler.exceptionCaught(IoSession,Throwable)event.voidfilterClose(IoFilter.NextFilter nextFilter, IoSession session) FiltersIoSession.close()method invocation.voidfilterWrite(IoFilter.NextFilter nextFilter, IoSession session, IoFilter.WriteRequest writeRequest) FiltersIoSession.write(Object)method invocation.voidinit()Invoked byReferenceCountingIoFilterwhen this filter is added to aIoFilterChainat the first time, so you can initialize shared resources.voidmessageReceived(IoFilter.NextFilter nextFilter, IoSession session, Object message) FiltersIoHandler.messageReceived(IoSession,Object)event.voidmessageSent(IoFilter.NextFilter nextFilter, IoSession session, Object message) FiltersIoHandler.messageSent(IoSession,Object)event.voidonPostAdd(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter) Invoked after this filter is added to the specified parent.voidonPostRemove(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter) Invoked after this filter is removed from the specified parent.voidonPreAdd(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter) Invoked before this filter is added to the specified parent.voidonPreRemove(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter) Invoked before this filter is removed from the specified parent.voidsessionClosed(IoFilter.NextFilter nextFilter, IoSession session) FiltersIoHandler.sessionClosed(IoSession)event.voidsessionCreated(IoFilter.NextFilter nextFilter, IoSession session) FiltersIoHandler.sessionCreated(IoSession)event.voidsessionIdle(IoFilter.NextFilter nextFilter, IoSession session, IdleStatus status) FiltersIoHandler.sessionIdle(IoSession,IdleStatus)event.voidsessionOpened(IoFilter.NextFilter nextFilter, IoSession session) FiltersIoHandler.sessionOpened(IoSession)event.
-
Method Details
-
init
Invoked byReferenceCountingIoFilterwhen this filter is added to aIoFilterChainat the first time, so you can initialize shared resources. Please note that this method is never called if you don't wrap a filter withReferenceCountingIoFilter.- Throws:
Exception
-
destroy
Invoked byReferenceCountingIoFilterwhen this filter is not used by anyIoFilterChainanymore, so you can destroy shared resources. Please note that this method is never called if you don't wrap a filter withReferenceCountingIoFilter.- Throws:
Exception
-
onPreAdd
Invoked before this filter is added to the specified parent. Please note that this method can be invoked more than once if this filter is added to more than one parents. This method is not invoked beforeinit()is invoked.- Parameters:
parent- the parent who called this methodname- the name assigned to this filternextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.- Throws:
Exception
-
onPostAdd
Invoked after this filter is added to the specified parent. Please note that this method can be invoked more than once if this filter is added to more than one parents. This method is not invoked beforeinit()is invoked.- Parameters:
parent- the parent who called this methodname- the name assigned to this filternextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.- Throws:
Exception
-
onPreRemove
void onPreRemove(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter) throws Exception Invoked before this filter is removed from the specified parent. Please note that this method can be invoked more than once if this filter is removed from more than one parents. This method is always invoked beforedestroy()is invoked.- Parameters:
parent- the parent who called this methodname- the name assigned to this filternextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.- Throws:
Exception
-
onPostRemove
void onPostRemove(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter) throws Exception Invoked after this filter is removed from the specified parent. Please note that this method can be invoked more than once if this filter is removed from more than one parents. This method is always invoked beforedestroy()is invoked.- Parameters:
parent- the parent who called this methodname- the name assigned to this filternextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.- Throws:
Exception
-
sessionCreated
FiltersIoHandler.sessionCreated(IoSession)event.- Throws:
Exception
-
sessionOpened
FiltersIoHandler.sessionOpened(IoSession)event.- Throws:
Exception
-
sessionClosed
FiltersIoHandler.sessionClosed(IoSession)event.- Throws:
Exception
-
sessionIdle
void sessionIdle(IoFilter.NextFilter nextFilter, IoSession session, IdleStatus status) throws Exception FiltersIoHandler.sessionIdle(IoSession,IdleStatus)event.- Throws:
Exception
-
exceptionCaught
void exceptionCaught(IoFilter.NextFilter nextFilter, IoSession session, Throwable cause) throws Exception FiltersIoHandler.exceptionCaught(IoSession,Throwable)event.- Throws:
Exception
-
messageReceived
void messageReceived(IoFilter.NextFilter nextFilter, IoSession session, Object message) throws Exception FiltersIoHandler.messageReceived(IoSession,Object)event.- Throws:
Exception
-
messageSent
void messageSent(IoFilter.NextFilter nextFilter, IoSession session, Object message) throws Exception FiltersIoHandler.messageSent(IoSession,Object)event.- Throws:
Exception
-
filterClose
FiltersIoSession.close()method invocation.- Throws:
Exception
-
filterWrite
void filterWrite(IoFilter.NextFilter nextFilter, IoSession session, IoFilter.WriteRequest writeRequest) throws Exception FiltersIoSession.write(Object)method invocation.- Throws:
Exception
-