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对象来进行的。

    使用它来处理连接。

  • 相关阅读:
    C Socket编程之Connect超时 (转)
    【c#】设置Socket连接、接收超时(转)
    socket测试远程地址能否连接并为连接设置超时(转)
    ZedGraph右键菜单怎样禁止它弹出(转)
    赚钱本身就是人生目的
    如果一个女人喜欢你,又不跟你在一起,而且只跟你很暧昧,那代表什么
    LayoutInflater的使用
    Android应用程序的生命周期
    Android的系统服务一览
    Android系统服务-简介
  • 原文地址:https://www.cnblogs.com/macula7/p/1960477.html
Copyright © 2011-2022 走看看