Package org.apache.mina.core.filterchain
Interface IoFilter
-
- All Known Implementing Classes:
AbstractStreamWriteFilter,BlacklistFilter,BufferedWriteFilter,CommonEventFilter,ConnectionThrottleFilter,ErrorGeneratingFilter,ExecutorFilter,FileRegionWriteFilter,IoFilterAdapter,KeepAliveFilter,LoggingFilter,MdcInjectionFilter,NoopFilter,ProfilerTimerFilter,ProtocolCodecFilter,ProxyFilter,ReferenceCountingFilter,SaslFilter,SessionAttributeInitializingFilter,SslFilter,StreamWriteFilter,WriteRequestFilter
public interface IoFilterA filter which interceptsIoHandlerevents 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 insideIoFilterChain.When you add an
IoFilterto anIoFilterChain:init()is invoked byReferenceCountingFilterif 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.core.filterchain.IoFilter.NextFilter)threw an exception.destroy()is also invoked byReferenceCountingFilterif the filter is the last filter which was added toIoFilterChains.
When you remove an
IoFilterfrom anIoFilterChain: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 byReferenceCountingFilterif the removed filter was the last one.
- Author:
- Apache MINA Project
- See Also:
IoFilterAdapter
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceIoFilter.NextFilterRepresents the nextIoFilterinIoFilterChain.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voiddestroy()Invoked byReferenceCountingFilterwhen this filter is not used by anyIoFilterChainanymore, so you can destroy shared resources.voidevent(IoFilter.NextFilter nextFilter, IoSession session, FilterEvent event)Propagate an event up to theIoHandlervoidexceptionCaught(IoFilter.NextFilter nextFilter, IoSession session, Throwable cause)FiltersIoHandler.exceptionCaught(IoSession,Throwable)event.voidfilterClose(IoFilter.NextFilter nextFilter, IoSession session)FiltersIoSession.closeNow()or aIoSession.closeOnFlush()method invocations.voidfilterWrite(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest)FiltersIoSession.write(Object)method invocation.voidinit()Invoked byReferenceCountingFilterwhen this filter is added to aIoFilterChainat the first time, so you can initialize shared resources.voidinputClosed(IoFilter.NextFilter nextFilter, IoSession session)FiltersIoHandler.inputClosed(IoSession)event.voidmessageReceived(IoFilter.NextFilter nextFilter, IoSession session, Object message)FiltersIoHandler.messageReceived(IoSession,Object)event.voidmessageSent(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest)FiltersIoHandler.messageSent(IoSession,Object)event.voidonPostAdd(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter)Invoked after this filter is added to the specifiedparent.voidonPostRemove(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter)Invoked after this filter is removed from the specifiedparent.voidonPreAdd(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter)Invoked before this filter is added to the specifiedparent.voidonPreRemove(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter)Invoked before this filter is removed from the specifiedparent.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 Detail
-
init
void init() throws Exception
Invoked byReferenceCountingFilterwhen 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 withReferenceCountingFilter.- Throws:
Exception- If an error occurred while processing the event
-
destroy
void destroy() throws ExceptionInvoked byReferenceCountingFilterwhen 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 withReferenceCountingFilter.- Throws:
Exception- If an error occurred while processing the event
-
onPreAdd
void onPreAdd(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter) throws Exception
Invoked before this filter is added to the specifiedparent. 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- If an error occurred while processing the event
-
onPostAdd
void onPostAdd(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter) throws Exception
Invoked after this filter is added to the specifiedparent. 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- If an error occurred while processing the event
-
onPreRemove
void onPreRemove(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter) throws Exception
Invoked before this filter is removed from the specifiedparent. 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- If an error occurred while processing the event
-
onPostRemove
void onPostRemove(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter) throws Exception
Invoked after this filter is removed from the specifiedparent. 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- If an error occurred while processing the event
-
sessionCreated
void sessionCreated(IoFilter.NextFilter nextFilter, IoSession session) throws Exception
FiltersIoHandler.sessionCreated(IoSession)event.- Parameters:
nextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has received this event- Throws:
Exception- If an error occurred while processing the event
-
sessionOpened
void sessionOpened(IoFilter.NextFilter nextFilter, IoSession session) throws Exception
FiltersIoHandler.sessionOpened(IoSession)event.- Parameters:
nextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has received this event- Throws:
Exception- If an error occurred while processing the event
-
sessionClosed
void sessionClosed(IoFilter.NextFilter nextFilter, IoSession session) throws Exception
FiltersIoHandler.sessionClosed(IoSession)event.- Parameters:
nextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has received this event- Throws:
Exception- If an error occurred while processing the event
-
sessionIdle
void sessionIdle(IoFilter.NextFilter nextFilter, IoSession session, IdleStatus status) throws Exception
FiltersIoHandler.sessionIdle(IoSession,IdleStatus)event.- Parameters:
nextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has received this eventstatus- TheIdleStatustype- Throws:
Exception- If an error occurred while processing the event
-
exceptionCaught
void exceptionCaught(IoFilter.NextFilter nextFilter, IoSession session, Throwable cause) throws Exception
FiltersIoHandler.exceptionCaught(IoSession,Throwable)event.- Parameters:
nextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has received this eventcause- The exception that cause this event to be received- Throws:
Exception- If an error occurred while processing the event
-
inputClosed
void inputClosed(IoFilter.NextFilter nextFilter, IoSession session) throws Exception
FiltersIoHandler.inputClosed(IoSession)event.- Parameters:
nextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has received this event- Throws:
Exception- If an error occurred while processing the event
-
messageReceived
void messageReceived(IoFilter.NextFilter nextFilter, IoSession session, Object message) throws Exception
FiltersIoHandler.messageReceived(IoSession,Object)event.- Parameters:
nextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has received this eventmessage- The received message- Throws:
Exception- If an error occurred while processing the event
-
messageSent
void messageSent(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception
FiltersIoHandler.messageSent(IoSession,Object)event.- Parameters:
nextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has received this eventwriteRequest- TheWriteRequestthat contains the sent message- Throws:
Exception- If an error occurred while processing the event
-
filterClose
void filterClose(IoFilter.NextFilter nextFilter, IoSession session) throws Exception
FiltersIoSession.closeNow()or aIoSession.closeOnFlush()method invocations.- Parameters:
nextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has to process this method invocation- Throws:
Exception- If an error occurred while processing the event
-
filterWrite
void filterWrite(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception
FiltersIoSession.write(Object)method invocation.- Parameters:
nextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has to process this invocationwriteRequest- TheWriteRequestto process- Throws:
Exception- If an error occurred while processing the event
-
event
void event(IoFilter.NextFilter nextFilter, IoSession session, FilterEvent event) throws Exception
Propagate an event up to theIoHandler- Parameters:
nextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has to process this invocationevent- The event to propagate- Throws:
Exception- If an error occurred while processing the event
-
-