zoukankan      html  css  js  c++  java
  • 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对象来进行的。

    使用它来处理连接。

  • 相关阅读:
    ruby -- 进阶学习(十三)解说ckeditor在production环境下如何完整显示
    ruby -- 进阶学习(十二)fragment cache
    ruby -- 进阶学习(十一)配置解决production环境下无法加载css或js
    ruby -- 问题解决(六)link_to to destroy not working
    ruby -- 基础学习(七)时间的内置函数和格式说明
    ruby -- 进阶学习(十)自定义路由中:new, :collection和:member的区别
    ruby -- 进阶学习(九)定制错误跳转404和500
    C++ -- STL泛型编程(二)之set
    SVN库文件上传操作步骤
    jmeter 正则表达式基础语法
  • 原文地址:https://www.cnblogs.com/macula7/p/1960477.html
Copyright © 2011-2022 走看看