Package 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
AnIoFilter
which translates binary or protocol specific data into message objects and vice versa usingProtocolCodecFactory
,ProtocolEncoder
, orProtocolDecoder
.- 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 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
filterWrite(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest)
FiltersIoSession.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)
FiltersIoHandler.messageSent(IoSession,Object)
event.void
onPostRemove(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter)
Invoked after this filter is removed from the specifiedparent
.void
onPreAdd(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter)
Invoked before this filter is added to the specifiedparent
.void
sessionClosed(IoFilter.NextFilter nextFilter, IoSession session)
FiltersIoHandler.sessionClosed(IoSession)
event.-
Methods inherited from class org.apache.mina.core.filterchain.IoFilterAdapter
destroy, event, exceptionCaught, filterClose, init, inputClosed, onPostAdd, onPreRemove, sessionCreated, sessionIdle, sessionOpened, toString
-
-
-
-
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 messagedecoder
- 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:
encoderClass
- The class responsible for encoding the messagedecoderClass
- 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
Invoked before this filter is added to the specifiedparent
. 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 beforeIoFilter.init()
is invoked.- Specified by:
onPreAdd
in interfaceIoFilter
- Overrides:
onPreAdd
in classIoFilterAdapter
- 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:
Exception
- If an error occurred while processing the event
-
onPostRemove
public void onPostRemove(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter) throws Exception
Invoked after this filter is removed from the specifiedparent
. 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 beforeIoFilter.destroy()
is invoked.- Specified by:
onPostRemove
in interfaceIoFilter
- Overrides:
onPostRemove
in classIoFilterAdapter
- 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:
Exception
- If an error occurred while processing the event
-
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 interfaceIoFilter
- Overrides:
messageReceived
in classIoFilterAdapter
- Parameters:
nextFilter
- theIoFilter.NextFilter
for this filter. You can reuse this object until this filter is removed from the chain.session
- TheIoSession
which has received this eventmessage
- The received message- Throws:
Exception
- If an error occurred while processing the event
-
messageSent
public void messageSent(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception
FiltersIoHandler.messageSent(IoSession,Object)
event.- Specified by:
messageSent
in interfaceIoFilter
- Overrides:
messageSent
in classIoFilterAdapter
- Parameters:
nextFilter
- theIoFilter.NextFilter
for this filter. You can reuse this object until this filter is removed from the chain.session
- TheIoSession
which has received this eventwriteRequest
- TheWriteRequest
that contains the sent message- Throws:
Exception
- If an error occurred while processing the event
-
filterWrite
public void filterWrite(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception
FiltersIoSession.write(Object)
method invocation.- Specified by:
filterWrite
in interfaceIoFilter
- Overrides:
filterWrite
in classIoFilterAdapter
- Parameters:
nextFilter
- theIoFilter.NextFilter
for this filter. You can reuse this object until this filter is removed from the chain.session
- TheIoSession
which has to process this invocationwriteRequest
- TheWriteRequest
to process- Throws:
Exception
- If an error occurred while processing the event
-
sessionClosed
public void sessionClosed(IoFilter.NextFilter nextFilter, IoSession session) throws Exception
FiltersIoHandler.sessionClosed(IoSession)
event.- Specified by:
sessionClosed
in interfaceIoFilter
- Overrides:
sessionClosed
in classIoFilterAdapter
- Parameters:
nextFilter
- theIoFilter.NextFilter
for this filter. You can reuse this object until this filter is removed from the chain.session
- TheIoSession
which has received this event- Throws:
Exception
- If an error occurred while processing the event
-
-