@Override
public void start() {
if (started) {
return;
}
synchronized (this) {
if (started) {
return;
}
// 生成阿里基于netty的bolt服务Server对象
remotingServer = initRemotingServer();
try {
if (remotingServer.start(serverConfig.getBoundHost())) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Bolt server has been bind to {}:{}", serverConfig.getBoundHost(),
serverConfig.getPort());
}
} else {
throw new SofaRpcRuntimeException("Failed to start bolt server, see more detail from bolt log.");
}
started = true;
if (EventBus.isEnable(ServerStartedEvent.class)) {
EventBus.post(new ServerStartedEvent(serverConfig, bizThreadPool));
}
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Exception e) {
throw new SofaRpcRuntimeException("Failed to start bolt server!", e);
}
}
}
AbstractHttpServer 提供http服务,底层通信通过ServerTransport类实现的
/**
* 服务端通讯层
*/
private ServerTransport serverTransport;
@Override
public void init(ServerConfig serverConfig) {
this.serverConfig = serverConfig;
this.serverTransportConfig = convertConfig(serverConfig);
// 启动线程池
this.bizThreadPool = initThreadPool(serverConfig);
// 服务端处理器
this.serverHandler = new HttpServerHandler();
// set default transport config
this.serverTransportConfig.setContainer(container);
this.serverTransportConfig.setServerHandler(serverHandler);
}
@Override
public void start() {
if (started) {
return;
}
synchronized (this) {
if (started) {
return;
}
try {
// 启动线程池
this.bizThreadPool = initThreadPool(serverConfig);
this.serverHandler.setBizThreadPool(bizThreadPool);
//实例化服务,具体代码见
serverTransport = ServerTransportFactory.getServerTransport(serverTransportConfig);
started = serverTransport.start();