Basic knowledge of Tomcat (a)

Architecture top
to the top-level structure (Figure A) a Tomcat, as follows:

 

 

 

Tomcat topmost containers are Server, represent the entire server can be seen from the diagram above, a-Service Server may comprise at least one, for a particular service.

Service consists mainly of two parts: Connector and Container. Tomcat can be seen that these two components of the heart from the figure above, their role is as follows:

1, Connector for processing connection-related things, and provide related conversion Socket Request and Response; 2, Container for packaging and managing Servlet, and specific processing request Request;

Only one of a Tomcat Server, a Server can contain multiple Service, a Service is only one Container, but can have multiple Connectors, because a service can have multiple connections, such as while providing Http and Https link can also be provided connected to different ports of the same protocol, a schematic diagram is as follows (Engine, Host, Context we will discuss below):

 

 

 

More Connector and a Container on the formation of a Service, with Service can provide services, but also a living environment Service, someone must be able to give her life, grasp the power of life and death, it is none other than the non-Server up! So the whole life cycle is controlled by the Tomcat Server.

Furthermore, the inclusion relationship or a parent-child relationship, can be seen in the server.xml configuration file in the conf directory of tomcat, the lower figure is a complete configuration file server.xml (Tomcat version later deleted the comment content 8.0)

 

 

 

Detailed configuration file content to Tomcat can view the official website: http: //tomcat.apache.org/tomcat-8.0-doc/index.html

The upper profile, also may be more clearly understood from the lower side of a block diagram:

 

 

 

Server port number tag set for 8005, shutdown = "SHUTDOWN", said in 8005 the port monitor "SHUTDOWN" command, if the reception will be closed to the Tomcat. A Server has a Service, of course, can also be configured, there are more than a Service, Service contents belong to the left of the Container, Service Below is a Connector.

Tomcat top architecture Summary:
(1) only one Tomcat Server, a Server can have multiple Service, a Service can have multiple Connector and a Container; 
(2) Server Tomcat in charge of the whole of life and death power; 
(4) Service is the external service provider; 
(. 5) Connector for receiving requests and packaged into request and Response to a specific process; 
(. 6) Container for packaging and managing Servlet, and specific processing rEQUEST request;

I know the relationship between the whole and the role of Tomcat top of layered architecture and various components, for the vast majority of developers Server and Service for us, really far away, and we have developed in most of the content configuration Connector and Container belongs to, so tell us about the next Connector and Container.

Connector and Container delicate relationship of
the above we know that generally after a request is sent to the Tomcat, first through the Service will then give us the Connector, Connector for requesting and receiving a request for the received encapsulated Request and Response to specific processing, request and Response Container after completing the package and then by processing, and then returns to the Connector Container after the request has been processed, and finally returned to the client through the Socket Connector result obtained by the process, so that it is finished processing the entire request!

Connector bottom is used to connect the Socket, Request and Response in accordance with HTTP protocol encapsulation, so the need to achieve Connector while TCP / IP protocol and the HTTP protocol!

Since Tomcat processes the request, then certainly need to receive this request, the request is received first thing we need to look at the Connector!

Connector Architecture Analysis
Connector for receiving requests and packaged into Request and Response, and then to the Container processing, after completion of processing to the Connector Container returned to the client.

Therefore, we can understand Connector is divided into four areas:

How to (1) Connector to accept the request? (2) How to request encapsulated into the Request and Response? (3) after the completion of the package Request and Response Container how to be treated? (4) Container after processing How to Connector and returned to the client?

First look at the structure of FIG Connector (FIG. B), as follows:

 

 

 

Connector ProtocolHandler is used to process the request, different connection types different ProtocolHandler representatives, such as: Http11Protocol Socket by using a common connection, Http11NioProtocol is used to connect the NioSocket.

Which contains three components from the ProtocolHandler: Endpoint, Processor, Adapter.

(. 1) Endpoint Socket for processing of the underlying network connection, Processor for Socket Endpoint received encapsulated Request, Adapter for Container Request to perform specific processing.

