From e341f144b9c46799706ff5e0cd0c8ba395d708c2 Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 26 Dec 2018 18:54:24 +0700 Subject: [PATCH] =?UTF-8?q?ReloadManager=20=D0=B8=20ReloadCommand?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launchserver/LaunchServer.java | 3 ++ .../ru/gravit/launchserver/Reloadable.java | 5 +++ .../command/service/ReloadCommand.java | 26 ++++++++++++++++ .../launchserver/manangers/ReloadManager.java | 31 +++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/Reloadable.java create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadCommand.java create mode 100644 LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReloadManager.java diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 4d5b441f..823c1f01 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -261,6 +261,8 @@ public static void main(String... args) throws Throwable { public final MirrorManager mirrorManager; + public final ReloadManager reloadManager; + public final BuildHookManager buildHookManager; @@ -359,6 +361,7 @@ public LaunchServer(Path dir) throws IOException, InvalidKeySpecException { proguardConf = new ProguardConf(this); sessionManager = new SessionManager(); mirrorManager = new MirrorManager(); + reloadManager = new ReloadManager(); GarbageManager.registerNeedGC(sessionManager); GarbageManager.registerNeedGC(limiter); Arrays.stream(config.mirrors).forEach(s -> { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/Reloadable.java b/LaunchServer/src/main/java/ru/gravit/launchserver/Reloadable.java new file mode 100644 index 00000000..54492000 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/Reloadable.java @@ -0,0 +1,5 @@ +package ru.gravit.launchserver; +@FunctionalInterface +public interface Reloadable { + void reload() throws Exception; +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadCommand.java new file mode 100644 index 00000000..ea7bf5b5 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/service/ReloadCommand.java @@ -0,0 +1,26 @@ +package ru.gravit.launchserver.command.service; + +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.Command; + +public class ReloadCommand extends Command { + public ReloadCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[name]"; + } + + @Override + public String getUsageDescription() { + return "Reload provider/handler/module config"; + } + + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args,1); + + } +} diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReloadManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReloadManager.java new file mode 100644 index 00000000..4ede4ee9 --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReloadManager.java @@ -0,0 +1,31 @@ +package ru.gravit.launchserver.manangers; + +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 ReloadManager { + private final HashMap RELOADABLES = new HashMap<>(); + public void registerReloadable(String name,Reloadable reloadable) + { + VerifyHelper.verifyIDName(name); + VerifyHelper.putIfAbsent(RELOADABLES, name, Objects.requireNonNull(reloadable, "adapter"), + String.format("Reloadable has been already registered: '%s'", name)); + } + public void reloadAll() + { + RELOADABLES.forEach((k,v) -> { + try { + v.reload(); + } catch (Exception e) { + LogHelper.error(e); + } + }); + } + public void reload(String name) throws Exception { + RELOADABLES.get(name).reload(); + } +}