Skip to content

Commit 677c43f

Browse files
committed
nit: clean up getNativeTransportFactory
1 parent 9d0f1d7 commit 677c43f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import io.netty.resolver.NameResolver;
3939
import io.netty.util.Timer;
4040
import io.netty.util.concurrent.*;
41+
import io.netty.util.internal.PlatformDependent;
4142
import org.asynchttpclient.*;
4243
import org.asynchttpclient.channel.ChannelPool;
4344
import org.asynchttpclient.channel.ChannelPoolPartitioning;
@@ -188,15 +189,20 @@ private Bootstrap newBootstrap(ChannelFactory<? extends Channel> channelFactory,
188189

189190
@SuppressWarnings("unchecked")
190191
private TransportFactory<? extends Channel, ? extends EventLoopGroup> getNativeTransportFactory() {
192+
String nativeTransportFactoryClassName = null;
193+
if (PlatformDependent.isOsx()) {
194+
nativeTransportFactoryClassName = "org.asynchttpclient.netty.channel.KQueueTransportFactory";
195+
} else if (!PlatformDependent.isWindows()) {
196+
nativeTransportFactoryClassName = "org.asynchttpclient.netty.channel.EpollTransportFactory";
197+
}
198+
191199
try {
192-
return (TransportFactory<? extends Channel, ? extends EventLoopGroup>) Class.forName("org.asynchttpclient.netty.channel.EpollTransportFactory").newInstance();
193-
} catch (Exception e) {
194-
try {
195-
return (TransportFactory<? extends Channel, ? extends EventLoopGroup>) Class.forName("org.asynchttpclient.netty.channel.KQueueTransportFactory").newInstance();
196-
} catch (Exception e1) {
197-
throw new IllegalArgumentException("No suitable native transport (epoll or kqueue) available");
200+
if (nativeTransportFactoryClassName != null) {
201+
return (TransportFactory<? extends Channel, ? extends EventLoopGroup>) Class.forName(nativeTransportFactoryClassName).newInstance();
198202
}
203+
} catch (Exception e) {
199204
}
205+
throw new IllegalArgumentException("No suitable native transport (epoll or kqueue) available");
200206
}
201207

202208
public void configureBootstraps(NettyRequestSender requestSender) {

0 commit comments

Comments
 (0)