DefaultProviderBootstrap.java for(ServerConfig serverConfig : serverConfigs){ try { Server server = serverConfig.buildIfAbsent(); // 注册序列化接口 server.registerProcessor(providerConfig, providerProxyInvoker); if (serverConfig.isAutoStart()) { server.start(); } } catch (SofaRpcRuntimeException e) { throw e; } catch (Exception e) { LOGGER.errorWithApp(appName, "Catch exception when register processor to server: " + serverConfig.getId(), e); } }
//BoltServer.java @Override publicvoidstart(){ if (started) { return; } synchronized (this) { if (started) { return; } // 生成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 { thrownew 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)); }
//RpcServer.java ->sofa-bolt项目 privatestaticfinal NioEventLoopGroup workerGroup = new NioEventLoopGroup(Runtime.getRuntime().availableProcessors() * 2, new NamedThreadFactory("Rpc-netty-server-worker"));
publicRpcServer(int port){ super(port); this.globalSwitch = new GlobalSwitch(); this.connectionEventListener = new ConnectionEventListener(); this.userProcessors = new ConcurrentHashMap(4); this.bossGroup = new NioEventLoopGroup(1, new NamedThreadFactory("Rpc-netty-server-boss")); }