Hi all; I'm having a hell of a time grasping MINA. I don't know why, but for some reason I just can't seem to get a handle on how to properly implement anything with it. I can get it working just fine but because it has many solutions to a single problem I always second-guess my design decisions.

Currently, I'm working with a protocol that delimits every message with a character. After some checking, I determined that I could simply use the TextLineEncoder/Decoder to process my messages if I passed in the right delimiter. I then created my own IoHandler and in the sessionCreate method, I instantiate the encoder/decoder and a ProtocolCodecFilter and just add them to the filter chain as the last entry. The code is basically this (stripped down for brevity in email):

public void sessionCreated(IoSession ioSession) throws Exception {
ProtocolEncoder delimitedEncoder = new TextLineEncoder(defaultCharset, terminator); ProtocolDecoder delimitedDecoder = new TextLineDecoder(defaultCharset, terminator); ProtocolCodecFilter codecFilter = new ProtocolCodecFilter(delimitedEncoder, delimitedDecoder);
   ioSession.getFilterChain().addLast("protocol", codecFilter);
}

This all works fine, but it seems horribly inefficient to create a filter, encoder and decoder for each and every connection established. Particularly when the ioSession provides the concept of attributes that can be used to store stateful data. Is my implementation actually correct? It seems a better approach (from a performance standpoint) would be to create stateless versions of those objects and tie them to the IOAcceptor itself unless I'm missing something (which seems likely at this point).

I've seen examples that add filters to either the ioSession OR the ioAcceptor. What's the difference? Adding to the acceptor adds them to all new sessions, is that correct?

Thanks in advance for any advice/help. I appreciate it!

Michael

Reply via email to