Thank you. However, which method can reach the best performace? My server
received huge size of packets every time from intrenet(sent to client), when
i do the decode, i will return the arraylist of decoded messages. I wonder
if it will use up the CPU 100% if the incoming packets are too fast and too
huge to decode. Mina provides a solution to prevent this? I also think we
should put this in the tutorial. This part is also what the beginner
sometimes really care about. I am the beginner and I know what they are
looking for.

2007/3/5, Trustin Lee <[EMAIL PROTECTED]>:

Hi Mat,

2007-03-05 (월), 03:11 +0800, mat 쓰시길:
> After I looked at the sumup server example, I wonder whether it is the
> example just for single client session? It seems it doesn't handle the
> mult-session case.

It does handle multiple sessions.

>
> I still get confused about how to handle the multi-session decoding.
What if
> the incoming message was truncated? How can I re-assembly the truncated
> message? Should I do something like?
>
> public MessageDecoderResult decode( IoSession session, ByteBuffer in,
> ProtocolDecoderOutput out ) throws Exception{
>
>   ByteBuffer savedByteBuffer = session.getAttribute
> ("SavedTruncatedByteBuffer");
>
>   SavedTruncatedByteBuffer +  in = newByteBuffer
>
>   IF( newByteBuffer.remaining() >= Message.length)
>     decode_body
>   ELSE
>     NEED_DATA
> }

No, you don't need to do that by yourself if you use
DumuxingProtocolCodecFactory or CumulativeProtocolDecoder.  You can
simply return NEED_DATA if there's not enough data received rather than
cumulating the partial buffer content.

>
> But after i read the source code of ProtocolCodecFilter, it seems each
> session has its own decoder class. So can I just save the truncated
message
> in the decoder class?

It depends.  If you registered your MessageDecoder with
Class<MessageDecoder>, then a new instance per session will be created.
If you wrote your own MessageDecoderFactory, then you can control the
cardinality.  I usually prefer to specify a class for registration,
because it is easy to implement.

>
> What is the purpose of CumulativeProtocolDecoder?

If you implement ProtocolDecoder directly, you have to cumulate partial
message content by yourself, and as you know, it's very cumbersome.
Extending CumulativeProtocolDecoder will do the cumulation for you.  You
can just return instead of cumulating the partial message, then
CuimulativeProtocolDecoder will come back later with cumulated full
message.

HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6


Reply via email to