mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 09:01:08 +03:00
ReloadManager и ReloadCommand
This commit is contained in:
parent
05bad22ede
commit
e341f144b9
4 changed files with 65 additions and 0 deletions
|
@ -261,6 +261,8 @@ public static void main(String... args) throws Throwable {
|
||||||
|
|
||||||
public final MirrorManager mirrorManager;
|
public final MirrorManager mirrorManager;
|
||||||
|
|
||||||
|
public final ReloadManager reloadManager;
|
||||||
|
|
||||||
|
|
||||||
public final BuildHookManager buildHookManager;
|
public final BuildHookManager buildHookManager;
|
||||||
|
|
||||||
|
@ -359,6 +361,7 @@ public LaunchServer(Path dir) throws IOException, InvalidKeySpecException {
|
||||||
proguardConf = new ProguardConf(this);
|
proguardConf = new ProguardConf(this);
|
||||||
sessionManager = new SessionManager();
|
sessionManager = new SessionManager();
|
||||||
mirrorManager = new MirrorManager();
|
mirrorManager = new MirrorManager();
|
||||||
|
reloadManager = new ReloadManager();
|
||||||
GarbageManager.registerNeedGC(sessionManager);
|
GarbageManager.registerNeedGC(sessionManager);
|
||||||
GarbageManager.registerNeedGC(limiter);
|
GarbageManager.registerNeedGC(limiter);
|
||||||
Arrays.stream(config.mirrors).forEach(s -> {
|
Arrays.stream(config.mirrors).forEach(s -> {
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package ru.gravit.launchserver;
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface Reloadable {
|
||||||
|
void reload() throws Exception;
|
||||||
|
}
|
|
@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<String,Reloadable> 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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue