Chained/Nested Pipeline?

"Trustin Lee (이희승)" trustin at gmail.com
Mon Mar 8 05:20:29 EST 2010


Hi Joel,

Unfortunately, the default ChannelPipeline implementation cannot be chained.

You can implement your own pipeline implementation to route an event
dynamically based on its properties.  The implementation could look
similar to DefaultChannelPipeline or StaticChannelPipeline, except that
ChannelHandlerContext.sendDownstream() will determine the next handler
dynamically.

As an alternative, you could simply hand off the event to your own
routing layer after HTTP decoding.

HTH,
Trustin

JoelPM wrote:
> I'm migrating an existing service that uses HTTP to Netty and have a question
> about the best way to achieve the following scenario. In my current service
> I have a router that inspects the path and dispatches to a different
> container based on path attributes. So far I have a simple
> ChannelPipelineFactory that looks like this:
> 
>   /**
>    * @see org.jboss.netty.channel.ChannelPipelineFactory#getPipeline()
>    */
>   @Override
>   public ChannelPipeline getPipeline() throws Exception {
>     ChannelPipeline pipeline = Channels.pipeline();
> 
>     pipeline.addLast("decoder", new OxHttpRequestDecoder());
>     pipeline.addLast("encoder", new OxHttpResponseEncoder());
>     pipeline.addLast("handler", new
> RoutingRequestHandler(pipelineFactories));
> 
>     return pipeline;
>   }
> 
> In RoutingRequestHandler I would like to be able to do something like this:
> 
>   @Override
>   public void messageReceived(ChannelHandlerContext ctx, MessageEvent evt)
>       throws Exception {
>     HttpRequest request = (HttpRequest) evt.getMessage();
> 
>     String path = getPath(request.getUri());
> 
>     ChannelPipelineFactory pathFactory = pipelineFactories.get(path);
> 
>     ChannelPipeline pathPipeline = pathFactory.getPipeline();
> 
>     // Not sure if this is the right thing to do here...
>     pathPipeline.attach(ctx.getChannel(), ?);
>   }
> 
> But I'm not sure if that's the right way to go about doing this. I saw in
> another post that it's possible to use the same pipeline for everything and
> do an 'instanceof' check on the message object to decide whether or not a
> ChannelHandler acts on the message, but that seems inefficient and
> needlessly complex when I can create a custom pipeline up front for the
> given path. Any advice on creating custom pipeline definitions for a given
> HTTP path would be greatly appreciated.
> 
> Also, thanks for the great framework - I've enjoyed reading about it and
> using it so far.
> 
> Joel

-- 
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: 260 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20100308/ad732d9c/attachment.bin 


More information about the netty-users mailing list