Search in sources :

Example 1 with Http2WithSSLServer

use of com.alipay.sofa.rpc.server.http.Http2WithSSLServer in project sofa-rpc by sofastack.

the class Http2WithSSLServerMain method main.

public static void main(String[] args) {
    System.setProperty("ssl", "true");
    System.setProperty("io.netty.handler.ssl.noOpenSsl", "false");
    String codebase = ReflectUtils.getCodeBase(Http2WithSSLServerMain.class);
    System.setProperty(RpcConfigKeys.CERTIFICATE_PATH.getAlias()[0], codebase + "selfSigned.crt");
    System.setProperty(RpcConfigKeys.PRIVATE_KEY_PATH.getAlias()[0], codebase + "privatekey.key");
    ApplicationConfig application = new ApplicationConfig().setAppName("test-server");
    ServerConfig serverConfig = new ServerConfig().setProtocol("h2").setPort(12300).setDaemon(false);
    ProviderConfig<ProtoService> providerConfig = new ProviderConfig<ProtoService>().setInterfaceId(ProtoService.class.getName()).setApplication(application).setRef(new ProtoServiceImpl()).setServer(serverConfig);
    providerConfig.export();
    ProviderConfig<HelloService> providerConfig2 = new ProviderConfig<HelloService>().setInterfaceId(HelloService.class.getName()).setApplication(application).setRef(new HelloServiceImpl()).setServer(serverConfig).setRegister(false);
    providerConfig2.export();
    // http://127.0.0.1:12300/com.alipay.sofa.rpc.test.HelloService/sayHello
    LOGGER.error("started at pid {}", RpcRuntimeContext.PID);
    final AtomicInteger cnt = ((ProtoServiceImpl) providerConfig.getRef()).getCounter();
    final ThreadPoolExecutor executor = ((Http2WithSSLServer) serverConfig.getServer()).getBizThreadPool();
    Thread thread = new Thread(new Runnable() {

        private long last = 0;

        @Override
        public void run() {
            while (true) {
                long count = cnt.get();
                long tps = count - last;
                LOGGER.error("last 10s invoke: {}, queue: {}", tps, executor.getQueue().size());
                last = count;
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                }
            }
        }
    }, "Print-tps-THREAD");
    thread.start();
}
Also used : ProtoServiceImpl(com.alipay.sofa.rpc.protobuf.ProtoServiceImpl) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) HelloService(com.alipay.sofa.rpc.test.HelloService) HelloServiceImpl(com.alipay.sofa.rpc.test.HelloServiceImpl) Http2WithSSLServer(com.alipay.sofa.rpc.server.http.Http2WithSSLServer) ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProtoService(com.alipay.sofa.rpc.protobuf.ProtoService) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Aggregations

ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)1 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)1 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)1 ProtoService (com.alipay.sofa.rpc.protobuf.ProtoService)1 ProtoServiceImpl (com.alipay.sofa.rpc.protobuf.ProtoServiceImpl)1 Http2WithSSLServer (com.alipay.sofa.rpc.server.http.Http2WithSSLServer)1 HelloService (com.alipay.sofa.rpc.test.HelloService)1 HelloServiceImpl (com.alipay.sofa.rpc.test.HelloServiceImpl)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1