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
public class ProtocolCodecFilter extends IoFilterAdapter
AnIoFilterwhich 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 voidfilterWrite(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest)FiltersIoSession.write(Object)method invocation.ProtocolEncodergetEncoder(IoSession session)Get the encoder instance from a given session.voidmessageReceived(IoFilter.NextFilter nextFilter, IoSession session, Object message)Process the incoming message, calling the session decoder.voidmessageSent(IoFilter.NextFilter nextFilter, IoSession session, WriteRequest writeRequest)FiltersIoHandler.messageSent(IoSession,Object)event.voidonPostRemove(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter)Invoked after this filter is removed from the specifiedparent.voidonPreAdd(IoFilterChain parent, String name, IoFilter.NextFilter nextFilter)Invoked before this filter is added to the specifiedparent.voidsessionClosed(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:
onPreAddin interfaceIoFilter- Overrides:
onPreAddin classIoFilterAdapter- Parameters:
parent- the parent who called this methodname- the name assigned to this filternextFilter- theIoFilter.NextFilterfor 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:
onPostRemovein interfaceIoFilter- Overrides:
onPostRemovein classIoFilterAdapter- Parameters:
parent- the parent who called this methodname- the name assigned to this filternextFilter- theIoFilter.NextFilterfor 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:
messageReceivedin interfaceIoFilter- Overrides:
messageReceivedin classIoFilterAdapter- Parameters:
nextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich 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:
messageSentin interfaceIoFilter- Overrides:
messageSentin classIoFilterAdapter- Parameters:
nextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has received this eventwriteRequest- TheWriteRequestthat 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:
filterWritein interfaceIoFilter- Overrides:
filterWritein classIoFilterAdapter- Parameters:
nextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has to process this invocationwriteRequest- TheWriteRequestto 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:
sessionClosedin interfaceIoFilter- Overrides:
sessionClosedin classIoFilterAdapter- Parameters:
nextFilter- theIoFilter.NextFilterfor this filter. You can reuse this object until this filter is removed from the chain.session- TheIoSessionwhich has received this event- Throws:
Exception- If an error occurred while processing the event
-
-