Page Edited :
MINA :
ProtocolCodec discussion
ProtocolCodec discussion has been edited by Emmanuel Lécharny (Nov 11, 2008). Change summary: Created the page. Added some description for the sessionCreated event IntroductionThis filter is one of the most important one. In many case, writing a MINA based application without having such a filter added is not really meaningful. Events handledHere is a list of all the handled events in this filter :
DescriptionConstructorIn order to be able to encode or decode a message, we need to pass the filter a factory, which will be used to create those two parts of the codec :
The factory is pretty simple. It offers two methods : public interface ProtocolCodecFactory { /** * Returns a new (or reusable) instance of [EMAIL PROTECTED] ProtocolEncoder} which * encodes message objects into binary or protocol-specific data. */ ProtocolEncoder getEncoder(IoSession session) throws Exception; /** * Returns a new (or reusable) instance of [EMAIL PROTECTED] ProtocolDecoder} which * decodes binary or protocol-specific data into message objects. */ ProtocolDecoder getDecoder(IoSession session) throws Exception; }
It's also possible to pass the encoder and decoder directly, as a factory will be created internally to encapsulate those two methods. SessionCreated eventThe current handling for this event is pretty simple : it stores the Encoder and Decoder instances in the session attributes. public void sessionCreated(NextFilter nextFilter, IoSession session) throws Exception { // Creates the decoder and stores it into the newly created session session.setAttribute(DECODER, factory.getDecoder(session)); // Creates the encoder and stores it into the newly created session session.setAttribute(ENCODER, factory.getEncoder(session)); // Call the next filter nextFilter.sessionCreated(session); }
SessionClosed event |
Unsubscribe or edit your notifications preferences