[FIX] autoDump и завершение работы

This commit is contained in:
Gravita 2021-02-12 21:19:49 +07:00
parent 9084361a38
commit 3cd9ddee0d
4 changed files with 33 additions and 12 deletions

View file

@ -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();
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 {

View file

@ -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;

View file

@ -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);

View file

@ -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();
}
}