Tomcat 7 Connector Intensive (1)

Source: Internet
Author: User

This class diagram is the method and property of the most important class that I intercept.

Where Protocalhandler is the protocol processor, Tomcat supports the protocols that are seen in the following ways. Different protocols implement different Protocalhandler classes.

 Public voidSetprotocol (String protocol) {if(Aprlifecyclelistener.isapravailable ()) {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.Http11NioProtocol"); } Else if("ajp/1.3". Equals (protocol)) {Setprotocolhandlerclassname ("Org.apache.coyote.ajp.AjpNioProtocol"); } Else if(Protocol! =NULL) {setprotocolhandlerclassname (protocol); }        }    }
View Code

Protocalhandler is the core of the entire connector class.

When initializing the connector, the processor object is created according to the protocol name.

  PublicConnector (String protocol) {Setprotocol (protocol); //Instantiate protocol HandlerProtocolhandler 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); }    }
View Code

The first is to initialize the Protocol processor (remove the less important code)

protected void throws lifecycleexception {        super. initinternal ();         // Initialize Adapter        New Coyoteadapter (this);        Protocolhandler.setadapter (adapter);
Each protocol processor has a corresponding adapter, what does the adapter do? protocolhandler.init (); }

Connector boot, actually start the corresponding protocol processor,

 protected voidStartinternal ()throwslifecycleexception {//Validate settings before starting        if(Getport () < 0) {            Throw Newlifecycleexception (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 Newlifecycleexception (Errprefix+ " " +sm.getstring ("Coyoteconnector.protocolhandlerstartfailed"), E); }    }
View Code

Termination is actually terminating the Protocol processor

 protected voidStartinternal ()throwslifecycleexception {//Validate settings before starting        if(Getport () < 0) {            Throw Newlifecycleexception (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 Newlifecycleexception (Errprefix+ " " +sm.getstring ("Coyoteconnector.protocolhandlerstartfailed"), E); }    }
View Code

You see here, actually see the connector class need to do the following work

(1) Create a Request object

/**       * Create (or allocate) and return a request object suitable for     * Specifying the contents of a request to the Responsible Container.      */     Public Request createrequest () {        new  request ();        Request.setconnector (this);         return (request);    }

(2) Create a Response object

  /**      * Create (or allocate) and return a Response object suitable for     * receiving the contents of a Response from The responsible Container.      */     Public Response Createresponse () {        new  Response ();        Response.setconnector (this);         return (response);    }

(3) to the two objects to the container, simply speaking, after creating the good object, passed to the adapter class is OK. Coyoteadapter class

Tomcat 7 Connector Intensive (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.