I solved this by setting a read idle timer to a small value when I think I have a partial message. I capture the previous idle timer value and a copy of the input Mina ByteBuffer into an object that I attach to the session, and return false. If I come back through the decoder with more data before timing out, and I believe it is the end of the data (in my case lim < cap), I get rid of the object attached to session, reset the idle timer, write it and return true. Because the CumulativeProtocolDecoder hangs of off a Mina filter, I implement the SessionIdle method on this particular filter, in the SessionIdle method (this is also the first SessionIdle method implemented in my filter chain), I copy the message again into a new ByteBuffer, call the nextFilter.messageReceived with my new ByteBuffer, reset my idle timer to the saved amount, and remove my temporary object from the session. I ended up copying to a new ByteBuffer, because when I didn't I got a buffer released multiple times exception.
I am not positive that this solves all of my issues, but initial testing seemed to go well. I was surprised that I didn't have to do anything to avoid concatenating my current message with the next, since I returned false in my CumulativeProtocolDecoder implementation, but it seemed to go away on its own when I called the nextFilter.messageReceived. I am sure this implementation causes a performance hit, but I have lots of connections that don't send many messages, so causing a connection to wait a second or two isn't really a problem. I also wasn't sure why I saw exceptions for multiple released buffers when I used the ByteBuffer I had attached to the object I created in the session, I realize that I can't do this with buffers/messages passed into the various filter/encoder/decoder methods. Perhaps that just shows that I don't quite know what I am doing yet... Anyone see any obvious issues with this? Jerry -- View this message in context: http://www.nabble.com/CumulativeProtocolDecoder-tp18777497p19301228.html Sent from the Apache MINA User Forum mailing list archive at Nabble.com.
