Undestanding the pipeline

Iain McGinniss iainmcgin at gmail.com
Tue Dec 15 06:34:20 EST 2009


Responses inline below...

On Mon, Dec 7, 2009 at 10:13 PM, justkevin <filter.netty at wx3.com> wrote:

>
> Hi all,
>
> I have a couple questions about the pipeline and processing incoming
> messages (I'm new to Netty, so these questions may be a bit naive):
>
> 1.) What's the difference between overriding handleUpstream and
> messageReceived? I see that one gets a ChannelEvent and the other gets a
> MessageEvent, but I'm not sure how to decide which one to override. Also,
> if
> I override both in a handler, why is it that messageReceived isn't
> triggered?
>

handleUpstream is the generic upstream event handling method - here, you
will have to do instanceof checks to determine what type of upstream event
it is, if that is relevant to your processing. messageReceived only deals
with data reception, and is a convenience method provided for overriding by
the SimpleChannelUpstreamHandler class. If you take a look at the source of
SimpleChannelUpstreamHandler<http://www.jboss.org/file-access/default/members/netty/freezone/xref/3.1/org/jboss/netty/channel/SimpleChannelUpstreamHandler.html#76>
you'll
see it is doing the instanceof checks in handleUpstream on your behalf.


>
> 2.) Let's say I expect the first thing to come from the client to be an
> authentication string. If they authenticate, I want to treat the rest of
> their data as length field based frames. I think this is roughly how to
> handle it using the pipeline model:
>
> Pipeline factory adds an AuthenticationHandler.
> The AuthenticationHandler looks for a string.
> If the string is "good", add a LengthFieldBasedFrameDecoder and a
> MessageHandler, remove the AuthenicationHandler. Pass the MessageHandler a
> user object maybe?
> Otherwise, close the connection (maybe send some kind of rejection
> message).
>
> Is that more or less correct? Thanks in advance for any help!
>

This seems like a sensible approach., but I'll let the others comment on
this. In some ways, I wish it were easier to encapsulate this kind of
pipeline state transition, so that adding / removing handlers at runtime was
so explicit.

Iain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-users/attachments/20091215/cd05e7e0/attachment.html 


More information about the netty-users mailing list