Search in sources :

Example 1 with BoltServer

use of com.alipay.sofa.rpc.server.bolt.BoltServer in project sofa-rpc by sofastack.

the class ProtobufServiceServerMain method main.

public static void main(String[] args) {
    ServerConfig serverConfig = new ServerConfig().setProtocol(// 设置一个协议,默认bolt
    "bolt").setPort(// 设置一个端口,默认12200
    12200).setDaemon(// 非守护线程
    false);
    ProviderConfig<ProtoService> providerConfig = new ProviderConfig<ProtoService>().setInterfaceId(// 指定接口
    ProtoService.class.getName()).setRef(// 指定实现
    new ProtoServiceImpl()).setServer(// 指定服务端
    serverConfig);
    // 发布服务
    providerConfig.export();
    LOGGER.error("started at pid {}", RpcRuntimeContext.PID);
    final AtomicInteger cnt = ((ProtoServiceImpl) providerConfig.getRef()).getCounter();
    final ThreadPoolExecutor executor = ((BoltServer) 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 1s invoke: {}, queue: {}", tps, executor.getQueue().size());
                last = count;
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                }
            }
        }
    }, "Print-tps-THREAD");
    thread.start();
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) BoltServer(com.alipay.sofa.rpc.server.bolt.BoltServer)

Example 2 with BoltServer

use of com.alipay.sofa.rpc.server.bolt.BoltServer in project sofa-boot by alipay.

the class ServerConfigContainer method startServers.

/**
 * 开启所有 ServerConfig 对应的 Server
 */
public void startServers() {
    if (boltServerConfig != null) {
        boltServerConfig.buildIfAbsent().start();
        BoltServer server = (BoltServer) boltServerConfig.getServer();
        ThreadPoolExecutor threadPoolExecutor = server.getBizThreadPool();
        if (threadPoolExecutor != null) {
            boltThreadPoolMonitor.setThreadPoolExecutor(threadPoolExecutor);
            boltThreadPoolMonitor.start();
        } else {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("the business threadpool can not be get");
            }
        }
    }
    if (restServerConfig != null) {
        restServerConfig.buildIfAbsent().start();
    }
    if (h2cServerConfig != null) {
        h2cServerConfig.buildIfAbsent().start();
    }
    if (httpServerConfig != null) {
        httpServerConfig.buildIfAbsent().start();
    // 加入线程监测?
    }
    if (tripleServerConfig != null) {
        tripleServerConfig.buildIfAbsent().start();
        TripleServer tripleServer = (TripleServer) tripleServerConfig.getServer();
        ThreadPoolExecutor threadPoolExecutor = tripleServer.getBizThreadPool();
        if (threadPoolExecutor != null) {
            tripleThreadPoolMonitor.setThreadPoolExecutor(threadPoolExecutor);
            tripleThreadPoolMonitor.start();
        } else {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("the business threadpool can not be get");
            }
        }
    }
    for (Map.Entry<String, ServerConfig> entry : customServerConfigs.entrySet()) {
        final ServerConfig serverConfig = entry.getValue();
        if (serverConfig != null) {
            serverConfig.buildIfAbsent().start();
        }
    }
    startCustomThreadPoolMonitor();
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) BoltServer(com.alipay.sofa.rpc.server.bolt.BoltServer) TripleServer(com.alipay.sofa.rpc.server.triple.TripleServer) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with BoltServer

use of com.alipay.sofa.rpc.server.bolt.BoltServer in project hugegraph-common by hugegraph.

the class RpcServer method port.

public int port() {
    this.checkEnabled();
    Server server = this.serverConfig.getServer();
    if (server instanceof BoltServer && server.isStarted()) {
        /*
             * When using random port 0, try to fetch the actual port
             * NOTE: RemotingServer.port() would return the actual port only
             *       if sofa-bolt version >= 1.6.1, please see:
             *       https://github.com/sofastack/sofa-bolt/issues/196
             * TODO: remove this code after adding Server.port() interface:
             *       https://github.com/sofastack/sofa-rpc/issues/1022
             */
        RemotingServer rs = Whitebox.getInternalState(server, "remotingServer");
        return rs.port();
    }
    // When using random port 0, the returned port is not the actual port
    return this.serverConfig.getPort();
}
Also used : BoltServer(com.alipay.sofa.rpc.server.bolt.BoltServer) RemotingServer(com.alipay.remoting.RemotingServer) Server(com.alipay.sofa.rpc.server.Server) RemotingServer(com.alipay.remoting.RemotingServer) BoltServer(com.alipay.sofa.rpc.server.bolt.BoltServer)

Example 4 with BoltServer

use of com.alipay.sofa.rpc.server.bolt.BoltServer in project sofa-boot by sofastack.

the class ServerConfigContainer method startServers.

/**
 * 开启所有 ServerConfig 对应的 Server
 */
public void startServers() {
    if (boltServerConfig != null) {
        boltServerConfig.buildIfAbsent().start();
        BoltServer server = (BoltServer) boltServerConfig.getServer();
        ThreadPoolExecutor threadPoolExecutor = server.getBizThreadPool();
        if (threadPoolExecutor != null) {
            boltThreadPoolMonitor.setThreadPoolExecutor(threadPoolExecutor);
            boltThreadPoolMonitor.start();
        } else {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("the business threadpool can not be get");
            }
        }
    }
    if (restServerConfig != null) {
        restServerConfig.buildIfAbsent().start();
    }
    if (h2cServerConfig != null) {
        h2cServerConfig.buildIfAbsent().start();
    }
    if (httpServerConfig != null) {
        httpServerConfig.buildIfAbsent().start();
    // 加入线程监测?
    }
    if (tripleServerConfig != null) {
        tripleServerConfig.buildIfAbsent().start();
        TripleServer tripleServer = (TripleServer) tripleServerConfig.getServer();
        ThreadPoolExecutor threadPoolExecutor = tripleServer.getBizThreadPool();
        if (threadPoolExecutor != null) {
            tripleThreadPoolMonitor.setThreadPoolExecutor(threadPoolExecutor);
            tripleThreadPoolMonitor.start();
        } else {
            if (LOGGER.isWarnEnabled()) {
                LOGGER.warn("the business threadpool can not be get");
            }
        }
    }
    for (Map.Entry<String, ServerConfig> entry : customServerConfigs.entrySet()) {
        final ServerConfig serverConfig = entry.getValue();
        if (serverConfig != null) {
            serverConfig.buildIfAbsent().start();
        }
    }
    startCustomThreadPoolMonitor();
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) BoltServer(com.alipay.sofa.rpc.server.bolt.BoltServer) TripleServer(com.alipay.sofa.rpc.server.triple.TripleServer) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

BoltServer (com.alipay.sofa.rpc.server.bolt.BoltServer)4 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)3 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)3 TripleServer (com.alipay.sofa.rpc.server.triple.TripleServer)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 RemotingServer (com.alipay.remoting.RemotingServer)1 Server (com.alipay.sofa.rpc.server.Server)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1