24
24
import io .netty .channel .ConnectTimeoutException ;
25
25
import io .netty .channel .EventLoopGroup ;
26
26
import io .netty .channel .MultiThreadIoEventLoopGroup ;
27
+ import io .netty .channel .nio .NioEventLoopGroup ;
27
28
import io .netty .channel .nio .NioIoHandler ;
28
29
import java .net .UnknownHostException ;
29
30
import java .security .cert .X509Certificate ;
@@ -62,6 +63,8 @@ final class Utils {
62
63
static final String SUBSCRIPTION_PROPERTY_FILTER_PREFIX = "filter." ;
63
64
static final String SUBSCRIPTION_PROPERTY_MATCH_UNFILTERED = "match-unfiltered" ;
64
65
66
+ static final boolean IS_NETTY_4_2 ;
67
+
65
68
static {
66
69
Map <Short , String > labels = new HashMap <>();
67
70
Arrays .stream (Constants .class .getDeclaredFields ())
@@ -77,6 +80,14 @@ final class Utils {
77
80
}
78
81
});
79
82
CONSTANT_LABELS = copyOf (labels );
83
+
84
+ boolean netty4_2 = true ;
85
+ try {
86
+ Class .forName ("io.netty.channel.MultiThreadIoEventLoopGroup" );
87
+ } catch (ClassNotFoundException e ) {
88
+ netty4_2 = false ;
89
+ }
90
+ IS_NETTY_4_2 = netty4_2 ;
80
91
}
81
92
82
93
static final AddressResolver DEFAULT_ADDRESS_RESOLVER = address -> address ;
@@ -413,8 +424,15 @@ static Function<ClientConnectionType, String> defaultConnectionNamingStrategy(St
413
424
prefixes .get (clientConnectionType ) + sequences .get (clientConnectionType ).getAndIncrement ();
414
425
}
415
426
427
+ @ SuppressWarnings ("deprecation" )
416
428
static EventLoopGroup eventLoopGroup () {
417
- return new MultiThreadIoEventLoopGroup (NioIoHandler .newFactory ());
429
+ if (IS_NETTY_4_2 ) {
430
+ System .out .println ("NETTY 4.2" );
431
+ return new MultiThreadIoEventLoopGroup (NioIoHandler .newFactory ());
432
+ } else {
433
+ System .out .println ("NETTY 4.1" );
434
+ return new NioEventLoopGroup ();
435
+ }
418
436
}
419
437
420
438
static ByteBufAllocator byteBufAllocator () {
0 commit comments