GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Clean up Future/Promises API by normanmaurer · Pull Request #16039 · netty/netty Conversation
Member
Motivation: Modification:
Result:
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
yawkat
reviewed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since i'm sure this is common, and this new pattern leads to lambda allocations, maybe it's worthwhile to cache these standard future listeners in the channel?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not keep a built-in constant around, eg in ChannelContext?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it can't be a constant because the listener doesn't know about the channel anymore
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes... we can do something similar once we bring back
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
yawkat
reviewed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the wildcard? Void is final
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because its what
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
yawkat
reviewed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it may be worthwhile using wildcards here and elsewhere. Using On the other hand, the advantages of the wildcard are probably minor, and it makes the code more verbose for all users.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure about that.. might make things a lot more verbose. On the other hand people could just use
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another option would be adding a
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||
| @Override | ||
| default ChannelFuture bind(SocketAddress localAddress) { | ||
| default Future<Void> bind(SocketAddress localAddress) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
bind and connect should be Future<QuicChannel> or Future<Channel>
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@chrisvest no... these are methods on the Channel itself and so should return Void. Only the one on *Bootstrap will return Future<Channel> (just as we did in the old main)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| .handler(HAProxyMessageEncoder.INSTANCE) | ||
| .group(group) | ||
| .connect(localAddress).sync().channel(); | ||
| .connect(localAddress).sync().getNow(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think we could replace a lot of these sync+getNow pattern instances with just get()
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This was done
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Future<Channel> ccf = cb.connect(new InetSocketAddress(NetUtil.LOCALHOST, port)); | ||
| assertTrue(ccf.awaitUninterruptibly().isSuccess()); | ||
| Channel clientChannel = ccf.channel(); | ||
| Channel clientChannel = ccf.getNow(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We can just do
Channel clientChannel = cb.connect(new InetSocketAddress(NetUtil.LOCALHOST, port)).get();
An let any failure propagate from get() - we'd get more info than the assertTrue failing.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Future<Channel> ccf = cb.connect(new InetSocketAddress(NetUtil.LOCALHOST, port)); | ||
| assertTrue(ccf.awaitUninterruptibly().isSuccess()); | ||
| clientChannel = ccf.channel(); | ||
| clientChannel = ccf.getNow(); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Here I think we could also just call get()
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
|
||
| // This method is invoked before channelRegistered() is triggered. Give user handlers a chance to set up | ||
| // the pipeline in its channelRegistered() implementation. | ||
| channel.executor().execute(new Runnable() { | ||
| regFuture.executor().execute(new Runnable() { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
In this case we could probably attach a listener to regFuture to guarantee our callback runs after it completes.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| */ | ||
| void register(ChannelPromise promise); | ||
| void register(Promise<Void> promise); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This looks weird now. Shouldn't this be a Promise<Channel> and take a target Channel parameter?
Same for bind, connect, disconnect, close, deregister and shutdown.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
No... IoTransport is usually implemented by the Channel implementation anyway that is used by the ChannelPipeline and so the result of the promise is not really used at all.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
(This is used by the head context of DefaultChannelPipeline).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| public void operationComplete(Future<? extends Void> f) { | ||
| if (f.isSuccess()) { | ||
| generateTraffic(ctx, this); | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
missing failure case?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It's the same as before... I just ported the code that's it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
327d44e to
a2bd174
Compare
Motivation: The generics for the existing futures, promises, and listeners are too complicated. This complication comes from the existence of `ChannelPromise` and `ChannelFuture`, which forces listeners to care about the particular _type_ of future being listened on. Modification: * Make the `FutureListener`, the default listener API, retiring the `GenericFutureListener` since we no longer need to abstract over the type of the future. * Change all uses of `ChannelPromise` to `Promise<Void>`. * Change all uses of `ChannelFuture` to `Future<Void>`. * Change all uses of `GenericFutureListener` to `FutureListener` as needed. * Remove `ChannelFutureListener` and `GenericFutureListener`. * Remove `ChannelPromise` and `ChannelFuture` — all usages now rely on the plain `Future` and `Promise` APIs. * Remove `CompleteChannelFuture`, `SucceededChannelFuture`, and `FailedChannelFuture`. Result: Cleaner generics and more straight forward code.
9c183cd to
a1b7610
Compare
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.