package ru.gravit.launchserver.manangers; import java.util.HashMap; import java.util.Objects; import ru.gravit.launchserver.Reloadable; import ru.gravit.utils.helper.LogHelper; import ru.gravit.utils.helper.VerifyHelper; public class ReloadManager { private final HashMap 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(); } public void printReloadables() { LogHelper.info("Print reloadables"); RELOADABLES.forEach((k,v) -> LogHelper.subInfo(k)); LogHelper.info("Found %d reloadables", RELOADABLES.size()); } }