Launcher/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ReloadManager.java

38 lines
1.1 KiB
Java
Raw Normal View History

2018-12-26 14:54:24 +03:00
package ru.gravit.launchserver.manangers;
import ru.gravit.launchserver.Reloadable;
import ru.gravit.utils.helper.LogHelper;
import ru.gravit.utils.helper.VerifyHelper;
2019-01-15 06:35:39 +03:00
import java.util.HashMap;
import java.util.Objects;
2018-12-26 14:54:24 +03:00
public class ReloadManager {
2019-01-15 06:35:39 +03:00
private final HashMap<String, Reloadable> RELOADABLES = new HashMap<>();
public void registerReloadable(String name, Reloadable reloadable) {
2018-12-26 14:54:24 +03:00
VerifyHelper.putIfAbsent(RELOADABLES, name, Objects.requireNonNull(reloadable, "adapter"),
String.format("Reloadable has been already registered: '%s'", name));
}
2019-01-15 06:35:39 +03:00
public void reloadAll() {
RELOADABLES.forEach((k, v) -> {
2018-12-26 14:54:24 +03:00
try {
v.reload();
} catch (Exception e) {
LogHelper.error(e);
}
});
}
2019-01-15 06:35:39 +03:00
2018-12-26 14:54:24 +03:00
public void reload(String name) throws Exception {
RELOADABLES.get(name).reload();
}
2019-01-15 06:35:39 +03:00
public void printReloadables() {
2018-12-26 15:10:56 +03:00
LogHelper.info("Print reloadables");
2019-01-15 06:35:39 +03:00
RELOADABLES.forEach((k, v) -> LogHelper.subInfo(k));
2018-12-26 15:10:56 +03:00
LogHelper.info("Found %d reloadables", RELOADABLES.size());
}
2018-12-26 14:54:24 +03:00
}