mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-01-09 00:59:44 +03:00
Команда dumpEntryCache
This commit is contained in:
parent
19509d7ac5
commit
e915d408a9
3 changed files with 95 additions and 0 deletions
|
@ -104,8 +104,25 @@ public synchronized boolean joinServer(String username, String accessToken, Stri
|
|||
|
||||
public synchronized void garbageCollection() {
|
||||
entryCache.clear();
|
||||
usernamesCache.clear();
|
||||
}
|
||||
|
||||
public Map<UUID, Entry> getEntryCache() {
|
||||
return entryCache;
|
||||
}
|
||||
|
||||
public Map<String, UUID> getUsernamesCache() {
|
||||
return usernamesCache;
|
||||
}
|
||||
|
||||
public void loadEntryCache(Map<UUID, Entry> map)
|
||||
{
|
||||
entryCache.putAll(map);
|
||||
}
|
||||
public void loadUsernameCache(Map<String, UUID> map)
|
||||
{
|
||||
usernamesCache.putAll(map);
|
||||
}
|
||||
|
||||
protected abstract boolean updateAuth(UUID uuid, String username, String accessToken) throws IOException;
|
||||
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
package ru.gravit.launchserver.command.dump;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.auth.handler.CachedAuthHandler;
|
||||
import ru.gravit.launchserver.command.Command;
|
||||
import ru.gravit.launchserver.socket.Client;
|
||||
import ru.gravit.utils.helper.IOHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
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.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DumpEntryCacheCommand extends Command {
|
||||
public DumpEntryCacheCommand(LaunchServer server) {
|
||||
super(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getArgsDescription() {
|
||||
return "[load/unload] [filename]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsageDescription() {
|
||||
return "Load or unload AuthHandler Entry cache";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(String... args) throws Exception {
|
||||
verifyArgs(args,2);
|
||||
if(!(server.config.authHandler instanceof CachedAuthHandler)) throw new UnsupportedOperationException("This command used only CachedAuthHandler");
|
||||
CachedAuthHandler authHandler = (CachedAuthHandler) server.config.authHandler;
|
||||
if(args[0].equals("unload"))
|
||||
{
|
||||
LogHelper.info("CachedAuthHandler write to %s",args[1]);
|
||||
Map<UUID,CachedAuthHandler.Entry> entryCache = authHandler.getEntryCache();
|
||||
Map<String, UUID> usernamesCache = authHandler.getUsernamesCache();
|
||||
EntryAndUsername serializable = new EntryAndUsername();
|
||||
serializable.entryCache = entryCache;
|
||||
serializable.usernameCache = usernamesCache;
|
||||
try(Writer writer = IOHelper.newWriter(Paths.get(args[1])))
|
||||
{
|
||||
LaunchServer.gson.toJson(serializable,writer);
|
||||
}
|
||||
LogHelper.subInfo("Write %d entryCache, %d usernameCache",entryCache.size(),usernamesCache.size());
|
||||
} else if(args[0].equals("load"))
|
||||
{
|
||||
LogHelper.info("CachedAuthHandler read from %s",args[1]);
|
||||
int size_entry = 0;
|
||||
int size_username = 0;
|
||||
try(Reader reader = IOHelper.newReader(Paths.get(args[1])))
|
||||
{
|
||||
EntryAndUsername entryAndUsername = LaunchServer.gson.fromJson(reader,EntryAndUsername.class);
|
||||
size_entry = entryAndUsername.entryCache.size();
|
||||
size_username = entryAndUsername.usernameCache.size();
|
||||
authHandler.loadEntryCache(entryAndUsername.entryCache);
|
||||
authHandler.loadUsernameCache(entryAndUsername.usernameCache);
|
||||
|
||||
}
|
||||
LogHelper.subInfo("Readed %d entryCache %d usernameCache",size_entry,size_username);
|
||||
}
|
||||
}
|
||||
|
||||
public class EntryAndUsername
|
||||
{
|
||||
public Map<UUID,CachedAuthHandler.Entry> entryCache;
|
||||
public Map<String, UUID> usernameCache;
|
||||
}
|
||||
}
|
|
@ -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.DumpEntryCacheCommand;
|
||||
import ru.gravit.launchserver.command.dump.DumpSessionsCommand;
|
||||
import ru.gravit.launchserver.command.hash.*;
|
||||
import ru.gravit.launchserver.command.modules.LoadModuleCommand;
|
||||
|
@ -106,6 +107,7 @@ protected CommandHandler(LaunchServer server) {
|
|||
|
||||
//Register dump commands
|
||||
registerCommand("dumpSessions", new DumpSessionsCommand(server));
|
||||
registerCommand("dumpEntryCache", new DumpEntryCacheCommand(server));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue