question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Netty5] ChannelPipeline mutating methods signature

See original GitHub issue

All the methods that mutate the ChannelPipeline are currently “synchronous”. This means all manipulation of the pipeline must complete before modifier methods return, and theChannelPipeline implementation must therefore account for concurrency. All of the interaction with the ChannelPipeline is inside the EventLoop and we can therefore delay modification until we are in the EventLoop. This will reduce complexity of the ChannelPipeline implementation, and also remove the current “best effort” concurrency code in AbstractChannelHandlerContext.

There are currently 2 different ideas here:

  1. Have all methods just return ChannelFuture which completes when the pipeline is modified (e.g. on the EventLoop). If we do this we also most likely should allow to pass in a ChannelPromise that is used for notifications.
  2. Only allow pipeline modifications on the EventLoop.

I am currently in favour of 1) as this is also what we did in SwiftNIO with great success and still will allow people to just use ChannelPipeline from “any thread”.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
normanmaurercommented, Jan 31, 2019

@nicktrav I like your idea. That said we may still want to return a Future (not sure about this yet).

@RoganDawes I think we should just not support the “varargs” anymore to fix the problem. About how this would look like when we return futures, I think we would allow to chain calls via some lambdas.

1reaction
njhillcommented, Jan 31, 2019

@normanmaurer is this obsolete in light of #8778?

Related to this and #8156, I had another idea w.r.t. the pipeline manipulation API design, i.e. how best to reference handlers after they are added. Why not have all the addX/replace methods return the new handler context, and move all of the addBefore, addAfter, replace, remove methods from the pipeline to the context?

I think this would address most/all of the frustrations raised in #8156, including most of the cartesian product explosion. You could do things such as:

channel.pipeline().addFirst(handler1).addAfter(handler2, "myname").addAfter(handler3);

channel.pipeline().context("myname").replace(handler4);

MyHandler removed = channel.pipeline().context(MyHandler.class).remove();

etc.

If we still want to avoid the synchronization here, all these methods could instead return Future<ChannelHandlerContext> along the lines of your suggestion 1 above.

cc @ejona86

Read more comments on GitHub >

github_iconTop Results From Across the Web

ChannelPipeline (Netty API Reference (4.0.56.Final))
A list of ChannelHandler s which handles or intercepts inbound events and outbound operations of a Channel . ChannelPipeline implements an advanced form...
Read more >
Under what circumstances will a ChannelPipeline have all of ...
1 Answer 1 ... Netty itself doesn't remove handlers form the Pipeline. ChannelPipeline is gathered by GC as regular Java object when it...
Read more >
Netty Notes Part 3 - Channel Pipeline and EventLoops
Managing passing the events to next handler in chain ChannelHandlerContext • Associates ChannelHandler and ChannelPipeline. Methods ...
Read more >
Management & Monitoring - Micronaut Documentation
UriBuilder methods queryParam and replaceQueryParam ignore null values. It is possible to stop the Netty server without stopping the Application context.
Read more >
Language Power - Aphyr
There's a Java library called Netty, which helps you write network servers. ... remember its method signature and constructor, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found