Repository navigation
Add a way to check if a IoEventLoopGroup / IoEventLoop is using a spe… - #14019
Conversation
|
Noticed I need something like this when porting our testsuite to the new API. |
d291bb9 to
82b41c4
Compare
| * @param handlerType the type of the {@link IoHandler}. | ||
| * @return if used or not. | ||
| */ | ||
| default boolean isIoType(Class<? extends IoHandler> handlerType) { |
There was a problem hiding this comment.
I am open for a better name
bryce-anderson
left a comment
There was a problem hiding this comment.
This seems good code wise, but I'm trying to figure out where this would be used. You mentioned tests: are there any good examples of tests that could be updated to make its purpose more obvious?
Yeah for example we used something like this: Beside this sometimes users did do instanceof checks to decide which |
…cific IoHandler Motivation: We need to provide a way for the user to check if an `IoEventLoopGroup` is supporting NIO / Epoll / KQueue etc. Before people often used `group instanceof NioEventLoopGroup` etc. Modifications: Add new method that people can use to check what kind of IO is used. Result: People can use `group.isIoType(NioHandler.class)` etc.
…opTest.java Co-authored-by: Bryce Anderson <[email protected]>
75ff5a4 to
cd5ef5e
Compare
bryce-anderson
left a comment
There was a problem hiding this comment.
Yeah for example we used something like this:
So the example could change to look like this?
diff --git a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketMultipleConnectTest.java b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketMultipleConnectTest.java
index b70313545e..219e6c9365 100644
--- a/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketMultipleConnectTest.java
+++ b/transport-native-epoll/src/test/java/io/netty/channel/epoll/EpollSocketMultipleConnectTest.java
@@ -18,7 +18,8 @@ package io.netty.channel.epoll;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.EventLoopGroup;
-import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.IoEventLoopGroup;
+import io.netty.channel.nio.NioIoHandler;
import io.netty.testsuite.transport.TestsuitePermutation;
import io.netty.testsuite.transport.socket.SocketMultipleConnectTest;
@@ -34,8 +35,12 @@ public class EpollSocketMultipleConnectTest extends SocketMultipleConnectTest {
for (TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap> comboFactory
: EpollSocketTestPermutation.INSTANCE.socketWithFastOpen()) {
EventLoopGroup group = comboFactory.newClientInstance().config().group();
- if (group instanceof NioEventLoopGroup || group instanceof EpollEventLoopGroup) {
- factories.add(comboFactory);
+
+ if (group instanceof IoEventLoopGroup) {
+ IoEventLoopGroup ioGroup = (IoEventLoopGroup) group;
+ if (ioGroup.isIoType(NioIoHandler.class) || ioGroup.isIoType(EpollIoHandler.class)) {
+ factories.add(comboFactory);
+ }
}
}
return factories;
It's more code but we can get rid of most of the sub-types which is good. If that's the motivation maybe we can adjust the test to show how to use it. After that
.
|
Yes ... I did this as a followup |
…cific IoHandler
Motivation:
We need to provide a way for the user to check if an
IoEventLoopGroupis supporting NIO / Epoll / KQueue etc. Before people often usedgroup instanceof NioEventLoopGroupetc.Modifications:
Add new method that people can use to check what kind of IO is used.
Result:
People can use
group.isIoType(NioHandler.class)etc.