2023-03-25 19:36:07 +01:00
From 40bdf52eae5d4d492216601188a4c54dbb00cc1c Mon Sep 17 00:00:00 2001
2016-05-28 18:34:39 +02:00
From: kamcio96 <k.nadworski@icloud.com>
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
2023-03-25 19:36:07 +01:00
index c036b613..f7794f66 100644
2016-05-28 18:34:39 +02:00
--- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
+++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
2022-11-14 20:14:25 +01:00
@@ -120,7 +120,7 @@ public class BungeeCord extends ProxyServer
* Localization formats.
2016-05-28 18:34:39 +02:00
*/
2022-11-14 20:14:25 +01:00
private Map<String, Format> messageFormats;
2016-05-28 18:34:39 +02:00
- public EventLoopGroup eventLoops;
+ public EventLoopGroup bossEventLoopGroup, workerEventLoopGroup;
/**
* locations.yml save thread.
*/
2022-11-14 20:14:25 +01:00
@@ -270,7 +270,8 @@ public class BungeeCord extends ProxyServer
2016-05-28 18:34:39 +02:00
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 );
2022-11-14 20:14:25 +01:00
@@ -359,7 +360,7 @@ public class BungeeCord extends ProxyServer
2018-09-16 18:06:25 +02:00
.option( ChannelOption.SO_REUSEADDR, true ) // TODO: Move this elsewhere!
2016-05-28 18:34:39 +02:00
.childAttr( PipelineUtils.LISTENER, info )
.childHandler( PipelineUtils.SERVER_CHILD )
- .group( eventLoops )
+ .group( bossEventLoopGroup, workerEventLoopGroup )
2020-01-21 18:36:22 +01:00
.localAddress( info.getSocketAddress() )
2016-05-28 18:34:39 +02:00
.bind().addListener( listener );
2022-11-14 20:14:25 +01:00
@@ -382,7 +383,7 @@ public class BungeeCord extends ProxyServer
2016-05-28 18:34:39 +02:00
}
}
};
- 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 );
}
}
}
2022-11-14 20:14:25 +01:00
@@ -491,12 +492,14 @@ public class BungeeCord extends ProxyServer
2020-03-11 16:38:30 +01:00
}
2016-05-28 18:34:39 +02:00
2020-03-11 16:38:30 +01:00
getLogger().info( "Closing IO threads" );
- eventLoops.shutdownGracefully();
- try
- {
- eventLoops.awaitTermination( Long.MAX_VALUE, TimeUnit.NANOSECONDS );
- } catch ( InterruptedException ex )
- {
2016-05-28 18:34:39 +02:00
+ 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) {}
2020-03-11 16:38:30 +01:00
}
2016-05-28 18:34:39 +02:00
2020-03-11 16:38:30 +01:00
getLogger().info( "Thank you and goodbye" );
2016-05-28 18:34:39 +02:00
diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java
2023-03-25 19:36:07 +01:00
index 51b2a324..634dfca7 100644
2016-05-28 18:34:39 +02:00
--- a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java
+++ b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java
2020-01-24 23:41:39 +01:00
@@ -184,7 +184,7 @@ public class BungeeServerInfo implements ServerInfo
2016-05-28 18:34:39 +02:00
};
new Bootstrap()
2020-01-21 18:36:22 +01:00
.channel( PipelineUtils.getChannel( socketAddress ) )
2016-05-28 18:34:39 +02:00
- .group( BungeeCord.getInstance().eventLoops )
+ .group( BungeeCord.getInstance().workerEventLoopGroup )
2023-03-25 19:36:07 +01:00
.handler( PipelineUtils.BASE_SERVERSIDE )
2020-02-01 16:39:53 +01:00
.option( ChannelOption.CONNECT_TIMEOUT_MILLIS, BungeeCord.getInstance().getConfig().getRemotePingTimeout() )
2020-01-21 18:36:22 +01:00
.remoteAddress( socketAddress )
2016-05-28 18:34:39 +02:00
--
2023-03-25 19:36:07 +01:00
2.40.0
2016-05-28 18:34:39 +02:00