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

32 lines
963 B
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;
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();
}
}