Event order and synchronization

McCloud Duncan.Doyle at gmail.com
Sun Aug 22 05:24:40 EDT 2010


Hello,

I'm trying to write a webservices monitor using a proxy build in Netty. I'm
using the Proxy example as a base. While figuring out Netty and its
internals (I like to know how stuff works), I came across this forum thread
which confused me with regards to setting ' 'setReadable(false)' on a
Channel and the order of events (channelOpen, messageReceived):
http://www.jboss.org/netty/community.html#nabble-td4075899|a4797193

In this thread it is stated that, when bytes are read before
'setReadable(false)' has been called, you will receive a 'messageReceived'
event (which is as expected). Now I was wondering, as Netty is asynchronous,
if it is possible that you get a 'messageReceived' event before the
'channelOpen' method has completely finished? If that is possible, looking
at the Proxy InboundHandler example
(http://docs.jboss.org/netty/3.2/xref/org/jboss/netty/example/proxy/HexDumpProxyInboundHandler.html),
you could get into a situation in which you write to an outboundChannel
which is still 'null' or which is not connected.

While Netty seems to use a single worker thread per connection, I guess that
this is not possible (the InboundHandler is used by only on thread, so you
can't execute methods concurrently on the same InboundHandler object), but
then there seems to be another problem with the example code. What happens
when bytes have been read before 'setReadable(false)' has been called and
the outbound connection can not be made (in the ' channelOpen' method)? I
guess that 'messageReceived' will be called which tries to write to an
outboundChannel which is not connected. So, shouldn't the 'messageReceived'
method in the example check whether the outboundChannel is actually open for
writing?

Just some questions so I won't run into strange concurrency bugs :-)

Cheers,

Duncan
-- 
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Event-order-and-synchronization-tp5449312p5449312.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list