org.apache.mina.filter.codec

## Class ProtocolCodecFilter<MESSAGE,ENCODED,ENCODING_STATE,DECODING_STATE>

- java.lang.Object
- - org.apache.mina.api.AbstractIoFilter
  - - org.apache.mina.filter.codec.ProtocolCodecFilter<MESSAGE,ENCODED,ENCODING_STATE,DECODING_STATE>

All Implemented Interfaces:
  IoFilter

    public class ProtocolCodecFilter<MESSAGE,ENCODED,ENCODING_STATE,DECODING_STATE>
    extends AbstractIoFilter

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

Author:
  Apache MINA Project

### Constructor Summary

Constructors
Constructor and Description
`ProtocolCodecFilter(ProtocolEncoder<MESSAGE,ENCODED,ENCODING_STATE> encoder, ProtocolDecoder<ENCODED,MESSAGE,DECODING_STATE> decoder)` Creates a new instance of ProtocolCodecFilter, with the specified encoder and decoder.

### Method Summary

Methods
`void` `messageReceived(IoSession session, Object in, ReadFilterChainController controller)` Process the incoming message, calling the session decoder.
`void` `messageWriting(IoSession session, WriteRequest message, WriteFilterChainController controller)` Invoked when a message is under writing.
`void` `sessionClosed(IoSession session)` Invoked when a connection is closed.
`void` `sessionOpened(IoSession session)` Invoked when a connection has been opened.

### Methods inherited from class org.apache.mina.api.AbstractIoFilter

`messageSent, sessionIdle`

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

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

### Constructor Detail

#### ProtocolCodecFilter

    public ProtocolCodecFilter(ProtocolEncoder<MESSAGE,ENCODED,ENCODING_STATE> encoder,
                       ProtocolDecoder<ENCODED,MESSAGE,DECODING_STATE> decoder)

Creates a new instance of ProtocolCodecFilter, with the specified encoder and decoder.

### Method Detail

#### messageReceived

    public void messageReceived(IoSession session,
                       Object in,
                       ReadFilterChainController controller)

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 `AbstractIoFilter`
Parameters:
  `session` - `IoSession` associated with the invocation
  `in` - the incoming message to process

#### messageWriting

    public void messageWriting(IoSession session,
                      WriteRequest message,
                      WriteFilterChainController controller)

Invoked when a message is under writing. The filter is supposed to apply the needed transformation.

Specified by:
  `messageWriting` in interface `IoFilter`
Overrides:
  `messageWriting` in class `AbstractIoFilter`
Parameters:
  `session` - `IoSession` associated with the invocation
  `message` - the message to process before writing

#### sessionOpened

    public void sessionOpened(IoSession session)

Invoked when a connection has been opened.

Specified by:
  `sessionOpened` in interface `IoFilter`
Overrides:
  `sessionOpened` in class `AbstractIoFilter`
Parameters:
  `session` - `IoSession` associated with the invocation

#### sessionClosed

    public void sessionClosed(IoSession session)

Invoked when a connection is closed.

Specified by:
  `sessionClosed` in interface `IoFilter`
Overrides:
  `sessionClosed` in class `AbstractIoFilter`
Parameters:
  `session` - `IoSession` associated with the invocation