ReloadManager и ReloadCommand

This commit is contained in:
Gravit 2018-12-26 18:54:24 +07:00
parent 05bad22ede
commit e341f144b9
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
4 changed files with 65 additions and 0 deletions

View file

@ -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 -> {

View file

@ -0,0 +1,5 @@
package ru.gravit.launchserver;
@FunctionalInterface
public interface Reloadable {
void reload() throws Exception;
}

View file

@ -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);
}
}

View file

@ -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();
}
}