tomcat Connector 连接器
?
連接器的核心功能,本文去除非核心功能,留下整個程序的框架,便于理解。
1、接受連接請求
2.創建request,和response.
3.調用容器對應的Invoke方法,
?首先看類的依賴結構。
1.Connetor 構造方法,根據具體的協議名字,創建協議處理器,主要有NIO,BIO,AJP,協議。如果要自定義協議處理劑最重要的協議處理器了。如圖,協議處理需要實現ProtocoHandler接口,
?構造函數 輸入為協議名稱
public Connector(String protocol) {setProtocol(protocol);// Instantiate protocol handlerProtocolHandler p = null;try {Class<?> clazz = Class.forName(protocolHandlerClassName);// 實例化一個協議處理器p = (ProtocolHandler) clazz.newInstance();} catch (Exception e) {log.error(sm.getString("coyoteConnector.protocolHandlerInstantiationFailed"), e);} finally {this.protocolHandler = p;}if (!Globals.STRICT_SERVLET_COMPLIANCE) {URIEncoding = "UTF-8";URIEncodingLower = URIEncoding.toLowerCase(Locale.ENGLISH);}}
2.createRequest 和相應 ?此處不仔細深入。很簡單。就是創建請求和相應對象
public Request createRequest() {Request request = new Request();request.setConnector(this);return (request);}/*** Create (or allocate) and return a Response object suitable for* receiving the contents of a Response from the responsible Container.*/public Response createResponse() {Response response = new Response();response.setConnector(this);return (response);}?
3.啟動和關閉。是默認方法;
protected void startInternal() throws LifecycleException {// Validate settings before startingif (getPort() < 0) {throw new LifecycleException(sm.getString("coyoteConnector.invalidPort", Integer.valueOf(getPort())));}setState(LifecycleState.STARTING);try {protocolHandler.start();} catch (Exception e) {String errPrefix = "";if(this.service != null) {errPrefix += "service.getName(): \"" + this.service.getName() + "\"; ";}throw new LifecycleException(errPrefix + " " + sm.getString("coyoteConnector.protocolHandlerStartFailed"), e);}}protected void stopInternal() throws LifecycleException {
?
?
setState(LifecycleState.STOPPING);
try {
protocolHandler.stop();
} catch (Exception e) {
throw new LifecycleException
(sm.getString
("coyoteConnector.protocolHandlerStopFailed"), e);
}
}
?
?
我們從代碼看到ProtocoHandler的重要性了明天再看
?
?
?
?
?
?
?
?
轉載于:https://www.cnblogs.com/hansongjiang/p/4194300.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的tomcat Connector 连接器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: django-celery
- 下一篇: Python实现Adaboost