From e8793807bf47e8438d586770d5f4316450da1fa7 Mon Sep 17 00:00:00 2001 From: kamcio96 Date: Mon, 14 Mar 2016 16:07:20 -0700 Subject: [PATCH] Use a worker and a boss event loop group. Merges the rest of https://github.com/SpigotMC/BungeeCord/pull/1706 by @kamcio96 along with b8845c4edbae46bb66f6adda338330a1d4032057 This is proper practice for netty. diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index c8d1d225..2d967df3 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -117,7 +117,7 @@ public class BungeeCord extends ProxyServer */ private ResourceBundle baseBundle; private ResourceBundle customBundle; - public EventLoopGroup eventLoops; + public EventLoopGroup bossEventLoopGroup, workerEventLoopGroup; /** * locations.yml save thread. */ @@ -254,7 +254,8 @@ public class BungeeCord extends ProxyServer ResourceLeakDetector.setLevel( ResourceLeakDetector.Level.DISABLED ); // Eats performance } - eventLoops = PipelineUtils.newEventLoopGroup( 0, new ThreadFactoryBuilder().setNameFormat( "Netty IO Thread #%1$d" ).build() ); + bossEventLoopGroup = PipelineUtils.newEventLoopGroup( 0, new ThreadFactoryBuilder().setNameFormat( "Netty Boss IO Thread #%1$d" ).build() ); + workerEventLoopGroup = PipelineUtils.newEventLoopGroup( 0, new ThreadFactoryBuilder().setNameFormat( "Netty Worker IO Thread #%1$d" ).build() ); File moduleDirectory = new File( "modules" ); moduleManager.load( this, moduleDirectory ); @@ -330,7 +331,7 @@ public class BungeeCord extends ProxyServer .childOption( ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 1024 * 1024 * 1 ) .childAttr( PipelineUtils.LISTENER, info ) .childHandler( PipelineUtils.SERVER_CHILD ) - .group( eventLoops ) + .group( bossEventLoopGroup, workerEventLoopGroup ) .localAddress( info.getHost() ) .bind().addListener( listener ); @@ -351,7 +352,7 @@ public class BungeeCord extends ProxyServer } } }; - new RemoteQuery( this, info ).start( PipelineUtils.getDatagramChannel(), new InetSocketAddress( info.getHost().getAddress(), info.getQueryPort() ), eventLoops, bindListener ); + new RemoteQuery( this, info ).start( PipelineUtils.getDatagramChannel(), new InetSocketAddress( info.getHost().getAddress(), info.getQueryPort() ), workerEventLoopGroup, bindListener ); } } } @@ -446,12 +447,14 @@ public class BungeeCord extends ProxyServer } getLogger().info( "Closing IO threads" ); - eventLoops.shutdownGracefully(); - try - { - eventLoops.awaitTermination( Long.MAX_VALUE, TimeUnit.NANOSECONDS ); - } catch ( InterruptedException ex ) - { + bossEventLoopGroup.shutdownGracefully(); + workerEventLoopGroup.shutdownGracefully(); + while (true) { + try { + bossEventLoopGroup.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); + workerEventLoopGroup.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); + break; + } catch (InterruptedException ignored) {} } getLogger().info( "Thank you and goodbye" ); diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java index 9756c09c..648cd273 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java @@ -145,7 +145,7 @@ public class BungeeServerInfo implements ServerInfo }; new Bootstrap() .channel( PipelineUtils.getChannel() ) - .group( BungeeCord.getInstance().eventLoops ) + .group( BungeeCord.getInstance().workerEventLoopGroup ) .handler( PipelineUtils.BASE ) .option( ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000 ) // TODO: Configurable .remoteAddress( getAddress() ) -- 2.18.0