tomcat Connector 连接器
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了tomcat Connector 连接器,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2073字,纯文字阅读大概需要3分钟。
内容图文
连接器的核心功能,本文去除非核心功能,留下整个程序的框架,便于理解。
1、接受连接请求
2.创建request,和response.
3.调用容器对应的Invoke方法,
首先看类的依赖结构。
1.Connetor 构造方法,根据具体的协议名字,创建协议处理器,主要有NIO,BIO,AJP,协议。如果要自定义协议处理剂最重要的协议处理器了。如图,协议处理需要实现ProtocoHandler接口,
构造函数 输入为协议名称
public Connector(String protocol) { setProtocol(protocol); // Instantiate protocol handler ProtocolHandler 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) { thrownew 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() + "\"; "; } thrownew 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的重要性了明天再看
原文:http://www.cnblogs.com/hansongjiang/p/4194300.html
内容总结
以上是互联网集市为您收集整理的tomcat Connector 连接器全部内容,希望文章能够帮你解决tomcat Connector 连接器所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。