Apache MINA – CumulativeProtocolDecoder Explained

Apache MINA uses the concept of Protocol Decoder to decoder read bytes into High Level Message objects. There are conditions in which a single packet may not contain the complete bytes to convert raw message into High Level Objects. For such situations, CumulativeProtocolDecoder can be used. Basically, encoder makes the framework buffer the data, till the complete data is received, to convert the byte[] into a high level object.

So, how do we use this Decoder

Extend from the class CumulativeProtocolDecoder and implement the doDecode().

Conditions to take care of

  1. read the IoBuffer and decode as per yur logic
  2. If the data is sufficient to create your message, return true, else return false
Under the Hood
The magic lies in the asbtract class CumulativeProtocolDecoder, which internally buffer the data and keep on calling our doDecoder(). Based on the return type from doDecode(), it either keeps buffering or allows the framework to call next filter in the chain.
Implementation of CumulativeProtocolDecoder can be seen in detail in the following post

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.