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:

  1. init() is invoked by ReferenceCountingIoFilter if the filter is added at the first time.
  2. onPreAdd(IoFilterChain, String, NextFilter) is invoked to notify that the filter will be added to the chain.
  3. The filter is added to the chain, and all events and I/O requests pass through the filter from now.
  4. onPostAdd(IoFilterChain, String, NextFilter) is invoked to notify that the filter is added to the chain.
  5. The filter is removed from the chain if onPostAdd(IoFilterChain, String, org.apache.mina.common.IoFilter.NextFilter) threw an exception. destroy() is also invoked by ReferenceCountingIoFilter if the filter is the last filter which was added to IoFilterChains.

When you remove an IoFilter from an IoFilterChain:

  1. onPreRemove(IoFilterChain, String, NextFilter) is invoked to notify that the filter will be removed from the chain.
  2. The filter is removed from the chain, and any events and I/O requests don't pass through the filter from now.
  3. onPostRemove(IoFilterChain, String, NextFilter) is invoked to notify that the filter is removed from the chain.
  4. destroy() is invoked by ReferenceCountingIoFilter if the removed filter was the last one.
See Also: