Search in sources :

Example 1 with TurboServer

use of rpc.turbo.server.TurboServer in project turbo-rpc by hank-whu.

the class RpcServerBenchmark method main.

public static void main(String[] args) throws Exception {
    ResourceLeakDetector.setLevel(Level.DISABLED);
    try (TurboServer server = new TurboServer("shop", "auth")) {
        Map<Class<?>, Object> services = Map.of(UserService.class, new UserServiceServerImpl());
        server.registerService(services);
        /*
			 * server.addFirst(new RpcServerFilter() {
			 * 
			 * @Override public void onSend(Request request, Response response) { try {
			 * Tracer tracer = request.getTracer();
			 * 
			 * if (tracer != null) { response.setTracer(tracer); }
			 * 
			 * } catch (Exception e) { e.printStackTrace(); } }
			 * 
			 * @Override public boolean onRecive(Request request) { try { Tracer tracer =
			 * request.getTracer();
			 * 
			 * if (tracer != null) { RemoteContext.getClientAddress().toString();
			 * RemoteContext.getServerAddress().toString();
			 * RemoteContext.getServiceMethodName();
			 * 
			 * TracerContext.setTracer(tracer); } } catch (Exception e) {
			 * e.printStackTrace(); }
			 * 
			 * return true; }
			 * 
			 * @Override public void onError(Request request, Response response, Throwable
			 * throwable) { } });
			 */
        server.startRpcServer(new HostPort("127.0.0.1", 8080));
        server.waitUntilShutdown();
    }
}
Also used : TurboServer(rpc.turbo.server.TurboServer) UserServiceServerImpl(rpc.turbo.benchmark.service.UserServiceServerImpl) HostPort(rpc.turbo.config.HostPort)

Example 2 with TurboServer

use of rpc.turbo.server.TurboServer 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)

Example 3 with TurboServer

use of rpc.turbo.server.TurboServer in project turbo-rpc by hank-whu.

the class RestServerBenchmark method main.

public static void main(String[] args) throws Exception {
    ResourceLeakDetector.setLevel(Level.DISABLED);
    try (TurboServer server = new TurboServer("shop", "auth")) {
        Map<Class<?>, Object> services = Map.of(UserService.class, new UserServiceServerImpl());
        server.registerService(services);
        server.startRestServer(new HostPort("0.0.0.0", 8080));
        server.waitUntilShutdown();
    }
}
Also used : TurboServer(rpc.turbo.server.TurboServer) UserServiceServerImpl(rpc.turbo.benchmark.service.UserServiceServerImpl) HostPort(rpc.turbo.config.HostPort)

Aggregations

TurboServer (rpc.turbo.server.TurboServer)3 UserServiceServerImpl (rpc.turbo.benchmark.service.UserServiceServerImpl)2 HostPort (rpc.turbo.config.HostPort)2 PostConstruct (javax.annotation.PostConstruct)1 ServerConfig (rpc.turbo.config.server.ServerConfig)1 ServerInvokerFactory (rpc.turbo.invoke.ServerInvokerFactory)1 Tuple3 (rpc.turbo.util.tuple.Tuple3)1