2018-12-26 15:40:53 +03:00
|
|
|
package ru.gravit.launchserver.manangers;
|
|
|
|
|
|
|
|
import ru.gravit.launchserver.Reconfigurable;
|
|
|
|
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 15:40:53 +03:00
|
|
|
public class ReconfigurableManager {
|
|
|
|
private final HashMap<String, Reconfigurable> RECONFIGURABLE = new HashMap<>();
|
2019-01-15 06:35:39 +03:00
|
|
|
|
|
|
|
public void registerReconfigurable(String name, Reconfigurable reconfigurable) {
|
2018-12-26 15:40:53 +03:00
|
|
|
VerifyHelper.putIfAbsent(RECONFIGURABLE, name, Objects.requireNonNull(reconfigurable, "adapter"),
|
|
|
|
String.format("Reloadable has been already registered: '%s'", name));
|
|
|
|
}
|
2019-01-15 06:35:39 +03:00
|
|
|
|
|
|
|
public void printHelp(String name) {
|
2018-12-26 15:40:53 +03:00
|
|
|
RECONFIGURABLE.get(name).printConfigHelp();
|
|
|
|
}
|
2019-01-15 06:35:39 +03:00
|
|
|
|
2019-01-15 06:32:46 +03:00
|
|
|
public void call(String name, String action, String[] args) {
|
2019-01-15 06:35:39 +03:00
|
|
|
RECONFIGURABLE.get(name).reconfig(action, args);
|
2018-12-26 15:40:53 +03:00
|
|
|
}
|
2019-01-15 06:35:39 +03:00
|
|
|
|
|
|
|
public void printReconfigurables() {
|
2018-12-26 15:40:53 +03:00
|
|
|
LogHelper.info("Print reconfigurables");
|
|
|
|
RECONFIGURABLE.forEach((k, v) -> LogHelper.subInfo(k));
|
|
|
|
LogHelper.info("Found %d reconfigurables", RECONFIGURABLE.size());
|
|
|
|
}
|
|
|
|
}
|