One message at a time in each handler?

"Trustin Lee (이희승)" trustin at gmail.com
Sun Jun 6 22:23:14 EDT 2010


Yes, only one event at a time will flow through individual channel
handlers in the same pipeline in Netty.  However, this is somewhat
different from SEDA.  It's not because of the queues but because of how
pipeline is implemented.

When an event is triggered, Netty calls the handler directly.  It means
Netty I/O thread will wait for your handler to return the control back.
 Until Netty takes the control back, Netty will not generate any event.
 Also, the same applies to event propagation in the pipeline.
Forwarding an event to the next handler is simply calling the handler
directly.

To let user implement SEDA, Netty provides ExecutionHandler, which has a
queue and a thread pool in org.jboss.netty.handler.execution.  If you do
not like it, you can always write your own handler that decouples the
event execution from the Netty I/O threads.

HTH,
Trustin

falconair wrote:
> Does netty's ChannelHandler semantics include a guarantee that only one
> message at a time will flow through individual channel handlers? 
> 
> I didn't read any such thing in the docs, but I understand netty is based on
> SEDA architecture, and I understand SEDA includes such guarantee.
> 
> In other words, which is more accurate representation of netty:
> 
> [h1]->[h2]->[h3]
> 
> or
> 
> {q1}==>[h1]->{q2}==>[h2]->{q3}==>[h3]
> 
> In the first scenario, multiple [h2] handler might be invoked for the SAME
> pipeline, which means instance variables are prone to threading issues.
> 
> In the second scenario, interleaved queues make sure only one message is
> processed by handler (for the same pipeline), therefore instance variables
> are safe from dead-locks and race conditions.

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



More information about the netty-users mailing list