dynamically channging netty pipeline

853 views
Skip to first unread message

Tanima Saini

unread,
Mar 2, 2015, 2:13:48 AM3/2/15
to ne...@googlegroups.com
Hi,

I am using netty 4.0.25Final to write a netty HTTP server. I need to add various handlers in the pipeline depending upon some parameters in HTTP GET request.

pipeline.addLast(new HttpRequestDecoder(4096, 8192, 8192, false),
                 new HttpResponseEncoder(),
                 new HttpObjectAggregator(1048576),
                 decisionHandler
                 );

Same pipeline is used if multiple requests come from the same connection. Request1 may need Handler1, Request2 may need Handler2 and Request3 may need Handler3. Suppose requests are coming as Request1, Request2, Request3. Request1 would modify the pipeline to add Handler1.

  1. In subsequent calls do we always need to check if the pipleline is already modified, then remove the unwanted handlers? And then add the required handlers which are needed to handler that particular call?

  2. Or should I remove the handler before going to the next handler (fireChannelRead(object))? Will it have performance impact?

  3. Is there any other way to do this?


Thanks & Regards,

Tanima

Norman Maurer

unread,
Mar 2, 2015, 8:59:41 AM3/2/15
to ne...@googlegroups.com, Tanima Saini
Answers inline...


On 2 Mar 2015 at 08:13:51, Tanima Saini (tanim...@gmail.com) wrote:

Hi,

I am using netty 4.0.25Final to write a netty HTTP server. I need to add various handlers in the pipeline depending upon some parameters in HTTP GET request.

pipeline.addLast(new HttpRequestDecoder(4096, 8192, 8192, false),
                 new HttpResponseEncoder(),
                 new HttpObjectAggregator(1048576),
                 decisionHandler
                 );

Same pipeline is used if multiple requests come from the same connection. Request1 may need Handler1, Request2 may need Handler2 and Request3 may need Handler3. Suppose requests are coming as Request1, Request2, Request3. Request1 would modify the pipeline to add Handler1.

  1. In subsequent calls do we always need to check if the pipleline is already modified, then remove the unwanted handlers? And then add the required handlers which are needed to handler that particular call?

Yes you will need to remove the handlers that you not need anymore as otherwise it will flow through them.


  1. Or should I remove the handler before going to the next handler (fireChannelRead(object))? Will it have performance impact?

The implementation use a doubly-linked list so sure there is some overhead. That said modification on the pipeline are usually very fast.


  1. Is there any other way to do this?

Nope..

We may introduce chained ChannelPipelines at some point but we did not yet.



Thanks & Regards,

Tanima


-- 
Norman Maurer


--
You received this message because you are subscribed to the Google Groups "Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netty+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netty/1bb3d3ae-9eb9-494a-98fa-a8ae9790d1d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages