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

Make EventLoopGroup check independent of EventLoopGroup class files #1857

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ public class ChannelManager {

private AsyncHttpClientHandler wsHandler;

private boolean isInstanceof(Object object, String name) {
final Class<?> clazz;
try {
clazz = Class.forName(name, false, null);
} catch (ClassNotFoundException ignored) {
return false;
}
return clazz.isInstance(object);
}

public ChannelManager(final AsyncHttpClientConfig config, Timer nettyTimer) {
this.config = config;

Expand Down Expand Up @@ -153,11 +163,11 @@ public ChannelManager(final AsyncHttpClientConfig config, Timer nettyTimer) {

if (eventLoopGroup instanceof NioEventLoopGroup) {
transportFactory = NioTransportFactory.INSTANCE;
} else if (eventLoopGroup instanceof EpollEventLoopGroup) {
} else if (isInstanceof(eventLoopGroup, "io.netty.channel.epoll.EpollEventLoopGroup")) {
transportFactory = new EpollTransportFactory();
} else if (eventLoopGroup instanceof KQueueEventLoopGroup) {
} else if (isInstanceof(eventLoopGroup, "io.netty.channel.kqueue.KQueueEventLoopGroup")) {
transportFactory = new KQueueTransportFactory();
} else if (eventLoopGroup instanceof IOUringEventLoopGroup) {
} else if (isInstanceof(eventLoopGroup, "io.netty.incubator.channel.uring.IOUringEventLoopGroup")) {
transportFactory = new IoUringIncubatorTransportFactory();
} else {
throw new IllegalArgumentException("Unknown event loop group " + eventLoopGroup.getClass().getSimpleName());
Expand Down