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?


>
> > 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?


> >
> > I agree that issue can be in my code/logic, but I'm only want to show
> some
> > of end user flows which can be appeared. =)
> >
> > My implementation of "comulative buffer" you can find here:
> >
> https://github.com/vkravets/Fido4Java/blob/5b1e0f0b91c928e01047a2604925f8964e7cbff6/binkp-mina3/src/main/java/org/fidonet/binkp/codec/BinkDataDecoder.java
>
> Sounds perfectly fine. You are correctly dealing with the fact that the
> incoming buffer might not contain all the needed data, the buffer is
> stored into the context, and you carefully reset the positon in this case.
>
> This is exactly what a decoder should do !
>
>
> > It will be great if someone comments or show me another way how it can be
> > implementing. Or improve such user case in MINA3 before release.
>
> I think your code is fine, and there is little we can add in MINA to
> fulfill your need.
>
>
Thanks a lot for your feedback.

>
Best Regards,
Vladimir

Reply via email to