use of rpc.turbo.config.server.ServerConfig in project turbo-rpc by hank-whu.
the class TurboServerStarter method startTuroboServer.
@PostConstruct
public void startTuroboServer() {
ServerConfig serverConfig;
try {
serverConfig = ServerConfig.parse("turbo-server.conf");
} catch (com.typesafe.config.ConfigException configException) {
if (logger.isErrorEnabled()) {
logger.error("turbo-server.conf 格式错误,无法开启TurboServer!", configException);
}
return;
} catch (Throwable e) {
if (logger.isErrorEnabled()) {
logger.error("类路径中找不到 turbo-server.conf,无法开启TurboServer!", e);
}
return;
}
@SuppressWarnings("rawtypes") Collection<Tuple3<TurboService, Class, Object>> turboServiceList = getTurboServiceList();
if (turboServiceList.isEmpty()) {
if (logger.isErrorEnabled()) {
logger.error("找不到有效的 TurboService,无法开启TurboServer!");
}
return;
}
ServerInvokerFactory invokerFactory = new ServerInvokerFactory(serverConfig.getGroup(), serverConfig.getApp());
turboServiceList.forEach(t3 -> {
invokerFactory.register(t3._2, t3._3);
});
try {
turboServer = new TurboServer(serverConfig, invokerFactory);
turboServer.startAndRegisterServer();
//
Map<String, TurboServerAware> turboServerAwareMap = applicationContext.getBeansOfType(TurboServerAware.class);
turboServerAwareMap.forEach((key, value) -> value.setTurboServer(turboServer));
} catch (Throwable e) {
if (logger.isErrorEnabled()) {
logger.error("TurboServer启动失败!", e);
}
}
}
Aggregations