Ashish wrote:
the codec factory expose two methods :
public ProtocolEncoder getEncoder( IoSession session )
public ProtocolDecoder getDecoder( IoSession session )
Usually, when designing a new codec, those methods returns a new instance of
the decoder/encoder for each sessions, as these instances are stored into
the user's session. In many cases (ie, when the encoding/decoding is
stateless), this is useless. We should instead create unique instances of
those encoder/decoder, and store the instance into the session. Even if the
codec is stateful, the current codec state should not be handled within the
codec, but in a separate context object.
I'm not saying that the current implementation is wrong, but I think we
should stress out this in the codec documentation, in order to let the
protocol developers to know about it.
The codec's that I have written so far are stateless. They operate on
the byte[] and if the message
is complete, transforms it. My experience is more with decoder's though.
I think this though came across my mind while browsing some decoder,
don't recall which. factory was creating a new Decoder instance each
time (probably it was one of ApacheDS decoder - DNS, NTP or ??)
Documenting it shall help, as developer's can decide whether they need
instance per session or one instance for application.
- ashish
Isn't the factory just supposed to return the same codec each time in
this case?
-Eero