diff --git a/client/pom.xml b/client/pom.xml index c9e13aea7e..220b01b687 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -60,6 +60,13 @@ netty-transport-native-kqueue osx-x86_64 + + io.netty.incubator + netty-incubator-transport-native-io_uring + 0.0.8.Final + provided + true + org.reactivestreams reactive-streams diff --git a/client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java b/client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java index b93dfb380e..2ffd87d955 100755 --- a/client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java +++ b/client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java @@ -141,6 +141,9 @@ public ChannelManager(final AsyncHttpClientConfig config, Timer nettyTimer) { transportFactory = new EpollTransportFactory(); } else if (eventLoopGroup instanceof KQueueEventLoopGroup) { transportFactory = new KQueueTransportFactory(); + } else if (eventLoopGroup.getClass().getSimpleName().equals("IOUringEventLoopGroup")) { + // NOTE: instanceof is not used since this is an optional dependency + transportFactory = new IOUringTransportFactory(); } else { throw new IllegalArgumentException("Unknown event loop group " + eventLoopGroup.getClass().getSimpleName()); } diff --git a/client/src/main/java/org/asynchttpclient/netty/channel/IOUringTransportFactory.java b/client/src/main/java/org/asynchttpclient/netty/channel/IOUringTransportFactory.java new file mode 100644 index 0000000000..9dbebb786e --- /dev/null +++ b/client/src/main/java/org/asynchttpclient/netty/channel/IOUringTransportFactory.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 AsyncHttpClient Project. All rights reserved. + * + * This program is licensed to you under the Apache License Version 2.0, + * and you may not use this file except in compliance with the Apache License Version 2.0. + * You may obtain a copy of the Apache License Version 2.0 at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the Apache License Version 2.0 is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. + */ +package org.asynchttpclient.netty.channel; + +import io.netty.incubator.channel.uring.IOUring; +import io.netty.incubator.channel.uring.IOUringEventLoopGroup; +import io.netty.incubator.channel.uring.IOUringSocketChannel; + +import java.util.concurrent.ThreadFactory; + +class IOUringTransportFactory implements TransportFactory { + + IOUringTransportFactory() { + try { + Class.forName("io.netty.incubator.channel.uring.IOUring"); + } catch (ClassNotFoundException e) { + throw new IllegalStateException("The io_uring transport is not available"); + } + if (!IOUring.isAvailable()) { + throw new IllegalStateException("The io_uring transport is not supported"); + } + } + + @Override + public IOUringSocketChannel newChannel() { + return new IOUringSocketChannel(); + } + + @Override + public IOUringEventLoopGroup newEventLoopGroup(int ioThreadsCount, ThreadFactory threadFactory) { + return new IOUringEventLoopGroup(ioThreadsCount, threadFactory); + } +}