Возможность перезапускать лаунчсервер без потери сессий на клиентах

This commit is contained in:
Gravit 2018-12-24 16:23:00 +07:00
parent d94e8f22e1
commit 232aeb5c68
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
5 changed files with 68 additions and 4 deletions

View file

@ -20,7 +20,7 @@ public final class MySQLSourceConfig implements AutoCloseable {
VerifyHelper.POSITIVE, "launcher.mysql.maxPoolSize can't be <= 0");
// Instance
private final String poolName;
private transient final String poolName;
// Config
private String address;
@ -33,8 +33,8 @@ public final class MySQLSourceConfig implements AutoCloseable {
private String timeZone;
// Cache
private DataSource source;
private boolean hikari;
private transient DataSource source;
private transient boolean hikari;
public MySQLSourceConfig(String poolName) {

View file

@ -0,0 +1,51 @@
package ru.gravit.launchserver.command.dump;
import com.google.gson.reflect.TypeToken;
import javafx.scene.media.MediaException;
import ru.gravit.launcher.Launcher;
import ru.gravit.launchserver.LaunchServer;
import ru.gravit.launchserver.command.Command;
import ru.gravit.launchserver.socket.Client;
import ru.gravit.utils.helper.IOHelper;
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.Type;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.Set;
public class DumpSessionsCommand extends Command {
public DumpSessionsCommand(LaunchServer server) {
super(server);
}
@Override
public String getArgsDescription() {
return "[load/unload] [filename]";
}
@Override
public String getUsageDescription() {
return "Load or unload sessions";
}
@Override
public void invoke(String... args) throws Exception {
verifyArgs(args,2);
if(args[0].equals("unload"))
{
try(Writer writer = IOHelper.newWriter(Paths.get(args[1])))
{
Launcher.gson.toJson(server.sessionManager.getSessions(),writer);
}
} else if(args[0].equals("load"))
{
try(Reader reader = IOHelper.newReader(Paths.get(args[1])))
{
Type setType = new TypeToken<HashSet<Client>>(){}.getType();
server.sessionManager.loadSessions(Launcher.gson.fromJson(reader,setType));
}
}
}
}

View file

@ -5,6 +5,7 @@
import ru.gravit.launchserver.command.CommandException;
import ru.gravit.launchserver.command.auth.*;
import ru.gravit.launchserver.command.basic.*;
import ru.gravit.launchserver.command.dump.DumpSessionsCommand;
import ru.gravit.launchserver.command.hash.*;
import ru.gravit.launchserver.command.modules.LoadModuleCommand;
import ru.gravit.launchserver.command.modules.ModulesCommand;
@ -102,6 +103,9 @@ protected CommandHandler(LaunchServer server) {
registerCommand("uuidToUsername", new UUIDToUsernameCommand(server));
registerCommand("ban", new BanCommand(server));
registerCommand("unban", new UnbanCommand(server));
//Register dump commands
registerCommand("dumpSessions", new DumpSessionsCommand(server));
}

View file

@ -10,7 +10,7 @@ public class SessionManager implements NeedGarbageCollection {
public static final long SESSION_TIMEOUT = 10 * 60 * 1000; // 10 минут
public static final boolean NON_GARBAGE_SERVER = true;
private Set<Client> clientSet = new HashSet<>(128);
private HashSet<Client> clientSet = new HashSet<>(128);
public boolean addClient(Client client) {
@ -52,4 +52,12 @@ public void updateClient(long session) {
Client newClient = new Client(session);
clientSet.add(newClient);
}
public Set<Client> getSessions()
{
return clientSet;
}
public void loadSessions(Set<Client> set)
{
clientSet.addAll(set);
}
}

View file

@ -132,6 +132,7 @@ public static void main(String... args) throws Throwable {
LogHelper.printLicense("Launcher");
// Start Launcher
initGson();
LogHelper.setStacktraceEnabled(true);
Instant start = Instant.now();
try {
new LauncherEngine().start(args);