2020import com .velocitypowered .proxy .util .concurrent .VelocityNettyThreadFactory ;
2121import io .netty .channel .ChannelFactory ;
2222import io .netty .channel .EventLoopGroup ;
23+ import io .netty .channel .IoHandlerFactory ;
24+ import io .netty .channel .MultiThreadIoEventLoopGroup ;
2325import io .netty .channel .epoll .Epoll ;
2426import io .netty .channel .epoll .EpollDatagramChannel ;
25- import io .netty .channel .epoll .EpollEventLoopGroup ;
27+ import io .netty .channel .epoll .EpollIoHandler ;
2628import io .netty .channel .epoll .EpollServerSocketChannel ;
2729import io .netty .channel .epoll .EpollSocketChannel ;
2830import io .netty .channel .kqueue .KQueue ;
2931import io .netty .channel .kqueue .KQueueDatagramChannel ;
30- import io .netty .channel .kqueue .KQueueEventLoopGroup ;
32+ import io .netty .channel .kqueue .KQueueIoHandler ;
3133import io .netty .channel .kqueue .KQueueServerSocketChannel ;
3234import io .netty .channel .kqueue .KQueueSocketChannel ;
33- import io .netty .channel .nio .NioEventLoopGroup ;
35+ import io .netty .channel .nio .NioIoHandler ;
3436import io .netty .channel .socket .DatagramChannel ;
3537import io .netty .channel .socket .ServerSocketChannel ;
3638import io .netty .channel .socket .SocketChannel ;
3739import io .netty .channel .socket .nio .NioDatagramChannel ;
3840import io .netty .channel .socket .nio .NioServerSocketChannel ;
3941import io .netty .channel .socket .nio .NioSocketChannel ;
42+ import io .netty .channel .uring .IoUring ;
43+ import io .netty .channel .uring .IoUringDatagramChannel ;
44+ import io .netty .channel .uring .IoUringIoHandler ;
45+ import io .netty .channel .uring .IoUringServerSocketChannel ;
46+ import io .netty .channel .uring .IoUringSocketChannel ;
4047import java .util .concurrent .ThreadFactory ;
41- import java .util .function .BiFunction ;
48+ import java .util .function .Supplier ;
4249
4350/**
4451 * Enumerates the supported transports for Velocity.
@@ -47,41 +54,52 @@ public enum TransportType {
4754 NIO ("NIO" , NioServerSocketChannel ::new ,
4855 NioSocketChannel ::new ,
4956 NioDatagramChannel ::new ,
50- ( name , type ) -> new NioEventLoopGroup ( 0 , createThreadFactory ( name , type )) ),
57+ NioIoHandler :: newFactory ),
5158 EPOLL ("epoll" , EpollServerSocketChannel ::new ,
5259 EpollSocketChannel ::new ,
5360 EpollDatagramChannel ::new ,
54- ( name , type ) -> new EpollEventLoopGroup ( 0 , createThreadFactory ( name , type )) ),
61+ EpollIoHandler :: newFactory ),
5562 KQUEUE ("kqueue" , KQueueServerSocketChannel ::new ,
5663 KQueueSocketChannel ::new ,
5764 KQueueDatagramChannel ::new ,
58- (name , type ) -> new KQueueEventLoopGroup (0 , createThreadFactory (name , type )));
65+ KQueueIoHandler ::newFactory ),
66+ IO_URING ("io_uring" , IoUringServerSocketChannel ::new ,
67+ IoUringSocketChannel ::new ,
68+ IoUringDatagramChannel ::new ,
69+ IoUringIoHandler ::newFactory );
5970
6071 final String name ;
6172 final ChannelFactory <? extends ServerSocketChannel > serverSocketChannelFactory ;
6273 final ChannelFactory <? extends SocketChannel > socketChannelFactory ;
6374 final ChannelFactory <? extends DatagramChannel > datagramChannelFactory ;
64- final BiFunction < String , Type , EventLoopGroup > eventLoopGroupFactory ;
75+ final Supplier < IoHandlerFactory > ioHandlerFactorySupplier ;
6576
6677 TransportType (final String name ,
6778 final ChannelFactory <? extends ServerSocketChannel > serverSocketChannelFactory ,
6879 final ChannelFactory <? extends SocketChannel > socketChannelFactory ,
6980 final ChannelFactory <? extends DatagramChannel > datagramChannelFactory ,
70- final BiFunction < String , Type , EventLoopGroup > eventLoopGroupFactory ) {
81+ final Supplier < IoHandlerFactory > ioHandlerFactorySupplier ) {
7182 this .name = name ;
7283 this .serverSocketChannelFactory = serverSocketChannelFactory ;
7384 this .socketChannelFactory = socketChannelFactory ;
7485 this .datagramChannelFactory = datagramChannelFactory ;
75- this .eventLoopGroupFactory = eventLoopGroupFactory ;
86+ this .ioHandlerFactorySupplier = ioHandlerFactorySupplier ;
7687 }
7788
7889 @ Override
7990 public String toString () {
8091 return this .name ;
8192 }
8293
94+ /**
95+ * Creates a new event loop group for the given type.
96+ *
97+ * @param type the type of event loop group to create
98+ * @return the event loop group
99+ */
83100 public EventLoopGroup createEventLoopGroup (final Type type ) {
84- return this .eventLoopGroupFactory .apply (this .name , type );
101+ return new MultiThreadIoEventLoopGroup (
102+ 0 , createThreadFactory (this .name , type ), this .ioHandlerFactorySupplier .get ());
85103 }
86104
87105 private static ThreadFactory createThreadFactory (final String name , final Type type ) {
@@ -98,6 +116,10 @@ public static TransportType bestType() {
98116 return NIO ;
99117 }
100118
119+ if (IoUring .isAvailable () && !Boolean .getBoolean ("velocity.disable-iouring-transport" )) {
120+ return IO_URING ;
121+ }
122+
101123 if (Epoll .isAvailable ()) {
102124 return EPOLL ;
103125 }
0 commit comments