Events

Yang Zhang yanghatespam at gmail.com
Sun Jun 7 03:46:51 EDT 2009


Hi,

이희승 (Trustin Lee) wrote:
> You can issue a new event by calling Channels.fireXXX(...),
> ChannelPipeline.sendUpstream/Downstream(...), or
> ChannelHandlerContext.sendUpstream/Downstream(...).  However, the call
> is made recursively.

The fact that the call is made recursively is problematic: the code 
immediately following the async call is expected to immediately execute 
(at least, before the callback is executed), but with the recursive 
call, the callback will execute *in the same thread and before* the code 
immediately following the call.

> callLater() with no delay is pretty simple to implement.  I wonder how
> Twisted Matrix implements delayed event triggering though.  Netty has a
> HashedWheelTimer which is dedicated to delayed task execution, and you
> can do whatever you want with it.

The blocking syscall (e.g. select) made at the core of any asynchronous 
IO framework comes with a timeout parameter, which the framework can use 
for asynchronous sleeps.  The framework manages a priority queue of 
"sleep" events, and wakes them up at the appropriate times using this 
timeout mechanism.

A while back I had asked about this but in the context of Apache Mina:

http://mail-archives.apache.org/mod_mbox/mina-dev/200709.mbox/%3C12893472.post@talk.nabble.com%3E

I then went ahead to implement my own reactor framework for this purpose:

http://assorted.sourceforge.net/java-reactor/

So you may refer to that for a simple example of how this can be done.

(I'm now working in a project that was already under way with Netty.)
-- 
Yang Zhang
http://www.mit.edu/~y_z/



More information about the netty-users mailing list