// Start our defined Connectors second synchronized (connectorsLock) { for (Connector connector : connectors) { // If it has already failed, don't try and start it if (connector.getState() != LifecycleState.FAILED) { connector.start(); } } } }
publicinterfaceProtocolHandler { //The adapter, used to call the connector. publicvoidsetAdapter(Adapter adapter); public Adapter getAdapter(); //The executor, provide access to the underlying thread pool. public Executor getExecutor(); //Initialise the protocol. publicvoidinit()throws Exception; //Start the protocol. publicvoidstart()throws Exception; //Pause the protocol (optional). publicvoidpause()throws Exception; //Resume the protocol (optional). publicvoidresume()throws Exception; //Stop the protocol. publicvoidstop()throws Exception; //Destroy the protocol (optional). publicvoiddestroy()throws Exception; /** * Close the server socket (to prevent further connections) if the server * socket was bound on {@link #start()} (rather than on {@link #init()} * but do not perform any further shutdown. */ publicvoidcloseServerSocketGraceful(); /** * Requires APR/native library * * @return <code>true</code> if this Protocol Handler requires the * APR/native library, otherwise <code>false</code> */ publicbooleanisAprRequired(); /** * Does this ProtocolHandler support sendfile? * * @return <code>true</code> if this Protocol Handler supports sendfile, * otherwise <code>false</code> */ publicbooleanisSendfileSupported(); publicvoidaddSslHostConfig(SSLHostConfig sslHostConfig); public SSLHostConfig[] findSslHostConfigs(); publicvoidaddUpgradeProtocol(UpgradeProtocol upgradeProtocol); public UpgradeProtocol[] findUpgradeProtocols(); }
/** * Endpoint that provides low-level network I/O - must be matched to the * ProtocolHandler implementation (ProtocolHandler using NIO, requires NIO * Endpoint etc.). */ privatefinal AbstractEndpoint<S,?> endpoint;
/** * The background thread that checks async requests and fires the * timeout if there has been no activity. * 后台线程检查异步请求,如果没有活动,则触发超时。 */ @Override publicvoidrun() { // Loop until we receive a shutdown command //循环,直到收到关机命令 while (asyncTimeoutRunning) { try { Thread.sleep(1000); } catch (InterruptedException e) { // Ignore } longnow= System.currentTimeMillis(); for (Processor processor : waitingProcessors) { processor.timeoutAsync(now); } // Loop if endpoint is paused //如果端点暂停,则循环 while (endpoint.isPaused() && asyncTimeoutRunning) { try { Thread.sleep(1000); } catch (InterruptedException e) { // Ignore } } } }