ChannelHandler instance

Trustin Lee tlee at redhat.com
Mon Mar 9 17:43:35 EDT 2009


Bob,

Sorry for the extremely late response first of all..

On Fri, Feb 27, 2009 at 6:25 AM, Bob Bucy <bob.bucy at gmail.com> wrote:
> Great job on Netty, loving this framework.  I am in the process of
> porting some .Net services that act as a specialized proxy (e.g.
> receives requests from many short-lived connections and passes the
> requests through to a finite number of persistent "back end"
> connections).

Nice to hear that you love Netty.  Let me know if you are satisfied
enough to write a testimonial -
http://www.jboss.org/netty/testimonials.html :)

> Usually, the messages are one-one (e.g. request -response), but some
> type of messages are many-to-one (e.g. many requests received on a
> channel will result in a single backend response).  The messages
> consist of a Header record, followed by many Detail Records, followed
> by a Trailer.  In this many-to-one case, as messages come in I need to
> make sure the message is sent to the same back-end channel.
>
> To accomplish this, I was planning on saving off the back end channel
> that a message was forwarded too in my ChannelHandler , thus follow-on
> messages can be sent to the same backend channel.  This is based on
> the assumption that the same instance of ChannelHandler always
> processes the messages decoded for a given Channel.
>
> Based on my tests/debugging this statement is true, but I wanted to
> verify before making this assumption.

As long as you create a new instance for a new pipeline, your
assumption is correct.  Your ChannelPipelineFactory seems to append a
new handler instance per pipeline, and therefore it just works as you
expected.  If you maintained a singleton of the handler instance and
added the same instance to multiple pipelines, it would have not
worked.

HTH,

— Trustin Lee, http://gleamynode.net/




More information about the netty-users mailing list