(2) Endpoint process because it is the underlying network Socket connection, so Endpoint is used to achieve TCP / IP protocol, and the HTTP protocol to implement Processor, Adapter request to the Servlet container adapted for specific processing.

(3) Endpoint abstract implementation AbstractEndpoint inside AsyncTimeout Acceptor and two internal classes and interfaces defined in a Handler. Acceptor to listen request, AsyncTimeout Request for checking asynchronous timeout, Handler for processing the received Socket, Processor calls are processed internally.

At this point, we should be very easy to answer (1) (2) (3) of the question, but (4) still do not know, then we look at how the Container is processed and after the processing is how processed the results are returned to the Connector?

Container Architecture Analysis
Container for packaging and managing Servlet, and specific processing request Request inside Connector 4 comprises a sub-container, the following chart (FIG. C):

 

 

 

4 child container action are:

(1) Engine: engine, used to manage multiple sites, a Service can only have a maximum of Engine; (2) Host: represents a site, can also be called a virtual host, Host can be added by configuring the site; (3) Context : represents an application program corresponding to a normal development, or a WEB-INF directory and below web.xml file; (. 4) Wrapper: each encloses a Wrapper the Servlet;

Here Tomcat file directory to find a control bit, as shown below:

 

 

 

Host is the difference between Context and Context represents an application, each file in the Tomcat webapps under our default configuration directory is a folder Context, ROOT directory in which to store the main application, other sub-directory for the application, and the entire webapps is a Host site.

When we access the application Context, if it is using the domain name directly under the ROOT can access, such as: www.ledouit.com, if other applications are under Host (webapps), you can use the www.ledouit.com/docs be visit, of course, the default specified application root (rOOT) can be set only by default under the Main Host site is used under the rOOT directory.

Here we see the Container know what is, but still do not know how Container is processed and the results after completion of the deal is how to deal with the return to the Connector's? But wait! Below began to explore how Container is handled!

Container processing request
Container processing request is to use Pipeline-Valve pipeline process! (Valve is a valve intended)

Pipeline-Valve is a chain of responsibility pattern, the chain of responsibility pattern refers to the process in the processing of a request handler in turn has a lot to process the request, each handler is responsible for doing their own appropriate treatment, requests the processed after processing the return , under a deal to let the process continue.

 

 

 

but! Chain of Responsibility pattern Pipeline-Valve and the general use of the chain of responsibility pattern is somewhat different! The main difference between the following two points:

(1) Each Pipeline has a specific Valve, and the last execution in the pipeline, this is called BaseValve Valve, BaseValve not be deleted; (2) in the upper container BaseValve pipeline in the pipeline will call the lower container.

We know Container contains four sub-containers, sub-containers and four respectively in the corresponding BaseValve: StandardEngineValve, StandardHostValve, StandardContextValve, StandardWrapperValve.

Pipeline processing of the flowchart is as follows (FIG. D):

 

 

 

(1) Connector after receiving the first call request will be Pipeline topmost container for processing, where the topmost container Pipeline is EnginePipeline (Engine conduit);

(2) the order will be executed Engine pipeline EngineValve1, EngineValve2 etc., and finally performs StandardEngineValve, in StandardEngineValve will call the Host pipeline, and then followed by the implementation of HostValve1 Host, HostValve2, and finally in the implementation of StandardHostValve, then turn call Context Wrapper pipes and pipelines, final implementation to StandardWrapperValve.

(3) when performing the StandardWrapperValve, it will create in StandardWrapperValve in FilterChain, and call its doFilter method to process the request, the FilterChain contains the request that matches the Filter and Servlet our configuration, it doFilter method will call all the Filter doFilter method and the method of the Servlet service, so that requests have been addressed!

(4) When all of the Pipeline-Valve have been executed, and the process is finished particular request, this time may be the results returned to the Connector, Connector returns the result to the client through the Socket embodiment.

Summarizes
this point, we have a general understanding of the overall architecture of Tomcat, Figure A, B, C, D can be seen the basic elements and the role of each component. We should have in mind a rough outline of the

Guess you like

Origin www.cnblogs.com/chz-blogs/p/11448635.html