You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Paul Chen <ch...@gmail.com> on 2006/08/08 04:54:42 UTC

Is there any working example of CumulativeProtocolDecoder?

Hi, folks,

If you have one that you can share, that's much appreciated.
We are facing a lot of issues with it such as Unregisterable
type exception or server hang...

Thanks a bunch

Re: Is there any working example of CumulativeProtocolDecoder?

Posted by Trustin Lee <tr...@gmail.com>.
On 8/8/06, Paul Chen <ch...@gmail.com> wrote:
>
> Hi, folks,
>
> If you have one that you can share, that's much appreciated.
> We are facing a lot of issues with it such as Unregisterable
> type exception or server hang...


Seems like you are using DemuxingProtocolCodecFactory, right?  Then you
could take a look at the SumUp example which is available in our Getting
Started page.

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41  4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4  455E 1C62 A7DC 0255 ECA6

Re: Is there any working example of CumulativeProtocolDecoder?

Posted by Zohar Amir <zo...@gmail.com>.
 Here's my doDecode(), HTH:

    @Override
    protected boolean doDecode(IoSession session, ByteBuffer in,
ProtocolDecoderOutput out) throws Exception {

        Part1 part1 = null;
        Part2 part2 = null;
        ByteBuffer contentBuffer = null;
        MessageType messageType = null;

        try {
            part1 = getPart1(in);
            part2 = getPart2(in);


            byte[] messageTypeBytes = getTlv(in, CONTENT_TYPE_TAG);
            int messageTypeCode = byteArrayToInt(messageTypeBytes);
            messageType = MessageType.getMessageType(messageTypeCode);
            if(messageType == null) {
                throw new DecoderException("unknown message type code " +
messageTypeCode);
            }

            // TODO see if we can avoid using arrays and stay with the
buffer
            int contentLength = byteArrayToInt(getTlv(in,
CONTENT_LENGTH_TAG));
            if (contentLength > 0) {
                byte[] contentBytes = new byte[contentLength];
                in.get(contentBytes);

                contentBuffer = ByteBuffer.allocate(contentLength);
                contentBuffer.put(contentBytes);
                contentBuffer.flip();
            }

        } catch (BufferUnderflowException  e) {
            in.rewind();
            return false;
        }

        Message message;
        try {
            message = new Message(messageType, transportBinding,
sessionBinding, contentBuffer);
        } catch (Throwable e){
            String errStr = "while creating a new message";
            logger.error(errStr);
            throw new DecoderException(errStr, e);
        }

        if (contentBuffer != null) {
            contentBuffer.release();
        }

        out.write(message);

        return true;
    }


On 8/8/06, Paul Chen <ch...@gmail.com> wrote:
>
> Hi, folks,
>
> If you have one that you can share, that's much appreciated.
> We are facing a lot of issues with it such as Unregisterable
> type exception or server hang...
>
> Thanks a bunch
>
>