I'm currently digging into Apache MINA. It's a great framework with lots of capabilities. The hardest part until now was the decoder part. Checking the api documents I understand that there are the following classes that one can extend and implement his own:
All of the above extend the CumulativeProtocolDecoder class - A ProtocolDecoder that cumulates the content of received buffers to a cumulative buffer to help users implement decoders.
I am using an instance of DemuxingProtocolDecoder class with my application. Under the package org.apache.mina.filter.codec.demux
there are some interfaces and classes that you can use to decode your messages. There is an interface called MessageDecoder
. Create your own class that implements this interface and MINA will the work. Something like this,
public class MyDecoder implements MessageDecoder {
public MessageDecoderResult decode(IoSession session, IoBuffer buffer, ProtocolDecoderOutput decoderOutput) throws Exception {
/* Your
decode
mechanism */
decoderOutput.write(message); // don't forget to write your decoded message object at some point.
return MessageDecoder.OK; //or something else that matches your needs.
}
}