A couple of questions about Netty internals

Trustin Lee (이희승) trustin at gmail.com
Tue Nov 3 08:02:05 EST 2009


Hi Mert,


On Tue, Nov 3, 2009 at 7:52 PM, Mert İnan <inanme at yahoo.com> wrote:
>
> Thank you Truntin.
>
> First i post to "Netty Developer Group", due to lack of response i thougth
> may be i posted to wrong group. So i posted to "Netty User Group" and tried
> to delete first post. but could not delete.
>
> which group should newbies should post?
> here i tried to ask my questions in more detail.

Actually, Netty User Group is the correct place, but I'm just fine. :)

> Trustin Lee wrote:
>>
>> Thanks for your interest in Netty, but please do not double-post.
>> Your second duplicate post has been discarded.
>>
>> On Mon, Nov 2, 2009 at 3:44 PM, Mert İnan <inanme at yahoo.com> wrote:
>>>
>>> Hi Netty Developer Group,
>>>
>>> i am trying to get confortable with Netty(3.1.5). Here are a couple of
>>> questions i come up with.
>>>
>>> 1. Data comes into netty, it goes up and down through handlers. There may
>>> be
>>> many ChannelUpstreamHandler and ChannelDownstreamHandler handlers. In all
>>> those handlers,in general, should i use Channels.fireMessageReceived only
>>> once? if so when? what happens if Channels.fireMessageReceived is called
>>> more then once in up handlers?
>>
>>
>> Trustin Lee wrote:
>>>
>>> There's no restriction on how many times an event should be generated
>>> by a handler.  This means, you can generate as many as events as you
>>> want
>>>
>> For example A handler fires X message, B handler receices it. B converts X
>> to Y message.
>> in B hanler X's lifecycle is over, Y message must go on to upper handlers.
>> Bu i can not code this approach.
>>
>> I could not find a way to kill X and forward Y from where X left.

1) In handler A, you could call Channels.fireMessageReceived(...) with
the message X.
2) In handler B, you could convert X to Y and then call
Channels.fireMessageReceived(...) with the message Y.

I'm not sure this is what you are looking for because this is a very
typical configuration.

>>> 2. What should i do when my decoder constructed by more than one handler?
>>> Is
>>> it required that Decoder must be implemented in one handler?
>>
>>
>> Trustin Lee wrote:
>>>
>>> You can write a complex decoder with more than one handler.  That is,
>>> you can combine multiple decoders to decode multi-layered protocols
>>> for example.
>>>
>>
>> how can i forward both the half decoded message and renaming buffer?
>> Should i encupsulate them in a new class for example?

Yes.  You can encapsulate them in a new class.  There might be other
ways, but I think it is simple and clean.

>>> 3. Why FrameDecoder.callDecode throws this Exception?
>>>
>>>                throw new IllegalStateException(
>>>                        "decode() method must read at least one byte " +
>>>                        "if it returned a frame (caused by: " + getClass()
>>> +
>>> ")");
>>
>>
>> Trustin Lee wrote:
>>>
>>> Decoding, by definition, reads something from the input and produces
>>> the decoded data.  Therefore, you cannot create something from
>>> nothing.
>>>
>>
>> I want to separete roles of framer and decoder. As you said decoder always
>> should read data.
>> But framer should not i guess. Framer must ensure that enough data is
>> received.
>> in my case, i want to ensure that enough data is received without actually
>> reading it and forward that data to decoder .

Yes, of course.  That's how it is implemented.  Could you take a look
into the telnet example?  Also, take a look at the source code of
frame decoder and string decoder.

>> i hope i could express myself.
>>
>>
>> Trustin Lee wrote:
>>>
>>> HTH
>>>
>>> — Trustin Lee, http://gleamynode.net/
>>>
>>> _______________________________________________
>>> netty-dev mailing list
>>> netty-dev at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/netty-dev
>>>
>>
>
> --
> View this message in context: http://n2.nabble.com/A-couple-of-questions-about-Netty-internals-tp3930218p3937712.html
> Sent from the Netty Developer Group mailing list archive at Nabble.com.
>
> _______________________________________________
> netty-dev mailing list
> netty-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-dev
>

— Trustin Lee, http://gleamynode.net/



More information about the netty-dev mailing list