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
Conversation
common/src/main/java/io/netty/util/concurrent/AbstractEventExecutor.java
Show resolved
Hide resolved
common/src/main/java/io/netty/util/concurrent/EventExecutorGroup.java
Outdated
Show resolved
Hide resolved
common/src/main/java/io/netty/util/concurrent/RunnableScheduledFutureAdapter.java
Outdated
Show resolved
Hide resolved
common/src/main/java/io/netty/util/concurrent/UnorderedThreadPoolEventExecutor.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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
common/src/main/java/io/netty/util/concurrent/AbstractEventExecutorGroup.java
Outdated
Show resolved
Hide resolved
@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
3e467bd
to
55cc686
Compare
@normanmaurer @NiteshKant Updated, please take a look. |
common/src/main/java/io/netty/util/concurrent/EventExecutorGroup.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
@Override | ||
public <T> Future<T> submit(Runnable task, T result) { | ||
return (Future<T>) super.submit(task, result); | ||
return (Future<T>) executor.submit(task, result); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@normanmaurer Comments addressed, please take a look. |
There was a problem hiding this 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
common/src/test/java/io/netty/util/concurrent/UnorderedThreadPoolEventExecutorTest.java
Show resolved
Hide resolved
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 { |
There was a problem hiding this comment.
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.
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*
andshutdown*
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