Package org.apache.mina.common
Interface IoFilter
-
- All Known Implementing Classes:
BlacklistFilter
,ExecutorFilter
,IoFilterAdapter
,LoggingFilter
,ProtocolCodecFilter
,ReferenceCountingIoFilter
,StreamWriteFilter
public interface IoFilter
A filter which interceptsIoHandler
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
IoSession
s. Users can cache the reference to the session, which might malfunction if any filters are added or removed later.The Life Cycle
IoFilter
s are activated only when they are insideIoFilterChain
.When you add an
IoFilter
to anIoFilterChain
:init()
is invoked byReferenceCountingIoFilter
if 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 byReferenceCountingIoFilter
if the filter is the last filter which was added toIoFilterChain
s.
When you remove an
IoFilter
from 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 byReferenceCountingIoFilter
if the removed filter was the last one.
- See Also:
IoFilterAdapter
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
IoFilter.NextFilter
Represents the nextIoFilter
inIoFilterChain
.static class
IoFilter.WriteRequest
Represents write request fired byIoSession.write(Object)
.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
destroy()
Invoked byReferenceCountingIoFilter
when this filter is not used by anyIoFilterChain
anymore, so you can destroy shared resources.void
exceptionCaught(IoFilter.NextFilter nextFilter, IoSession session, java.lang.Throwable cause)
FiltersIoHandler.exceptionCaught(IoSession,Throwable)
event.void
filterClose(IoFilter.NextFilter nextFilter, IoSession session)
FiltersIoSession.close()
method invocation.void
filterWrite(IoFilter.NextFilter nextFilter, IoSession session, IoFilter.WriteRequest writeRequest)
FiltersIoSession.write(Object)
method invocation.void
init()
Invoked byReferenceCountingIoFilter
when this filter is added to aIoFilterChain
at the first time, so you can initialize shared resources.void
messageReceived(IoFilter.NextFilter nextFilter, IoSession session, java.lang.Object message)
FiltersIoHandler.messageReceived(IoSession,Object)
event.void
messageSent(IoFilter.NextFilter nextFilter, IoSession session, java.lang.Object message)
FiltersIoHandler.messageSent(IoSession,Object)
event.void
onPostAdd(IoFilterChain parent, java.lang.String name, IoFilter.NextFilter nextFilter)
Invoked after this filter is added to the specified parent.void
onPostRemove(IoFilterChain parent, java.lang.String name, IoFilter.NextFilter nextFilter)
Invoked after this filter is removed from the specified parent.void
onPreAdd(IoFilterChain parent, java.lang.String name, IoFilter.NextFilter nextFilter)
Invoked before this filter is added to the specified parent.void
onPreRemove(IoFilterChain parent, java.lang.String name, IoFilter.NextFilter nextFilter)
Invoked before this filter is removed from the specified parent.void
sessionClosed(IoFilter.NextFilter nextFilter, IoSession session)
FiltersIoHandler.sessionClosed(IoSession)
event.void
sessionCreated(IoFilter.NextFilter nextFilter, IoSession session)
FiltersIoHandler.sessionCreated(IoSession)
event.void
sessionIdle(IoFilter.NextFilter nextFilter, IoSession session, IdleStatus status)
FiltersIoHandler.sessionIdle(IoSession,IdleStatus)
event.void
sessionOpened(IoFilter.NextFilter nextFilter, IoSession session)
FiltersIoHandler.sessionOpened(IoSession)
event.
-
-
-
Method Detail
-
init
void init() throws java.lang.Exception
Invoked byReferenceCountingIoFilter
when this filter is added to aIoFilterChain
at 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:
java.lang.Exception
-
destroy
void destroy() throws java.lang.Exception
Invoked byReferenceCountingIoFilter
when this filter is not used by anyIoFilterChain
anymore, so you can destroy shared resources. Please note that this method is never called if you don't wrap a filter withReferenceCountingIoFilter
.- Throws:
java.lang.Exception
-
onPreAdd
void onPreAdd(IoFilterChain parent, java.lang.String name, IoFilter.NextFilter nextFilter) throws java.lang.Exception
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.NextFilter
for this filter. You can reuse this object until this filter is removed from the chain.- Throws:
java.lang.Exception
-
onPostAdd
void onPostAdd(IoFilterChain parent, java.lang.String name, IoFilter.NextFilter nextFilter) throws java.lang.Exception
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.NextFilter
for this filter. You can reuse this object until this filter is removed from the chain.- Throws:
java.lang.Exception
-
onPreRemove
void onPreRemove(IoFilterChain parent, java.lang.String name, IoFilter.NextFilter nextFilter) throws java.lang.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.NextFilter
for this filter. You can reuse this object until this filter is removed from the chain.- Throws:
java.lang.Exception
-
onPostRemove
void onPostRemove(IoFilterChain parent, java.lang.String name, IoFilter.NextFilter nextFilter) throws java.lang.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.NextFilter
for this filter. You can reuse this object until this filter is removed from the chain.- Throws:
java.lang.Exception
-
sessionCreated
void sessionCreated(IoFilter.NextFilter nextFilter, IoSession session) throws java.lang.Exception
FiltersIoHandler.sessionCreated(IoSession)
event.- Throws:
java.lang.Exception
-
sessionOpened
void sessionOpened(IoFilter.NextFilter nextFilter, IoSession session) throws java.lang.Exception
FiltersIoHandler.sessionOpened(IoSession)
event.- Throws:
java.lang.Exception
-
sessionClosed
void sessionClosed(IoFilter.NextFilter nextFilter, IoSession session) throws java.lang.Exception
FiltersIoHandler.sessionClosed(IoSession)
event.- Throws:
java.lang.Exception
-
sessionIdle
void sessionIdle(IoFilter.NextFilter nextFilter, IoSession session, IdleStatus status) throws java.lang.Exception
FiltersIoHandler.sessionIdle(IoSession,IdleStatus)
event.- Throws:
java.lang.Exception
-
exceptionCaught
void exceptionCaught(IoFilter.NextFilter nextFilter, IoSession session, java.lang.Throwable cause) throws java.lang.Exception
FiltersIoHandler.exceptionCaught(IoSession,Throwable)
event.- Throws:
java.lang.Exception
-
messageReceived
void messageReceived(IoFilter.NextFilter nextFilter, IoSession session, java.lang.Object message) throws java.lang.Exception
FiltersIoHandler.messageReceived(IoSession,Object)
event.- Throws:
java.lang.Exception
-
messageSent
void messageSent(IoFilter.NextFilter nextFilter, IoSession session, java.lang.Object message) throws java.lang.Exception
FiltersIoHandler.messageSent(IoSession,Object)
event.- Throws:
java.lang.Exception
-
filterClose
void filterClose(IoFilter.NextFilter nextFilter, IoSession session) throws java.lang.Exception
FiltersIoSession.close()
method invocation.- Throws:
java.lang.Exception
-
filterWrite
void filterWrite(IoFilter.NextFilter nextFilter, IoSession session, IoFilter.WriteRequest writeRequest) throws java.lang.Exception
FiltersIoSession.write(Object)
method invocation.- Throws:
java.lang.Exception
-
-