tomcat Connector 连接器
?
連接器的核心功能,本文去除非核心功能,留下整個程序的框架,便于理解。
1、接受連接請求
2.創(chuàng)建request,和response.
3.調(diào)用容器對應(yīng)的Invoke方法,
?首先看類的依賴結(jié)構(gòu)。
1.Connetor 構(gòu)造方法,根據(jù)具體的協(xié)議名字,創(chuàng)建協(xié)議處理器,主要有NIO,BIO,AJP,協(xié)議。如果要自定義協(xié)議處理劑最重要的協(xié)議處理器了。如圖,協(xié)議處理需要實現(xiàn)ProtocoHandler接口,
?構(gòu)造函數(shù) 輸入為協(xié)議名稱
public Connector(String protocol) {setProtocol(protocol);// Instantiate protocol handlerProtocolHandler p = null;try {Class<?> clazz = Class.forName(protocolHandlerClassName);// 實例化一個協(xié)議處理器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 和相應(yīng) ?此處不仔細(xì)深入。很簡單。就是創(chuàng)建請求和相應(yīng)對象
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.啟動和關(guān)閉。是默認(rèn)方法;
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的重要性了明天再看
?
?
?
?
?
?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/hansongjiang/p/4194300.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的tomcat Connector 连接器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: django-celery
- 下一篇: Python实现Adaboost