org.apache.mina.filter.codec

## Class ProtocolCodecFilter

- java.lang.Object
- - org.apache.mina.core.filterchain.IoFilterAdapter
  - - org.apache.mina.filter.codec.ProtocolCodecFilter

- All Implemented Interfaces:
    IoFilter
  Direct Known Subclasses:
    HttpClientCodec, HttpServerCodec

      public class ProtocolCodecFilter
      extends IoFilterAdapter

  An `IoFilter` which translates binary or protocol specific data into message objects and vice versa using `ProtocolCodecFactory`, `ProtocolEncoder`, or `ProtocolDecoder`.
  Author:
    Apache MINA Project

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface org.apache.mina.core.filterchain.IoFilter

      `IoFilter.NextFilter`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ProtocolCodecFilter(Class<? extends ProtocolEncoder> encoderClass, Class<? extends ProtocolDecoder> decoderClass)` Creates a new instance of ProtocolCodecFilter, without any factory.
    `ProtocolCodecFilter(ProtocolCodecFactory factory)` Creates a new instance of ProtocolCodecFilter, associating a factory for the creation of the encoder and decoder.
    `ProtocolCodecFilter(ProtocolEncoder encoder, ProtocolDecoder decoder)` Creates a new instance of ProtocolCodecFilter, without any factory.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `filterWrite(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest)` Filters `IoSession.write(Object)` method invocation.
    `ProtocolEncoder` | `getEncoder(IoSession session)` Get the encoder instance from a given session.
    `void` | `messageReceived(IoFilter.NextFilter nextFilter, IoSession session, Object message)` Process the incoming message, calling the session decoder.
    `void` | `messageSent(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest)` Filters `IoHandler.messageSent(IoSession,Object)` event.
    `void` | `onPostRemove(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter)` Invoked after this filter is removed from the specified `parent`.
    `void` | `onPreAdd(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter)` Invoked before this filter is added to the specified `parent`.
    `void` | `sessionClosed(IoFilter.NextFilter nextFilter, IoSession session)` Filters `IoHandler.sessionClosed(IoSession)` event.

    - ### Methods inherited from class org.apache.mina.core.filterchain.IoFilterAdapter

      `destroy, exceptionCaught, filterClose, init, onPostAdd, onPreRemove, sessionCreated, sessionIdle, sessionOpened, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### ProtocolCodecFilter

          public ProtocolCodecFilter(ProtocolCodecFactory factory)

      Creates a new instance of ProtocolCodecFilter, associating a factory for the creation of the encoder and decoder.
      Parameters:
        `factory` - The associated factory

    - #### ProtocolCodecFilter

          public ProtocolCodecFilter(ProtocolEncoder encoder,
                             ProtocolDecoder decoder)

      Creates a new instance of ProtocolCodecFilter, without any factory. The encoder/decoder factory will be created as an inner class, using the two parameters (encoder and decoder).
      Parameters:
        `encoder` - The class responsible for encoding the message
        `decoder` - The class responsible for decoding the message

    - #### ProtocolCodecFilter

          public ProtocolCodecFilter(Class<? extends ProtocolEncoder> encoderClass,
                             Class<? extends ProtocolDecoder> decoderClass)

      Creates a new instance of ProtocolCodecFilter, without any factory. The encoder/decoder factory will be created as an inner class, using the two parameters (encoder and decoder), which are class names. Instances for those classes will be created in this constructor.
      Parameters:
        `encoder` - The class responsible for encoding the message
        `decoder` - The class responsible for decoding the message

  - ### Method Detail

    - #### getEncoder

          public ProtocolEncoder getEncoder(IoSession session)

      Get the encoder instance from a given session.
      Parameters:
        `session` - The associated session we will get the encoder from
      Returns:
        The encoder instance, if any

    - #### onPreAdd

          public void onPreAdd(IoFilterChain parent,
                      String name,
                      IoFilter.NextFilter nextFilter)
                        throws Exception

      Description copied from class: `IoFilterAdapter`
      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 before `IoFilter.init()` is invoked.
      Specified by:
        `onPreAdd` in interface `IoFilter`
      Overrides:
        `onPreAdd` in class `IoFilterAdapter`
      Parameters:
        `parent` - the parent who called this method
        `name` - the name assigned to this filter
        `nextFilter` - the `IoFilter.NextFilter` for this filter. You can reuse this object until this filter is removed from the chain.
      Throws:
        `Exception`

    - #### onPostRemove

          public void onPostRemove(IoFilterChain parent,
                          String name,
                          IoFilter.NextFilter nextFilter)
                            throws Exception

      Description copied from class: `IoFilterAdapter`
      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 before `IoFilter.destroy()` is invoked.
      Specified by:
        `onPostRemove` in interface `IoFilter`
      Overrides:
        `onPostRemove` in class `IoFilterAdapter`
      Parameters:
        `parent` - the parent who called this method
        `name` - the name assigned to this filter
        `nextFilter` - the `IoFilter.NextFilter` for this filter. You can reuse this object until this filter is removed from the chain.
      Throws:
        `Exception`

    - #### messageReceived

          public void messageReceived(IoFilter.NextFilter nextFilter,
                             IoSession session,
                             Object message)
                               throws Exception

      Process the incoming message, calling the session decoder. As the incoming buffer might contains more than one messages, we have to loop until the decoder throws an exception. while ( buffer not empty ) try decode ( buffer ) catch break;
      Specified by:
        `messageReceived` in interface `IoFilter`
      Overrides:
        `messageReceived` in class `IoFilterAdapter`
      Throws:
        `Exception`

    - #### messageSent

          public void messageSent(IoFilter.NextFilter nextFilter,
                         IoSession session,
                         WriteRequest writeRequest)
                           throws Exception

      Description copied from class: `IoFilterAdapter`
      Filters `IoHandler.messageSent(IoSession,Object)` event.
      Specified by:
        `messageSent` in interface `IoFilter`
      Overrides:
        `messageSent` in class `IoFilterAdapter`
      Throws:
        `Exception`

    - #### filterWrite

          public void filterWrite(IoFilter.NextFilter nextFilter,
                         IoSession session,
                         WriteRequest writeRequest)
                           throws Exception

      Description copied from class: `IoFilterAdapter`
      Filters `IoSession.write(Object)` method invocation.
      Specified by:
        `filterWrite` in interface `IoFilter`
      Overrides:
        `filterWrite` in class `IoFilterAdapter`
      Throws:
        `Exception`

    - #### sessionClosed

          public void sessionClosed(IoFilter.NextFilter nextFilter,
                           IoSession session)
                             throws Exception

      Description copied from class: `IoFilterAdapter`
      Filters `IoHandler.sessionClosed(IoSession)` event.
      Specified by:
        `sessionClosed` in interface `IoFilter`
      Overrides:
        `sessionClosed` in class `IoFilterAdapter`
      Throws:
        `Exception`

Copyright © 2004-2012 Apache MINA Project. All Rights Reserved.