mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Grundvig" <m...@electrotank.com>
Subject Re: Dumb Questions about MINA Implementation
Date Sun, 10 Sep 2006 15:00:41 GMT
Thanks Niklas! That makes sense. I was using the SumUp example as a 
foundation for my code and it simply creates the needed objects in the 
sessionCreated method. This is where I started going astray. Thanks again!

Michael

----- Original Message ----- 
From: "Niklas Therning" <niklas@trillian.se>
To: <mina-dev@directory.apache.org>
Sent: Sunday, September 10, 2006 1:16 AM
Subject: Re: Dumb Questions about MINA Implementation


> Mike Grundvig wrote:
>> ...
>>
>> 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?
> Yes, you're correct. Adding filters to the IoAcceptor means that they
> will be added to all session created from that IoAcceptor. I'd say that
> I would either add the ProtocolCodecFilter to the IoAcceptor or use a
> single ProtocolCodecFilter instance in my IoHandler like this:
>
> public MyIoHandler() {
>   ProtocolEncoder delimitedEncoder = new
> TextLineEncoder(defaultCharset, terminator);
>   ProtocolDecoder delimitedDecoder = new
> TextLineDecoder(defaultCharset, terminator);
>   this.codecFilter = new ProtocolCodecFilter(delimitedEncoder,
> delimitedDecoder);
> }
>
> public void sessionCreated(IoSession ioSession) throws Exception {
>   ioSession.getFilterChain().addLast("protocol", codecFilter);
> }
>
> Of course, for this to work TextLineEncoder, TextLineDecoder and
> ProtocolCodecFilter must be stateless. Luckily they are.
>
> HTH
>
> -- 
> Niklas Therning
> www.spamdrain.net
>
> 



Mime
View raw message