Class DefaultIoFilterChain

java.lang.Object
org.apache.mina.core.filterchain.DefaultIoFilterChain
All Implemented Interfaces:
IoFilterChain
Direct Known Subclasses:
VmPipeFilterChain

public class DefaultIoFilterChain extends Object implements IoFilterChain
A default implementation of IoFilterChain that provides all operations for developers who want to implement their own transport layer once used with AbstractIoSession.
  • Field Details

  • Constructor Details

    • DefaultIoFilterChain

      public DefaultIoFilterChain(AbstractIoSession session)
      Create a new default chain, associated with a session. It will only contain a HeadFilter and a TailFilter.
      Parameters:
      session - The session associated with the created filter chain
  • Method Details

    • getSession

      public IoSession getSession()
      Specified by:
      getSession in interface IoFilterChain
      Returns:
      the parent IoSession of this chain.
    • getEntry

      public IoFilterChain.Entry getEntry(String name)
      Returns the IoFilterChain.Entry with the specified name in this chain.
      Specified by:
      getEntry in interface IoFilterChain
      Parameters:
      name - The filter's name we are looking for
      Returns:
      null if there's no such name in this chain
    • getEntry

      public IoFilterChain.Entry getEntry(IoFilter filter)
      Returns the IoFilterChain.Entry with the specified filter in this chain.
      Specified by:
      getEntry in interface IoFilterChain
      Parameters:
      filter - The Filter we are looking for
      Returns:
      null if there's no such filter in this chain
    • getEntry

      public IoFilterChain.Entry getEntry(Class<? extends IoFilter> filterType)
      Returns the IoFilterChain.Entry with the specified filterType in this chain. If there's more than one filter with the specified type, the first match will be chosen.
      Specified by:
      getEntry in interface IoFilterChain
      Parameters:
      filterType - The filter class we are looking for
      Returns:
      null if there's no such name in this chain
    • get

      public IoFilter get(String name)
      Returns the IoFilter with the specified name in this chain.
      Specified by:
      get in interface IoFilterChain
      Parameters:
      name - the filter's name
      Returns:
      null if there's no such name in this chain
    • get

      public IoFilter get(Class<? extends IoFilter> filterType)
      Returns the IoFilter with the specified filterType in this chain. If there's more than one filter with the specified type, the first match will be chosen.
      Specified by:
      get in interface IoFilterChain
      Parameters:
      filterType - The filter class
      Returns:
      null if there's no such name in this chain
    • getNextFilter

      public IoFilter.NextFilter getNextFilter(String name)
      Returns the IoFilter.NextFilter of the IoFilter with the specified name in this chain.
      Specified by:
      getNextFilter in interface IoFilterChain
      Parameters:
      name - The filter's name we want the next filter
      Returns:
      null if there's no such name in this chain
    • getNextFilter

      public IoFilter.NextFilter getNextFilter(IoFilter filter)
      Returns the IoFilter.NextFilter of the specified IoFilter in this chain.
      Specified by:
      getNextFilter in interface IoFilterChain
      Parameters:
      filter - The filter for which we want the next filter
      Returns:
      null if there's no such name in this chain
    • getNextFilter

      public IoFilter.NextFilter getNextFilter(Class<? extends IoFilter> filterType)
      Returns the IoFilter.NextFilter of the specified filterType in this chain. If there's more than one filter with the specified type, the first match will be chosen.
      Specified by:
      getNextFilter in interface IoFilterChain
      Parameters:
      filterType - The Filter class for which we want the next filter
      Returns:
      null if there's no such name in this chain
    • addFirst

      public void addFirst(String name, IoFilter filter)
      Adds the specified filter with the specified name at the beginning of this chain.
      Specified by:
      addFirst in interface IoFilterChain
      Parameters:
      name - The filter's name
      filter - The filter to add
    • addLast

      public void addLast(String name, IoFilter filter)
      Adds the specified filter with the specified name at the end of this chain.
      Specified by:
      addLast in interface IoFilterChain
      Parameters:
      name - The filter's name
      filter - The filter to add
    • addBefore

      public void addBefore(String baseName, String name, IoFilter filter)
      Adds the specified filter with the specified name just before the filter whose name is baseName in this chain.
      Specified by:
      addBefore in interface IoFilterChain
      Parameters:
      baseName - The targeted Filter's name
      name - The filter's name
      filter - The filter to add
    • addAfter

      public void addAfter(String baseName, String name, IoFilter filter)
      Adds the specified filter with the specified name just after the filter whose name is baseName in this chain.
      Specified by:
      addAfter in interface IoFilterChain
      Parameters:
      baseName - The targeted Filter's name
      name - The filter's name
      filter - The filter to add
    • remove

      public IoFilter remove(String name)
      Removes the filter with the specified name from this chain.
      Specified by:
      remove in interface IoFilterChain
      Parameters:
      name - The name of the filter to remove
      Returns:
      The removed filter
    • remove

      public void remove(IoFilter filter)
      Replace the filter with the specified name with the specified new filter.
      Specified by:
      remove in interface IoFilterChain
      Parameters:
      filter - The filter to remove
    • remove

      public IoFilter remove(Class<? extends IoFilter> filterType)
      Replace the filter of the specified type with the specified new filter. If there's more than one filter with the specified type, the first match will be replaced.
      Specified by:
      remove in interface IoFilterChain
      Parameters:
      filterType - The filter class to remove
      Returns:
      The removed filter
    • replace

      public IoFilter replace(String name, IoFilter newFilter)
      Replace the filter with the specified name with the specified new filter.
      Specified by:
      replace in interface IoFilterChain
      Parameters:
      name - The name of the filter we want to replace
      newFilter - The new filter
      Returns:
      the old filter
    • replace

      public void replace(IoFilter oldFilter, IoFilter newFilter)
      Replace the filter with the specified name with the specified new filter.
      Specified by:
      replace in interface IoFilterChain
      Parameters:
      oldFilter - The filter we want to replace
      newFilter - The new filter
    • replace

      public IoFilter replace(Class<? extends IoFilter> oldFilterType, IoFilter newFilter)
      Replace the filter of the specified type with the specified new filter. If there's more than one filter with the specified type, the first match will be replaced.
      Specified by:
      replace in interface IoFilterChain
      Parameters:
      oldFilterType - The filter class we want to replace
      newFilter - The new filter
      Returns:
      The replaced IoFilter
    • clear

      public void clear() throws Exception
      Removes all filters added to this chain.
      Specified by:
      clear in interface IoFilterChain
      Throws:
      Exception - If we weren't able to clear the filters
    • register

      private void register(DefaultIoFilterChain.EntryImpl prevEntry, String name, IoFilter filter)
      Register the newly added filter, inserting it between the previous and the next filter in the filter's chain. We also call the preAdd and postAdd methods.
    • deregister

      private void deregister(DefaultIoFilterChain.EntryImpl entry)
    • deregister0

      private void deregister0(DefaultIoFilterChain.EntryImpl entry)
    • checkOldName

      private DefaultIoFilterChain.EntryImpl checkOldName(String baseName)
      Throws an exception when the specified filter name is not registered in this chain.
      Returns:
      An filter entry with the specified name.
    • checkAddable

      private void checkAddable(String name)
      Checks the specified filter name is already taken and throws an exception if already taken.
    • fireSessionCreated

      public void fireSessionCreated()
      Fires a IoHandler.sessionCreated(IoSession) event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.
      Specified by:
      fireSessionCreated in interface IoFilterChain
    • callNextSessionCreated

      private void callNextSessionCreated(IoFilterChain.Entry entry, IoSession session)
    • fireSessionOpened

      public void fireSessionOpened()
      Fires a IoHandler.sessionOpened(IoSession) event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.
      Specified by:
      fireSessionOpened in interface IoFilterChain
    • fireEvent

      public void fireEvent(FilterEvent event)
      Fires a IoHandler.event(IoSession, FilterEvent) event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.
      Specified by:
      fireEvent in interface IoFilterChain
      Parameters:
      event - The specific event being fired
    • callNextSessionOpened

      private void callNextSessionOpened(IoFilterChain.Entry entry, IoSession session)
    • fireSessionClosed

      public void fireSessionClosed()
      Fires a IoHandler.sessionClosed(IoSession) event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.
      Specified by:
      fireSessionClosed in interface IoFilterChain
    • callNextSessionClosed

      private void callNextSessionClosed(IoFilterChain.Entry entry, IoSession session)
    • fireSessionIdle

      public void fireSessionIdle(IdleStatus status)
      Fires a IoHandler.sessionIdle(IoSession, IdleStatus) event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.
      Specified by:
      fireSessionIdle in interface IoFilterChain
      Parameters:
      status - The current status to propagate
    • callNextSessionIdle

      private void callNextSessionIdle(IoFilterChain.Entry entry, IoSession session, IdleStatus status)
    • fireMessageReceived

      public void fireMessageReceived(Object message)
      Fires a IoHandler.messageReceived(IoSession, Object) event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.
      Specified by:
      fireMessageReceived in interface IoFilterChain
      Parameters:
      message - The received message
    • callNextMessageReceived

      private void callNextMessageReceived(IoFilterChain.Entry entry, IoSession session, Object message)
    • fireMessageSent

      public void fireMessageSent(WriteRequest request)
      Fires a IoHandler.messageSent(IoSession, Object) event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.
      Specified by:
      fireMessageSent in interface IoFilterChain
      Parameters:
      request - The sent request
    • callNextMessageSent

      private void callNextMessageSent(IoFilterChain.Entry entry, IoSession session, WriteRequest writeRequest)
    • fireExceptionCaught

      public void fireExceptionCaught(Throwable cause)
      Fires a IoHandler.exceptionCaught(IoSession, Throwable) event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.
      Specified by:
      fireExceptionCaught in interface IoFilterChain
      Parameters:
      cause - The exception cause
    • callNextExceptionCaught

      private void callNextExceptionCaught(IoFilterChain.Entry entry, IoSession session, Throwable cause)
    • fireInputClosed

      public void fireInputClosed()
      Fires a IoHandler.inputClosed(IoSession) event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.
      Specified by:
      fireInputClosed in interface IoFilterChain
    • callNextInputClosed

      private void callNextInputClosed(IoFilterChain.Entry entry, IoSession session)
    • fireFilterWrite

      public void fireFilterWrite(WriteRequest writeRequest)
      Fires a IoSession.write(Object) event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.
      Specified by:
      fireFilterWrite in interface IoFilterChain
      Parameters:
      writeRequest - The message to write
    • callPreviousFilterWrite

      private void callPreviousFilterWrite(IoFilterChain.Entry entry, IoSession session, WriteRequest writeRequest)
    • fireFilterClose

      public void fireFilterClose()
      Fires a IoSession.closeNow() or a IoSession.closeOnFlush() event. Most users don't need to call this method at all. Please use this method only when you implement a new transport or fire a virtual event.
      Specified by:
      fireFilterClose in interface IoFilterChain
    • callPreviousFilterClose

      private void callPreviousFilterClose(IoFilterChain.Entry entry, IoSession session)
    • callNextFilterEvent

      private void callNextFilterEvent(IoFilterChain.Entry entry, IoSession session, FilterEvent event)
    • getAll

      public List<IoFilterChain.Entry> getAll()
      Specified by:
      getAll in interface IoFilterChain
      Returns:
      The list of all IoFilterChain.Entrys this chain contains.
    • getAllReversed

      public List<IoFilterChain.Entry> getAllReversed()
      Specified by:
      getAllReversed in interface IoFilterChain
      Returns:
      The reversed list of all IoFilterChain.Entrys this chain contains.
    • contains

      public boolean contains(String name)
      Specified by:
      contains in interface IoFilterChain
      Parameters:
      name - The filter's name we are looking for
      Returns:
      true if this chain contains an IoFilter with the specified name.
    • contains

      public boolean contains(IoFilter filter)
      Specified by:
      contains in interface IoFilterChain
      Parameters:
      filter - The filter we are looking for
      Returns:
      true if this chain contains the specified filter.
    • contains

      public boolean contains(Class<? extends IoFilter> filterType)
      Specified by:
      contains in interface IoFilterChain
      Parameters:
      filterType - The filter's class we are looking for
      Returns:
      true if this chain contains an IoFilter of the specified filterType.
    • toString

      public String toString()
      Overrides:
      toString in class Object