Search in sources :

Example 1 with ServerInvokerFactory

use of rpc.turbo.invoke.ServerInvokerFactory 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);
        }
    }
}
Also used : TurboServer(rpc.turbo.server.TurboServer) ServerConfig(rpc.turbo.config.server.ServerConfig) Tuple3(rpc.turbo.util.tuple.Tuple3) ServerInvokerFactory(rpc.turbo.invoke.ServerInvokerFactory) PostConstruct(javax.annotation.PostConstruct)

Aggregations

PostConstruct (javax.annotation.PostConstruct)1 ServerConfig (rpc.turbo.config.server.ServerConfig)1 ServerInvokerFactory (rpc.turbo.invoke.ServerInvokerFactory)1 TurboServer (rpc.turbo.server.TurboServer)1 Tuple3 (rpc.turbo.util.tuple.Tuple3)1