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

42 lines
1.3 KiB
Java
Raw Normal View History

package pro.gravit.launchserver.manangers;
2018-12-26 14:54:24 +03:00
import pro.gravit.launchserver.Reloadable;
import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.helper.VerifyHelper;
2018-12-26 14:54:24 +03:00
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) {
VerifyHelper.putIfAbsent(RELOADABLES, name.toLowerCase(), Objects.requireNonNull(reloadable, "adapter"),
String.format("Reloadable has been already registered: '%s'", name.toLowerCase()));
2018-12-26 14:54:24 +03:00
}
2019-05-15 14:11:22 +03:00
public Reloadable unregisterReloadable(String name) {
return RELOADABLES.remove(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.toLowerCase()).reload();
2018-12-26 14:54:24 +03:00
}
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
}