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<UUID, Entry> clientSet = new ConcurrentHashMap<>(128); private transient final Map<UUID, Set<Entry>> 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<UUID, Entry> clientSet; - private transient final Map<UUID, Set<Entry>> uuidIndex; + private final Map<UUID, Entry> clientSet; + private final Map<UUID, Set<Entry>> uuidIndex; private DumpedData(Map<UUID, Entry> clientSet, Map<UUID, Set<Entry>> 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(); } }