mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Maarten Bosteels" <mbosteels....@gmail.com>
Subject Re: ProtocolDecoderAdapter and session-state.
Date Fri, 16 Mar 2007 19:47:40 GMT
Hi Niklas,

I am reading the mina mailing list since about a year, but this is the
first time I see a recommendation to keep the ProtocolDecoder
implemantation stateless.
I prefer to create a new decoder per session and keep the decoder
state in the decode.
Sound OO-principle says : store the state in the class that uses it.

Should I really anticipate that mina will someday no longer support
statefull decoders ?

Maarten


On 3/16/07, Niklas Therning <niklas@trillian.se> wrote:
> Nordin, Glenn wrote:
> > Hi!
> >
> > I have two questions about Apache MINA 1.0 .
> >
> > 1. Is it possible to store state for incomplete reads in
> > ProtocolDecoderAdapter without mixing state from different sessions,
> >     if I always create a new instance (prototype) of the ProtocolDecoder
> > in ProtocolCodecFactory.getDecoder method?
> >     In other words ignoring the IoSession parameter in the decode method
> > as if the same IoSession is always returned.
> >
>
> ProtocolCodecFilter in MINA 1.0 will use the ProtocolCodecFactory to get
> a per session decoder the first time a message is received for a
> session. The decoder is stored as a session attribute and reused when
> decoding subsequent messages for that session. Judging from this it
> should be safe to have stateful ProtocolDecoders as you are suggesting.
>
> However, this behavior could change in future versions of MINA. To be on
> the safe side you should store the per session state as session
> attributes and keep your ProtocolDecoder stateless.
>
> > 2. IoHandler and ProtocolDecoderAdapter:
> >     I think only a single thread is used per session at the same time,
> > but it is not always the same thread.
> >     Can I write code as if the same thread per session is executing the
> > methods in IoHandler and ProtocolDecoder?
> >
> I guess this depends on how you have set up your thread model (see
> http://mina.apache.org/configuring-thread-model.html). But generally
> speaking I don't think this is a good idea. What are you trying to achieve?
>
> HTH
>
> --
> Niklas Therning
> www.spamdrain.net
>
>

Mime
View raw message