2018-12-26 14:54:24 +03:00
|
|
|
package ru.gravit.launchserver.manangers;
|
|
|
|
|
2018-12-26 15:33:49 +03:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Objects;
|
|
|
|
|
2018-12-26 14:54:24 +03:00
|
|
|
import ru.gravit.launchserver.Reloadable;
|
|
|
|
import ru.gravit.utils.helper.LogHelper;
|
|
|
|
import ru.gravit.utils.helper.VerifyHelper;
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2018-12-26 15:10:56 +03:00
|
|
|
public void printReloadables()
|
|
|
|
{
|
|
|
|
LogHelper.info("Print reloadables");
|
|
|
|
RELOADABLES.forEach((k,v) -> LogHelper.subInfo(k));
|
|
|
|
LogHelper.info("Found %d reloadables", RELOADABLES.size());
|
|
|
|
}
|
2018-12-26 14:54:24 +03:00
|
|
|
}
|