Chained/Nested Pipeline?

JoelPM joel.meyer at gmail.com
Tue Mar 2 13:55:29 EST 2010


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
-- 
View this message in context: http://n2.nabble.com/Chained-Nested-Pipeline-tp4662922p4662922.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list