• tomcat源码阅读_代码篇8


    连接器:

    包package org.apache.catalina.connector;

    构造函数:   

    public Connector()
            throws Exception {
            this(null);
        }

        public Connector(String protocol)
            throws Exception {
            setProtocol(protocol);//设置协议
            // Instantiate protocol handler
            try {
                Class clazz = Class.forName(protocolHandlerClassName);//加载处理协议的类,“org.apache.coyote.http11.Http11Protocol”
                this.protocolHandler = (ProtocolHandler) clazz.newInstance();//创建该类对象
            } catch (Exception e) {
                log.error
                    (sm.getString
                     ("coyoteConnector.protocolHandlerInstantiationFailed", e));
            }
        }

    其中setProtocal方法如下,会根据不同的协议加载不同的类:

        public void setProtocol(String protocol) {

            // Test APR support
            initializeAPR();

            if (aprInitialized) {
                if ("HTTP/1.1".equals(protocol)) {
                    setProtocolHandlerClassName
                        ("org.apache.coyote.http11.Http11AprProtocol");
                } else if ("AJP/1.3".equals(protocol)) {
                    setProtocolHandlerClassName
                        ("org.apache.coyote.ajp.AjpAprProtocol");
                } else if (protocol != null) {
                    setProtocolHandlerClassName(protocol);
                } else {
                    setProtocolHandlerClassName
                        ("org.apache.coyote.http11.Http11AprProtocol");
                }
            } else {
                if ("HTTP/1.1".equals(protocol)) {
                    setProtocolHandlerClassName
                        ("org.apache.coyote.http11.Http11Protocol");
                } else if ("AJP/1.3".equals(protocol)) {
                    setProtocolHandlerClassName
                        ("org.apache.jk.server.JkCoyoteHandler");
                } else if (protocol != null) {
                    setProtocolHandlerClassName(protocol);
                }
            }

        }

    initializeAPR方法会检查APR支持情况,暂保留该问题

    HTTP/1.1以及AJP/1.3

    initialize方法:

        public void initialize()
            throws LifecycleException
        {
            if (initialized) {
                if(log.isInfoEnabled())
                    log.info(sm.getString("coyoteConnector.alreadyInitialized"));
               return;
            }

            this.initialized = true;

            if( oname == null && (container instanceof StandardEngine)) {
                try {
                    // we are loaded directly, via API - and no name was given to us
                    StandardEngine cb=(StandardEngine)container;
                    oname = createObjectName(cb.getName(), "Connector");
                    Registry.getRegistry(null, null)
                        .registerComponent(this, oname, null);
                    controller=oname;
                } catch (Exception e) {
                    log.error( "Error registering connector ", e);
                }
                if(log.isDebugEnabled())
                    log.debug("Creating name for connector " + oname);
            }

            // Initializa adapter
            adapter = new CoyoteAdapter(this);//将当前对象封装到CoyoteAdapter适配器里面
            protocolHandler.setAdapter(adapter);

            IntrospectionUtils.setProperty(protocolHandler, "jkHome",
                                           System.getProperty("catalina.base"));

            try {
                protocolHandler.init();
            } catch (Exception e) {
                throw new LifecycleException
                    (sm.getString
                     ("coyoteConnector.protocolHandlerInitializationFailed", e));
            }
        }

    接下来的start、resume方法都是针对protocolHandler对象来进行的。

    使用它来处理连接。

  • 相关阅读:
    iOS
    UIView
    sql server 无法创建索引 因为对象名称和索引名称重复
    select2多选
    NPOI 给导出Excel添加简单样式
    NPOI简单的给某个单元格字体设置颜色
    ASP.NET MVC5 历史数据查询
    C# 反射Reflection
    C# 程序集Assembly
    GetExecutingAssembly() 和 GetCallingAssembly() 的区别
  • 原文地址:https://www.cnblogs.com/macula7/p/1960477.html
Copyright © 2020-2023  润新知