Le 4/23/14 1:34 PM, Vladimir Kravets a écrit :
> 2014-04-23 13:43 GMT+03:00 Emmanuel Lécharny <[email protected]>:
>
>>> But I faced with flow which implementation wasn't easy.
>>> And it's related to internal realization of cummulative buffer (it's not
>>> exists in the mina3, thus I'm tried to write own). I try to do it and it
>>> wasn't work... =(
>> The internal IoBuffer is an array of ByteBuffer. It will 'cumulate' all
>> the read data from the socket, and you'll see the result as a single
>> ByteBuffer (ie, all the operation done on the IoBuffer will be the same
>> than the ByteBuffer operations, except that they will be applied on
>> many). I don't think you need to implement your own cumulative buffer.
>>
>>
> Yep, I know this, but first decoder will get data in the ByteBuffer not in
> the IoBuffer... Should I perform such transformation before decoder will be
> called?

You have 2 decoders in the chain ?


>
>
>>> After investigation code of mina I found that the same buffer passed to
>> the
>>> decoder in case if previous call of decoder successfully return data
>> object
>>> (not null!)
>> Not sure I see what you mean here... Can you be a bit more explicit ?
>>
>>
> If you look to code which you show below you can see that if decoder decode
> the message:
> 1. Will be called IoHandler
> 2. On the second loop we try to call decode with the same buffer. This is
> doing since buffer can have more than one messages.
>
> This is I'm  trying to said.
>
> This is the way the ProtocolCodecFilter works :
>>     public void messageReceived(IoSession session, Object in,
>> ReadFilterChainController controller) {
>>         LOGGER.debug("Processing a MESSAGE_RECEIVED for session {}",
>> session);
>>
>>         DECODING_STATE state = getDecodingState(session);
>>
>>         // Loop until the decoder cannot decode more
>>         MESSAGE msg;
>>         try {
>>             while (((msg = decoder.decode((ENCODED) in, state)) != null)) {
>>                 controller.callReadNextFilter(msg);
>>             }
>>         } catch (ProtocolDecoderException e) {
>>             LOGGER.debug("decoding exception : ", e);
>>             throw e;
>>         }
>>     }
>>
>>
>>> As for me from one point it's logical, from another point we need have
>>> heavy logic to prevent duplication during union two buffers.
>> Be sure to flip the IoBuffer when you have processed a message. This is
>> critical.
>>
>> Not sure that I understanding you well. You are talking about after adding
> to IoBuffer or after reading enough data from it?
>
> In my code after reading data from IoBuffer I do nothing. Am I should added
> ioBuf.flip() in this case?


No, not in your code. It's fine as it is.


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 

Reply via email to