Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netty Future no longer extends JDK Future #11647

Merged
merged 8 commits into from Sep 8, 2021

Conversation

chrisvest
Copy link
Contributor

Motivation:
It is important to avoid blocking method calls in an event loop thread, since that can stall the system.
Netty's Future interface was extending the JDK Future interface, which included a number of blocking methods of questionable use in Netty.
We wish to reduce the number of blocking methods on the Future API in order to discourage their use a little.
Further more, the Netty Future specification of the behaviour of the cancel() and isDone() methods are inconsistent with those of the JDK Future.
If Netty's Future stop extending the JDK Future interface, it will also no longer be bound by its specification.

Modification:
Make Netty's Future no longer extend the JDK Future interface.
Change the EvenExecutorGroup interface to no longer extend ScheduledExecutorService.
The EventExecutorGroup still extends Executor, because Executor does not dictate any return type of the execute() method — this is also useful in the DefaultFutureCompletionStage implementation.
The Netty ScheduledFuture interface has been removed since it provided no additional features that were actually used.
Numerous changes to use sites that previously relied on the JDK types.
Remove the Future.cancel() method that took a boolean argument — this argument was always ignored in our implementations, which was another spec deviation.
Various invoke* and shutdown* methods have been removed from the EvenExecutorGroup API since it no longer extends ScheduledExecutorService — these were either not used anywhere, or deprecated with better alternatives available.

Result:
Cleaner code, leaner API.

Fixes #7712, #8520

Copy link
Member

@NiteshKant NiteshKant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after open comments are resolved

@normanmaurer
Copy link
Member

@chrisvest can you please rebase ?

Motivation:
It is important to avoid blocking method calls in an event loop thread, since that can stall the system.
Netty's Future interface was extending the JDK Future interface, which included a number of blocking methods of questionable use in Netty.
We wish to reduce the number of blocking methods on the Future API in order to discourage their use a little.
Further more, the Netty Future specification of the behaviour of the cancel() and isDone() methods are inconsistent with those of the JDK Future.
If Netty's Future stop extending the JDK Future interface, it will also no longer be bound by its specification.

Modification:
Make Netty's Future no longer extend the JDK Future interface.
Change the EvenExecutorGroup interface to no longer extend ScheduledExecutorService.
The EventExecutorGroup still extends Executor, because Executor does not dictate any return type of the `execute()` method — this is also useful in the DefaultFutureCompletionStage implementation.
The Netty ScheduledFuture interface has been removed since it provided no additional features that were actually used.
Numerous changes to use sites that previously relied on the JDK types.
Remove the `Future.cancel()` method that took a boolean argument — this argument was always ignored in our implementations, which was another spec deviation.
Various `invoke*` and `shutdown*` methods have been removed from the EvenExecutorGroup API since it no longer extends ScheduledExecutorService — these were either not used anywhere, or deprecated with better alternatives available.

Result:
Cleaner code, leaner API.

Fixes netty#7712, netty#8520
@chrisvest
Copy link
Contributor Author

@normanmaurer @NiteshKant Updated, please take a look.

}

@Override
public <T> Future<T> submit(Runnable task, T result) {
return (Future<T>) super.submit(task, result);
return (Future<T>) executor.submit(task, result);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Future.executor() exists I think we need to take special action to ensure the returned Future actually return UnorderedThreadPoolEventExecutor and not the "inner" executor. Same is true for all the other methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already the case because of how the inner executor decorates tasks. I have added a test for this.

@chrisvest
Copy link
Contributor Author

@normanmaurer Comments addressed, please take a look.

Copy link
Member

@normanmaurer normanmaurer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing... after that :shipit:

Co-authored-by: Norman Maurer <norman_maurer@apple.com>
* {@linkplain Thread#interrupt() interrupted}.
* @throws ExecutionException If the task failed, either by throwing an exception, or through cancellation.
* @throws TimeoutException If the future did not complete within the specified timeout.
*/
default V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in this PR but wondering if we should remove blocking methods from the Future. If at all blocking is required which I believe would be for test/examples then asJdkFuture() can be used to get to blocking methods.

@chrisvest chrisvest dismissed normanmaurer’s stale review September 8, 2021 07:05

Change request got merged

@chrisvest chrisvest merged commit 59275fb into netty:main Sep 8, 2021
@chrisvest chrisvest deleted the 5x-no-jdk-future branch September 8, 2021 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants