Event order and synchronization

"이희승 (Trustin Lee)" trustin at gmail.com
Wed Aug 25 22:48:48 EDT 2010


Hi Duncan,

On 08/22/2010 06:24 PM, McCloud wrote:
> 
> 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

Yes, that is correct.

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

Unless you forward the event to other thread pool, the order is always
maintained correctly.   If you want to use a thread pool to handle
events, please refer to ExecutionHandler.

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

It is not really a problem because writing to a unconnected channel will
simply fail with an exception and the connection will be closed. :)

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

It's nice to see someone who enjoys reading code and ask good questions!

Cheers,
T
-- 
what we call human nature in actuality is human habit
http://gleamynode.net/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 293 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20100826/bb6aed4a/attachment.bin 


More information about the netty-users mailing list