Bladeren bron

update netty to version 4.1.13.Final and make use of the newly added Kqueue support (#2911)

Luis Neves 8 jaren geleden
bovenliggende
commit
3118a187d3

+ 9 - 2
frameworks/Java/netty/pom.xml

@@ -14,16 +14,23 @@
 		<dependency>
 		<dependency>
 			<groupId>io.netty</groupId>
 			<groupId>io.netty</groupId>
 			<artifactId>netty-codec-http</artifactId>
 			<artifactId>netty-codec-http</artifactId>
-			<version>4.1.11.Final </version>
+			<version>4.1.13.Final </version>
 		</dependency>
 		</dependency>
 
 
 		<dependency>
 		<dependency>
 			<groupId>io.netty</groupId>
 			<groupId>io.netty</groupId>
 			<artifactId>netty-transport-native-epoll</artifactId>
 			<artifactId>netty-transport-native-epoll</artifactId>
-			<version>4.1.11.Final </version>
+			<version>4.1.13.Final </version>
 			<classifier>linux-x86_64</classifier>
 			<classifier>linux-x86_64</classifier>
 		</dependency>
 		</dependency>
 
 
+		<dependency>
+			<groupId>io.netty</groupId>
+			<artifactId>netty-transport-native-kqueue</artifactId>
+			<version>4.1.13.Final </version>
+			<classifier>osx-x86_64</classifier>
+		</dependency>
+
 		<dependency>
 		<dependency>
 			<groupId>com.fasterxml.jackson.module</groupId>
 			<groupId>com.fasterxml.jackson.module</groupId>
 			<artifactId>jackson-module-afterburner</artifactId>
 			<artifactId>jackson-module-afterburner</artifactId>

+ 9 - 5
frameworks/Java/netty/src/main/java/hello/HelloWebServer.java

@@ -11,6 +11,8 @@ import io.netty.channel.epoll.Epoll;
 import io.netty.channel.epoll.EpollChannelOption;
 import io.netty.channel.epoll.EpollChannelOption;
 import io.netty.channel.epoll.EpollEventLoopGroup;
 import io.netty.channel.epoll.EpollEventLoopGroup;
 import io.netty.channel.epoll.EpollServerSocketChannel;
 import io.netty.channel.epoll.EpollServerSocketChannel;
+import io.netty.channel.kqueue.KQueue;
+import io.netty.channel.kqueue.KQueueServerSocketChannel;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.nio.NioServerSocketChannel;
 import io.netty.channel.socket.nio.NioServerSocketChannel;
 import io.netty.util.ResourceLeakDetector;
 import io.netty.util.ResourceLeakDetector;
@@ -32,22 +34,24 @@ public class HelloWebServer {
 		// Configure the server.
 		// Configure the server.
 
 
 		if (Epoll.isAvailable()) {
 		if (Epoll.isAvailable()) {
-			doRun(new EpollEventLoopGroup(), EpollServerSocketChannel.class, true);
+			doRun(new EpollEventLoopGroup(), EpollServerSocketChannel.class, IoMultiplexer.EPOLL);
+		} else if (KQueue.isAvailable()) {
+			doRun(new EpollEventLoopGroup(), KQueueServerSocketChannel.class, IoMultiplexer.KQUEUE);
 		} else {
 		} else {
-			doRun(new NioEventLoopGroup(), NioServerSocketChannel.class, false);
+			doRun(new NioEventLoopGroup(), NioServerSocketChannel.class, IoMultiplexer.JDK);
 		}
 		}
 	}
 	}
 
 
-	private void doRun(EventLoopGroup loupGroup, Class<? extends ServerChannel> serverChannelClass, boolean isNative) throws InterruptedException {
+	private void doRun(EventLoopGroup loupGroup, Class<? extends ServerChannel> serverChannelClass, IoMultiplexer multiplexer) throws InterruptedException {
 		try {
 		try {
 			InetSocketAddress inet = new InetSocketAddress(port);
 			InetSocketAddress inet = new InetSocketAddress(port);
 
 
 			ServerBootstrap b = new ServerBootstrap();
 			ServerBootstrap b = new ServerBootstrap();
 
 
-			if (isNative) {
+			if (multiplexer == IoMultiplexer.EPOLL) {
 				b.option(EpollChannelOption.SO_REUSEPORT, true);
 				b.option(EpollChannelOption.SO_REUSEPORT, true);
 			}
 			}
-
+			
 			b.option(ChannelOption.SO_BACKLOG, 8192);
 			b.option(ChannelOption.SO_BACKLOG, 8192);
 			b.option(ChannelOption.SO_REUSEADDR, true);
 			b.option(ChannelOption.SO_REUSEADDR, true);
 			b.group(loupGroup).channel(serverChannelClass).childHandler(new HelloServerInitializer(loupGroup.next()));
 			b.group(loupGroup).channel(serverChannelClass).childHandler(new HelloServerInitializer(loupGroup.next()));

+ 5 - 0
frameworks/Java/netty/src/main/java/hello/IoMultiplexer.java

@@ -0,0 +1,5 @@
+package hello;
+
+public enum IoMultiplexer {
+	EPOLL, KQUEUE, JDK
+}