22
33import io .netty .channel .ChannelFactory ;
44import io .netty .channel .EventLoopGroup ;
5+ import io .netty .channel .MultiThreadIoEventLoopGroup ;
56import io .netty .channel .epoll .Epoll ;
67import io .netty .channel .epoll .EpollDatagramChannel ;
78import io .netty .channel .epoll .EpollEventLoopGroup ;
9+ import io .netty .channel .epoll .EpollIoHandler ;
810import io .netty .channel .epoll .EpollServerSocketChannel ;
911import io .netty .channel .epoll .EpollSocketChannel ;
1012import io .netty .channel .kqueue .KQueue ;
1113import io .netty .channel .kqueue .KQueueDatagramChannel ;
1214import io .netty .channel .kqueue .KQueueEventLoopGroup ;
15+ import io .netty .channel .kqueue .KQueueIoHandler ;
1316import io .netty .channel .kqueue .KQueueServerSocketChannel ;
1417import io .netty .channel .kqueue .KQueueSocketChannel ;
1518import io .netty .channel .nio .NioEventLoopGroup ;
19+ import io .netty .channel .nio .NioIoHandler ;
1620import io .netty .channel .socket .DatagramChannel ;
1721import io .netty .channel .socket .ServerSocketChannel ;
1822import io .netty .channel .socket .SocketChannel ;
1923import io .netty .channel .socket .nio .NioDatagramChannel ;
2024import io .netty .channel .socket .nio .NioServerSocketChannel ;
2125import io .netty .channel .socket .nio .NioSocketChannel ;
22- import io .netty .incubator . channel .uring .IOUring ;
23- import io .netty .incubator . channel .uring .IOUringDatagramChannel ;
24- import io .netty .incubator . channel .uring .IOUringEventLoopGroup ;
25- import io .netty .incubator . channel .uring .IOUringServerSocketChannel ;
26- import io .netty .incubator . channel .uring .IOUringSocketChannel ;
26+ import io .netty .channel .uring .IoUring ;
27+ import io .netty .channel .uring .IoUringDatagramChannel ;
28+ import io .netty .channel .uring .IoUringIoHandler ;
29+ import io .netty .channel .uring .IoUringServerSocketChannel ;
30+ import io .netty .channel .uring .IoUringSocketChannel ;
2731
2832import java .util .concurrent .ThreadFactory ;
29- import java .util .function .Function ;
33+ import java .util .function .BiFunction ;
3034
3135public class TransportHelper {
3236 public static final TransportHelper .TransportType TRANSPORT_TYPE = TransportHelper .determineTransportMethod ();
37+ public static final boolean NEW_NETTY = isClassAvailable ("io.netty.channel.MultiThreadIoEventLoopGroup" );
3338
3439 public enum TransportMethod {
3540 NIO , EPOLL , KQUEUE , IO_URING
@@ -42,24 +47,28 @@ public record TransportType(TransportMethod method,
4247 ChannelFactory <? extends SocketChannel > socketChannelFactory ,
4348 Class <? extends DatagramChannel > datagramChannelClass ,
4449 ChannelFactory <? extends DatagramChannel > datagramChannelFactory ,
45- Function < ThreadFactory , EventLoopGroup > eventLoopGroupFactory ,
50+ BiFunction < Integer , ThreadFactory , EventLoopGroup > eventLoopGroupFactory ,
4651 boolean supportsTcpFastOpenServer ,
4752 boolean supportsTcpFastOpenClient ) {
4853 }
4954
55+ @ SuppressWarnings ("deprecation" )
5056 private static TransportType determineTransportMethod () {
51- if (isClassAvailable ("io.netty.incubator.channel.uring.IOUring" ) && IOUring .isAvailable ()) {
57+ if (isClassAvailable ("io.netty.channel.uring.IoUring" )
58+ && IoUring .isAvailable ()
59+ && Boolean .getBoolean ("Mcpl.io_uring" )
60+ ) {
5261 return new TransportType (
5362 TransportMethod .IO_URING ,
54- IOUringServerSocketChannel .class ,
55- IOUringServerSocketChannel ::new ,
56- IOUringSocketChannel .class ,
57- IOUringSocketChannel ::new ,
58- IOUringDatagramChannel .class ,
59- IOUringDatagramChannel ::new ,
60- factory -> new IOUringEventLoopGroup ( 0 , factory ),
61- IOUring .isTcpFastOpenServerSideAvailable (),
62- IOUring .isTcpFastOpenClientSideAvailable ()
63+ IoUringServerSocketChannel .class ,
64+ IoUringServerSocketChannel ::new ,
65+ IoUringSocketChannel .class ,
66+ IoUringSocketChannel ::new ,
67+ IoUringDatagramChannel .class ,
68+ IoUringDatagramChannel ::new ,
69+ ( threads , factory ) -> new MultiThreadIoEventLoopGroup ( threads , factory , IoUringIoHandler . newFactory () ),
70+ IoUring .isTcpFastOpenServerSideAvailable (),
71+ IoUring .isTcpFastOpenClientSideAvailable ()
6372 );
6473 }
6574
@@ -72,7 +81,8 @@ private static TransportType determineTransportMethod() {
7281 EpollSocketChannel ::new ,
7382 EpollDatagramChannel .class ,
7483 EpollDatagramChannel ::new ,
75- factory -> new EpollEventLoopGroup (0 , factory ),
84+ NEW_NETTY ? (threads , factory ) ->
85+ new MultiThreadIoEventLoopGroup (threads , factory , EpollIoHandler .newFactory ()) : EpollEventLoopGroup ::new ,
7686 Epoll .isTcpFastOpenServerSideAvailable (),
7787 Epoll .isTcpFastOpenClientSideAvailable ()
7888 );
@@ -87,7 +97,8 @@ private static TransportType determineTransportMethod() {
8797 KQueueSocketChannel ::new ,
8898 KQueueDatagramChannel .class ,
8999 KQueueDatagramChannel ::new ,
90- factory -> new KQueueEventLoopGroup (0 , factory ),
100+ NEW_NETTY ? (threads , factory ) ->
101+ new MultiThreadIoEventLoopGroup (threads , factory , KQueueIoHandler .newFactory ()) : KQueueEventLoopGroup ::new ,
91102 KQueue .isTcpFastOpenServerSideAvailable (),
92103 KQueue .isTcpFastOpenClientSideAvailable ()
93104 );
@@ -101,7 +112,8 @@ private static TransportType determineTransportMethod() {
101112 NioSocketChannel ::new ,
102113 NioDatagramChannel .class ,
103114 NioDatagramChannel ::new ,
104- factory -> new NioEventLoopGroup (0 , factory ),
115+ NEW_NETTY ? (threads , factory ) ->
116+ new MultiThreadIoEventLoopGroup (threads , factory , NioIoHandler .newFactory ()) : NioEventLoopGroup ::new ,
105117 false ,
106118 false
107119 );
0 commit comments