加入收藏 | 设为首页 | 会员中心 | 我要投稿 应用网_丽江站长网 (http://www.0888zz.com/)- 科技、建站、数据工具、云上网络、机器学习!
当前位置: 首页 > 站长资讯 > 外闻 > 正文

查漏补缺:连接器在Tomcat中是如何设计的

发布时间:2019-09-24 16:26:56 所属栏目:外闻 来源:今日头条
导读:副标题#e# 从连接器(Connector)源码说起 既然是来解析连接器(Connector),那么我们直接从源码入手,后面所有源码我会剔除不重要部分,所以会忽略大部分源码细节,只关注流程。源码如下(高能预警,大量代码): publicclassConnectorextendsLifecycleMBeanBas

根据上面源码,我们发现主要是处理protocolHandler并初始化它,同时我们注意到了protocolHandler 设置了一个适配器,我们看看这个适配器是做啥的,跟踪源码如下:

  1. /** 
  2.  * The adapter, used to call the connector. 
  3.  * 
  4.  * @param adapter The adapter to associate 
  5.  */ 
  6.  public void setAdapter(Adapter adapter); 

这个注释已经说的很直白了,这个适配器就是用来调用连接器的。我们再继续看看protocolHandler的初始化方法

  1.  /** 
  2.  * Endpoint that provides low-level network I/O - must be matched to the 
  3.  * ProtocolHandler implementation (ProtocolHandler using NIO, requires NIO 
  4.  * Endpoint etc.). 
  5.  */ 
  6. private final AbstractEndpoint<S,?> endpoint; 
  7. public void init() throws Exception { 
  8.  if (getLog().isInfoEnabled()) { 
  9.  getLog().info(sm.getString("abstractProtocolHandler.init", getName())); 
  10.  logPortOffset(); 
  11.  } 
  12.  if (oname == null) { 
  13.  // Component not pre-registered so register it 
  14.  oname = createObjectName(); 
  15.  if (oname != null) { 
  16.  Registry.getRegistry(null, null).registerComponent(this, oname, null); 
  17.  } 
  18.  } 
  19.  if (this.domain != null) { 
  20.  rgOname = new ObjectName(domain + ":type=GlobalRequestProcessor,name=" + getName()); 
  21.  Registry.getRegistry(null, null).registerComponent( 
  22.  getHandler().getGlobal(), rgOname, null); 
  23.  } 
  24.  String endpointName = getName(); 
  25.  endpoint.setName(endpointName.substring(1, endpointName.length()-1)); 
  26.  endpoint.setDomain(domain); 
  27.  endpoint.init(); 
  28.  } 

(编辑:应用网_丽江站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读