Archive for August, 2008

How to use the MINA IoFilter

August 18, 2008 4 comments

While rewriting a personal project using Apache Mina I found out that there was very limited documentation about how to chain up IoFilters and ProtocolCodecs properly. I’m using a text based protocol that uses line delimiters to indicate message boundaries. Mina comes with a TextLineCodec that does the splitting for you, resulting in your handler receiving String objects, instead of IoBuffers.

Great of course, but my idea was to line up the TextLineCodec filter with my own custom codec that creates nice command objects for my handler, and does some exception handling in case an invalid message is received. That way my handler code stays clean of any low-level protocol concerns and only works with high level objects. After several hours of fiddling around trying to create my own ProtocolCodec implementation I was unable to get it done. The interfaces didn’t allow me to pass on something else than an IoBuffer, not what i call a high-level object. After a mail conversation with Trustin Lee i decided to directly implement the IoFilter interface. But let’s start with the IoHandler.

Read more…

Categories: Apache Mina, Java