zoukankan      html  css  js  c++  java
  • tomcat Connector 连接器

    连接器的核心功能,本文去除非核心功能,留下整个程序的框架,便于理解。

    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 starting
            if (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的重要性了明天再看

     
  • 相关阅读:
    JavaScript学习总结--事件冒泡与事件捕获
    JavaScript学习总结5--事件对象
    使用“微信公众号淘客管理工具”10分钟就能搭建淘客返利公众号
    C#实现通过拼多多分享微信公众号实现查询优惠券、佣金比率
    C# 实现生成带二维码的专属微信公众号推广海报
    公众号搭建淘宝、京东、拼多多查券平台
    开始使用Material UI
    Jenkins执行批处理文件失败
    取消Jquery mobile自动省略的文本
    C#调用Win32 api时的内存操作
  • 原文地址:https://www.cnblogs.com/hansongjiang/p/4194300.html
Copyright © 2011-2022 走看看