主要阐述Cobar启动初始化工作:包括CobarServer对象的实例化和配置文件的读取
1.程序的入口- - -CobarStartup
在CobarStartup中包含以下main函数
public static void main(String[] args) {
try {
// init
CobarServer server = CobarServer.getInstance();
server.beforeStart(dateFormat);
// startup
server.startup();
} catch (Throwable e) {
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
LogLog.error(sdf.format(new Date()) + " startup error", e);
System.exit(-1);
}
}
从main函数可以获取到以下几点:
1.CobarServer是以单例模式运行的;
private static final CobarServer INSTANCE = new CobarServer();
private CobarServer() {
this.config = new CobarConfig();
SystemConfig system = config.getSystem();
MySQLLexer.setCStyleCommentVersion(system.getParserCommentVersion());
this.timer = new Timer(NAME + "Timer", true);
this.initExecutor = ExecutorUtil.create("InitExecutor", system.getInitExecutor());
this.timerExecutor = ExecutorUtil.create("TimerExecutor", system.getTimerExecutor());
this.managerExecutor = ExecutorUtil.create("ManagerExecutor", system.getManagerExecutor());
this.sqlRecorder = new SQLRecorder(system.getSqlRecordCount());
this.isOnline = new AtomicBoolean(true);
this.startupTime = TimeUtil.currentTimeMillis();
}
this.config = new CobarConfig() 完成配置文件加载
//- - - CobarConfig() - - -
ConfigInitializer confInit = new ConfigInitializer();
//- - - ConfigInitializer() - - -
SchemaLoader schemaLoader = new XMLSchemaLoader();
XMLConfigLoader configLoader = new XMLConfigLoader(schemaLoader);
//org.w3c.dom包完成xml文件解析
<