mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
Возможность перезапускать лаунчсервер без потери сессий на клиентах
This commit is contained in:
parent
d94e8f22e1
commit
232aeb5c68
5 changed files with 68 additions and 4 deletions
|
@ -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) {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue