From 3cd9ddee0d1075ed1079f66d62349c92dcef6327 Mon Sep 17 00:00:00 2001 From: Gravita Date: Fri, 12 Feb 2021 21:19:49 +0700 Subject: [PATCH] =?UTF-8?q?[FIX]=20autoDump=20=D0=B8=20=D0=B7=D0=B0=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D1=88=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pro/gravit/launchserver/LaunchServer.java | 13 ++++++++++--- .../auth/session/MemorySessionStorage.java | 18 +++++++++++------- .../config/LaunchServerConfig.java | 7 +++++++ .../socket/LauncherNettyServer.java | 7 +++++-- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index b74d8de7..202459d6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -319,7 +319,8 @@ public void buildLauncherBinaries() throws IOException { } public void close() throws Exception { - + LogHelper.info("Close server socket"); + nettyServerSocketHandler.close(); // Close handlers & providers config.close(ReloadType.FULL); modulesManager.invokeEvent(new ClosePhase()); @@ -368,8 +369,14 @@ public void run() { } if (config.netty != null) rebindNettyServerSocket(); - modulesManager.fullInitializedLaunchServer(this); - modulesManager.invokeEvent(new LaunchServerFullInitEvent(this)); + try { + modulesManager.fullInitializedLaunchServer(this); + modulesManager.invokeEvent(new LaunchServerFullInitEvent(this)); + LogHelper.info("LaunchServer started"); + } catch (Throwable e) { + LogHelper.error(e); + JVMHelper.RUNTIME.exit(-1); + } } public void syncLauncherBinaries() throws IOException { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/session/MemorySessionStorage.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/session/MemorySessionStorage.java index 620b0faa..0dc45db7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/session/MemorySessionStorage.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/session/MemorySessionStorage.java @@ -17,7 +17,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Stream; -public class MemorySessionStorage extends SessionStorage implements NeedGarbageCollection { +public class MemorySessionStorage extends SessionStorage implements NeedGarbageCollection, AutoCloseable { private transient final Map clientSet = new ConcurrentHashMap<>(128); private transient final Map> uuidIndex = new ConcurrentHashMap<>(32); @@ -90,10 +90,6 @@ public boolean deleteSessionsByUserUUID(UUID userUUID) { public void clear() { clientSet.clear(); uuidIndex.clear(); - if(autoDump) { - garbageCollection(); - dumpSessionsData(); - } } public void dumpSessionsData() { @@ -161,6 +157,14 @@ public void garbageCollection() { to_delete.clear(); } + @Override + public void close() throws Exception { + if(autoDump) { + garbageCollection(); + dumpSessionsData(); + } + } + private static class Entry { public byte[] data; public UUID sessionUuid; @@ -174,8 +178,8 @@ public Entry(byte[] data, UUID sessionUuid) { } private static class DumpedData { - private transient final Map clientSet; - private transient final Map> uuidIndex; + private final Map clientSet; + private final Map> uuidIndex; private DumpedData(Map clientSet, Map> uuidIndex) { this.clientSet = clientSet; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index 671a4ba9..107153c5 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -235,6 +235,13 @@ public void close(LaunchServer.ReloadType type) { } if(sessions != null) { server.unregisterObject("sessions", sessions); + if (sessions instanceof AutoCloseable) { + try { + ((AutoCloseable) sessions).close(); + } catch (Exception e) { + LogHelper.error(e); + } + } } if (dao != null) { server.unregisterObject("dao", dao); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java index 6042d2d2..a68169df 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/LauncherNettyServer.java @@ -24,6 +24,7 @@ import pro.gravit.utils.helper.LogHelper; import java.net.InetSocketAddress; +import java.util.concurrent.TimeUnit; public class LauncherNettyServer implements AutoCloseable { private static final String WEBSOCKET_PATH = "/api"; @@ -77,7 +78,9 @@ public ChannelFuture bind(InetSocketAddress address) { @Override public void close() { - workerGroup.shutdownGracefully(); - bossGroup.shutdownGracefully(); + workerGroup.shutdownGracefully(2, 5, TimeUnit.SECONDS); + bossGroup.shutdownGracefully(2, 5, TimeUnit.SECONDS); + //workerGroup.shutdownGracefully(); + //bossGroup.shutdownGracefully(); } }