Recommended way of decoding non-framed messages?

tsuna tsunanet at gmail.com
Sun Aug 1 00:15:32 EDT 2010


On Sat, Jul 31, 2010 at 8:25 AM, Bruno de Carvalho <kindernade at gmail.com> wrote:
> Take a look at ReplayingDecoder (http://docs.jboss.org/netty/3.2/api/org/jboss/netty/handler/codec/replay/ReplayingDecoder.html). It's a mix of your solutions 1 and 3.
>
> In every successful read you advance state and every time you try to read past the capacity an exception is thrown (maintaining current state). Difference is this exception is already created and the buffer itself is a special variant of ChannelBuffer. At first it may sound like it's not very performance friendly but trust me, it is ;)

I see, that's a clever idea.  Not sure whether it'll fit in my code,
but I'll give it a try.

The javadoc of ReplayingDecoder makes the following claim:
"Please note that the overhead of throwing an Error is minimal unlike
throwing a new Exception in an ordinary way. ReplayingDecoder reuses
the same Error instance so that it does not need to fill its stack
trace, which takes most of Exception initialization time."

I read the Chapter 11 of the JLS on exceptions
(http://java.sun.com/docs/books/jls/third_edition/html/exceptions.html)
and I didn't find anything related to this.  Chapter 14, section 20.2
(http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.20.2),
which is the only part of the JLS to say something about stack traces,
mentions:
"a backtrace is not required [...] The problem with mandating a
backtrace is that an exception can be created at one point in the
program and thrown at a later one. It is prohibitively expensive to
store a stack trace in an exception unless it is actually thrown (in
which case the trace may be generated while unwinding the stack).
Hence we do not mandate a back trace in every exception"

I'm guessing that the behavior described in ReplayingDecoder is just
one of the many possible implementations allowed by the JLS and that
Sun's implementation follows this behavior (although it seems to go
against the statement that "It is prohibitively expensive to store a
stack trace in an exception" of the JLS).

If anyone a pointer to a source code or document that relates to this
implementation detail, please send it my way.
Thanks.

-- 
Benoit "tsuna" Sigoure
Software Engineer @ www.StumbleUpon.com



More information about the netty-users mailing list