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();
}
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();
}
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();
}
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();
}
Aggregations