BoltServer implements Server { @Override public void start() { if (started) { return; } synchronized (this) { if (started) { return; } remotingServer = initRemotingServer(); try { if (remotingServer.start()) { if (LOGGER.isInfoEnabled()) { LOGGER.info("Bolt server has been bind to {}:{}", serverConfig.getBoundHost(), serverConfig.getPort()); } } else { throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_START_BOLT_SERVER)); } started = true; if (EventBus.isEnable(ServerStartedEvent.class)) { EventBus.post(new ServerStartedEvent(serverConfig, bizThreadPool)); } } catch (SofaRpcRuntimeException e) { throw e; } catch (Exception e) { throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_START_BOLT_SERVER), e); } } }  @Override void init(ServerConfig serverConfig); @Override void start(); @Override boolean isStarted(); @Override boolean hasNoEntry(); @Override void stop(); @Override void registerProcessor(ProviderConfig providerConfig, Invoker instance); @Override void unRegisterProcessor(ProviderConfig providerConfig, boolean closeIfNoEntry); @Override void destroy(); @Override void destroy(DestroyHook hook); ThreadPoolExecutor getBizThreadPool(); Invoker findInvoker(String serviceName); void cleanReflectCache(ProviderConfig providerConfig);  }
@Test public void start() throws Exception { String host = "127.0.0.1"; int port = 17701; ServerConfig serverConfig = new ServerConfig(); serverConfig.setBoundHost(host); serverConfig.setPort(port); serverConfig.setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT); BoltServer server = new BoltServer(); server.init(serverConfig); server.start(); Assert.assertTrue(server.started); Assert.assertTrue(NetUtils.canTelnet(host, port, 1000)); ServerConfig serverConfig2 = new ServerConfig(); serverConfig2.setBoundHost(host); serverConfig2.setPort(port); serverConfig2.setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT); BoltServer server2 = new BoltServer(); server2.init(serverConfig2); boolean error = false; try { server2.start(); } catch (Exception e) { error = true; } Assert.assertTrue(error); server.stop(); Assert.assertFalse(server.started); Thread.sleep(1000); Assert.assertFalse(NetUtils.canTelnet(host, port, 1000)); server.start(); Assert.assertTrue(server.started); Assert.assertTrue(NetUtils.canTelnet(host, port, 1000)); server.stop(); Assert.assertFalse(server.started); Thread.sleep(1000); Assert.assertFalse(NetUtils.canTelnet(host, port, 1000)); server.destroy(); }