diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 892803f3a..54524138e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ configurate3 = "3.7.3" configurate4 = "4.1.2" flare = "2.0.1" log4j = "2.22.1" -netty = "4.2.0.Alpha4" +netty = "4.2.0.Alpha5" [plugins] indra-publishing = "net.kyori.indra.publishing:2.0.6" diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/TransportType.java b/proxy/src/main/java/com/velocitypowered/proxy/network/TransportType.java index 543c85824..3bece5e87 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/TransportType.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/TransportType.java @@ -45,6 +45,7 @@ import io.netty.channel.uring.IoUringIoHandler; import io.netty.channel.uring.IoUringServerSocketChannel; import io.netty.channel.uring.IoUringSocketChannel; import java.util.concurrent.ThreadFactory; +import java.util.function.Supplier; /** * Enumerates the supported transports for Velocity. @@ -53,36 +54,37 @@ public enum TransportType { NIO("NIO", NioServerSocketChannel::new, NioSocketChannel::new, NioDatagramChannel::new, - NioIoHandler.newFactory()), + NioIoHandler::newFactory), EPOLL("epoll", EpollServerSocketChannel::new, EpollSocketChannel::new, EpollDatagramChannel::new, - EpollIoHandler.newFactory()), + EpollIoHandler::newFactory), KQUEUE("kqueue", KQueueServerSocketChannel::new, KQueueSocketChannel::new, KQueueDatagramChannel::new, - KQueueIoHandler.newFactory()), + KQueueIoHandler::newFactory), IO_URING("io_uring", IoUringServerSocketChannel::new, IoUringSocketChannel::new, IoUringDatagramChannel::new, - IoUringIoHandler.newFactory()); + IoUringIoHandler::newFactory); final String name; final ChannelFactory serverSocketChannelFactory; final ChannelFactory socketChannelFactory; final ChannelFactory datagramChannelFactory; - final IoHandlerFactory ioHandlerFactory; + final Supplier ioHandlerFactorySupplier; + volatile IoHandlerFactory ioHandlerFactory; TransportType(final String name, final ChannelFactory serverSocketChannelFactory, final ChannelFactory socketChannelFactory, final ChannelFactory datagramChannelFactory, - final IoHandlerFactory ioHandlerFactory) { + final Supplier ioHandlerFactorySupplier) { this.name = name; this.serverSocketChannelFactory = serverSocketChannelFactory; this.socketChannelFactory = socketChannelFactory; this.datagramChannelFactory = datagramChannelFactory; - this.ioHandlerFactory = ioHandlerFactory; + this.ioHandlerFactorySupplier = ioHandlerFactorySupplier; } @Override @@ -90,7 +92,17 @@ public enum TransportType { return this.name; } + /** + * Creates a new event loop group for the given type. + * + * @param type the type of event loop group to create + * @return the event loop group + */ public EventLoopGroup createEventLoopGroup(final Type type) { + if (this.ioHandlerFactory == null) { + this.ioHandlerFactory = this.ioHandlerFactorySupplier.get(); + } + assert this.ioHandlerFactory != null; return new MultiThreadIoEventLoopGroup( 0, createThreadFactory(this.name, type), this.ioHandlerFactory); }