From 73dfdd1494550198a9fe21565dcc882e60584273 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 26 Dec 2018 19:40:53 +0700 Subject: [PATCH] =?UTF-8?q?Reconfigurable=20=D0=B8=20=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=B4=D1=8B=20config/configHelp/configList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launchserver/LaunchServer.java | 4 +++ .../gravit/launchserver/Reconfigurable.java | 6 ++++ .../command/handler/CommandHandler.java | 7 ++-- .../command/service/ConfigCommand.java | 30 +++++++++++++++++ .../command/service/ConfigHelpCommand.java | 28 ++++++++++++++++ .../command/service/ConfigListCommand.java | 25 +++++++++++++++ .../command/service/ReloadInfoCommand.java | 2 -- .../manangers/ReconfigurableManager.java | 32 +++++++++++++++++++ 8 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/Reconfigurable.java create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigCommand.java create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigHelpCommand.java create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigListCommand.java create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index e8d7785c..d2d86ce7 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -263,6 +263,8 @@ public static void main(String... args) throws Throwable { public final ReloadManager reloadManager; + public final ReconfigurableManager reconfigurableManager; + public final BuildHookManager buildHookManager; @@ -367,6 +369,8 @@ public LaunchServer(Path dir) throws IOException, InvalidKeySpecException { sessionManager = new SessionManager(); mirrorManager = new MirrorManager(); reloadManager = new ReloadManager(); + reconfigurableManager = new ReconfigurableManager(); + GarbageManager.registerNeedGC(sessionManager); GarbageManager.registerNeedGC(limiter); if(config.permissionsHandler instanceof Reloadable) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/Reconfigurable.java b/LaunchServer/src/main/java/ru/gravit/launchserver/Reconfigurable.java new file mode 100644 index 00000000..0c83c2c8 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/Reconfigurable.java @@ -0,0 +1,6 @@ +package ru.gravit.launchserver; + +public interface Reconfigurable { + void reconfig(String action,String[] args); + void printConfigHelp(); +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java index 0425987a..bde57a62 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java @@ -10,9 +10,7 @@ import ru.gravit.launchserver.command.hash.*; import ru.gravit.launchserver.command.modules.LoadModuleCommand; import ru.gravit.launchserver.command.modules.ModulesCommand; -import ru.gravit.launchserver.command.service.ReloadAllCommand; -import ru.gravit.launchserver.command.service.ReloadCommand; -import ru.gravit.launchserver.command.service.ReloadInfoCommand; +import ru.gravit.launchserver.command.service.*; import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.VerifyHelper; @@ -116,6 +114,9 @@ protected CommandHandler(LaunchServer server) { registerCommand("reload",new ReloadCommand(server)); registerCommand("reloadAll",new ReloadAllCommand(server)); registerCommand("reloadInfo",new ReloadInfoCommand(server)); + registerCommand("config", new ConfigCommand(server)); + registerCommand("configHelp", new ConfigHelpCommand(server)); + registerCommand("configList", new ConfigListCommand(server)); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigCommand.java new file mode 100644 index 00000000..137e9895 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigCommand.java @@ -0,0 +1,30 @@ +package ru.gravit.launchserver.command.service; + +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.Command; +import ru.gravit.utils.helper.LogHelper; + +public class ConfigCommand extends Command { + public ConfigCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[name] [action] [more args]"; + } + + @Override + public String getUsageDescription() { + return "call reconfigurable action"; + } + + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args,2); + LogHelper.info("Call %s module % action",args[0],args[1]); + String[] new_args = new String[args.length - 2]; + System.arraycopy(args, 2, new_args, 0, args.length - 2); + server.reconfigurableManager.call(args[0],args[1],new_args); + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigHelpCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigHelpCommand.java new file mode 100644 index 00000000..1e2f3d8c --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigHelpCommand.java @@ -0,0 +1,28 @@ +package ru.gravit.launchserver.command.service; + +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.Command; +import ru.gravit.utils.helper.LogHelper; + +public class ConfigHelpCommand extends Command { + public ConfigHelpCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[name]"; + } + + @Override + public String getUsageDescription() { + return "print help for config command"; + } + + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args,1); + LogHelper.info("Help %s module",args[0]); + server.reconfigurableManager.printHelp(args[0]); + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigListCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigListCommand.java new file mode 100644 index 00000000..186d0e1e --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ConfigListCommand.java @@ -0,0 +1,25 @@ +package ru.gravit.launchserver.command.service; + +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.Command; + +public class ConfigListCommand extends Command { + public ConfigListCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[name]"; + } + + @Override + public String getUsageDescription() { + return "print help for config command"; + } + + @Override + public void invoke(String... args) throws Exception { + server.reconfigurableManager.printReconfigurables(); + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadInfoCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadInfoCommand.java index ebfa04a1..df6af499 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadInfoCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadInfoCommand.java @@ -21,8 +21,6 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { - verifyArgs(args,1); - LogHelper.info("Reload %s config",args[0]); server.reloadManager.printReloadables(); } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java new file mode 100644 index 00000000..45d32a1f --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReconfigurableManager.java @@ -0,0 +1,32 @@ +package ru.gravit.launchserver.manangers; + +import ru.gravit.launchserver.Reconfigurable; +import ru.gravit.launchserver.Reloadable; +import ru.gravit.utils.helper.LogHelper; +import ru.gravit.utils.helper.VerifyHelper; + +import java.util.HashMap; +import java.util.Objects; + +public class ReconfigurableManager { + private final HashMap RECONFIGURABLE = new HashMap<>(); + public void registerReconfigurable(String name, Reconfigurable reconfigurable) + { + VerifyHelper.verifyIDName(name); + VerifyHelper.putIfAbsent(RECONFIGURABLE, name, Objects.requireNonNull(reconfigurable, "adapter"), + String.format("Reloadable has been already registered: '%s'", name)); + } + public void printHelp(String name) + { + RECONFIGURABLE.get(name).printConfigHelp(); + } + public void call(String name, String action, String[] args) throws Exception { + RECONFIGURABLE.get(name).reconfig(action,args); + } + public void printReconfigurables() + { + LogHelper.info("Print reconfigurables"); + RECONFIGURABLE.forEach((k, v) -> LogHelper.subInfo(k)); + LogHelper.info("Found %d reconfigurables", RECONFIGURABLE.size()); + } +}