Loader加载limax配置
进程启动入口
static private final Loader instance = new Loader(); //service-endpoint.xml public static void load(String filename) throws Exception { instance.load(filename); }
2.统一解析xml节点,分为priorload和normaload两大类
//所有节点xml配置的根为:ServiceConf
private void loadByElement(Element self) throws Exception {
if (false == self.getNodeName().equals("ServiceConf"))
throw new IllegalArgumentException(self.getNodeName() + " is not a ServiceConf.");
loadPropertiesElements(self);
priorLoadElements(self);
normalLoadElements(self);
}
3.针对每一个节点单独解析
private final ConfigParserCreator propertiesParserCreator;
private final Map<String, ConfigParserCreator> priorcreatormap = new HashMap<String, ConfigParserCreator>();
private final Map<String, ConfigParserCreator> normalcreatormap = new HashMap<String, ConfigParserCreator>();
public Loader() {
propertiesParserCreator = self0 -> self -> {
String filename = self.getAttribute("file");
Properties properties = new Properties();
properties.load(new InputStreamReader(new FileInputStream(filename), StandardCharsets.UTF_8));
ElementHelper.setProperties(properties);
};
priorcreatormap.put("Properties", _self -> self -> {
});
priorcreatormap.put("Trace", self0 -> self -> {
final Trace.Config config = new Trace.Config();
final ElementHelper eh = new ElementHelper(self);
config.setOutDir(eh.getString("outDir", "./trace"));
config.setConsole(eh.getBoolean("console", true));
config.setRotateHourOfDay(eh.getInt("rotateHourOfDay", 6));
config.setRotateMinute(eh.getInt("rotateMinute", 0));
config.setRotatePeriod(eh.getLong("rotatePeriod", 86400000l));
config.setLevel(eh.getString("level", "warn").toUpperCase());
Trace.openNew(config);
JMXRegister(config, "limax.xmlconfig:type=Service,name=Trace");
});
priorcreatormap.put("Limit", self0 -> self -> {
final ElementHelper eh = new ElementHelper(self);
Limit.put(eh.getString("name"), eh.getLong("maxSize", Long.MAX_VALUE));
});
normalcreatormap.put("Manager", new XmlConfigs.ManagerConfigParserCreator());
normalcreatormap.put("GlobalId", new XmlConfigs.GlobalIdConfigParserCreator());
normalcreatormap.put("ThreadPoolSize", self -> threadpoolsize);
normalcreatormap.put("JmxServer", self -> new XmlConfigs.JMXServer());
normalcreatormap.put("NodeService", self -> new XmlConfigs.NodeService());
normalcreatormap.put("Provider", new limax.provider.XmlConfig.ProviderDataCreator());
normalcreatormap.put("Zdb", self -> new limax.provider.XmlConfig.StartZdb());
normalcreatormap.put("Switcher", self -> new limax.switcher.Config.SwitcherConfig());
}
4 增加启动后处理任务
//服务器和客户端节点
if (type.equalsIgnoreCase("client")) {
ClientManagerConfigBuilder builder = new ClientManagerConfigXmlBuilder()
.defaultState(getDefaultState(self, listener));
Service.addRunAfterEngineStartTask(() -> launchManagerTask(
builder.dispatcher(new Dispatcher(Engine.getProtocolExecutor())), listener, name));
return (ConfigParser) builder;
}
if (type.equalsIgnoreCase("server")) {
ServerManagerConfigBuilder builder = new ServerManagerConfigXmlBuilder()
.defaultState(getDefaultState(self, listener));
Service.addRunAfterEngineStartTask(() -> launchManagerTask(
builder.dispatcher(new Dispatcher(Engine.getProtocolExecutor())), listener, name));
return (ConfigParser) builder;
}
5 总结
(1)Service统一处理xml配置,解析节点在normalcreatormap中执行。
(2)节点解析之后会把网络连接,服务器启动等task交给addRunAfterEngineStartTask执行。
(3)下一个过程是开启网络模块。