use of com.jd.blockchain.peer.web.LedgerLoadTimer in project jdchain-core by blockchain-jd-com.
the class PeerServerBooter method startServer.
/**
* 启动服务;
*
* @param ledgerBindingConfig 账本绑定配置;
* @param hostAddress 服务地址;如果为空,则采用默认配置;
* @param port 端口地址;如果小于等于 0 ,则采用默认配置;
* @return
*/
private static ConfigurableApplicationContext startServer(LedgerBindingConfig ledgerBindingConfig, String hostAddress, int port, String springConfigLocation, Object... externalBeans) {
List<String> argList = new ArrayList<String>();
String logConfig = System.getProperty(LOG_CONFIG_FILE);
if (!StringUtils.isEmpty(logConfig)) {
argList.add(String.format("--logging.config=%s", logConfig));
}
String argServerAddress = String.format("--server.address=%s", "0.0.0.0");
argList.add(argServerAddress);
if (port > 0) {
String argServerPort = String.format("--server.port=%s", port);
argList.add(argServerPort);
} else {
port = 8080;
}
if (springConfigLocation != null) {
argList.add(String.format("--spring.config.location=%s", springConfigLocation));
}
String[] args = argList.toArray(new String[argList.size()]);
SpringApplication app = new SpringApplication(PeerConfiguration.class);
if (externalBeans != null && externalBeans.length > 0) {
app.addInitializers((ApplicationContextInitializer<ConfigurableApplicationContext>) applicationContext -> {
ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory();
for (Object bean : externalBeans) {
if (bean != null) {
beanFactory.registerSingleton(bean.toString(), bean);
}
}
});
}
// 启动 web 服务;
ConfigurableApplicationContext ctx = app.run(args);
RuntimeConstant.setMonitorProperties(port, Boolean.valueOf(ctx.getEnvironment().getProperty("server.ssl.enabled")));
// 配置文件为空,则说明目前没有账本,不需要配置账本相关信息
if (ledgerBindingConfig != null) {
// 建立共识网络;
Map<String, LedgerBindingConfigAware> bindingConfigAwares = ctx.getBeansOfType(LedgerBindingConfigAware.class);
for (LedgerBindingConfigAware aware : bindingConfigAwares.values()) {
aware.setConfig(ledgerBindingConfig);
}
ConsensusManage consensusManage = ctx.getBean(ConsensusManage.class);
consensusManage.runAllRealms();
}
// 释放定时任务许可
LedgerLoadTimer loadTimerBean = ctx.getBean(LedgerLoadTimer.class);
loadTimerBean.release();
return ctx;
}
Aggregations