Tomcat source code analysis II: first look at the overall architecture of Tomcat

Tomcat source code analysis II: first look at the overall architecture of Tomcat

Tomcat Chart

Let's look at a more classic Tomcat architecture diagram:

From this figure, we can see that contains Tomcat Server, Service, Connector, Container and other components, then we went to look at the general interrelationship between these components and their role. Prior to this, we first supplement a knowledge point, the point is, what function it implements Tomcat is it? By looking for some information, refer to the geeks time here "thorough dismantling Tomcat_Jetty" in summary, that Tomcat to achieve two core functions:

  • Socket connection processing, and is responsible for conversion of the byte stream object Request and Response Network;
  • Loading and managing Servlet, and specific processing request Request.

Corresponds to the architecture of Figure, Tomcat designed two core components: a connector (Connector) and the container (Container) respectively to do two things. The connector is responsible for foreign exchange, which is handling Socket connections container is responsible for internal processing.

Introduction of the components

Before introducing the components, let's look at this relationship the following diagram:

As it can be seen from the figure, the top layer Server (not indicated in the figure), i.e. a Tomcat instance. In a Server Service below you can have many service, and each service is divided into Service and container connector, which is above architecture diagram Connector and Container, which can have multiple connectors, and the container is only one connector Connector and the interaction between the container and the container is by ServletRequest ServletResponse communication.

There may be multiple Service within Tomcat, which is designed for flexibility considerations. By configuring multiple Service in Tomcat, you can achieve different applications to be deployed on the same machine access through a different port number.

In fact, we can focus on the following Tomcat in conf / web.xml configuration:

Below, we look at the content focused connector connector and the container vessel

Connector Connector

Connector for shielded Servlet container distinction protocol type and I / O models, either HTTP or AJP, acquired in the container is a standard ServletRequest object. Connector first look at the design of the structure diagram:

Reference "in-depth dismantling Tomcat_Jetty" regarding Connector functionality summary, mainly has the following functions:

  • Listening to the network port.
  • Receiving network connection request.
  • Network byte stream read request.
  • (HTTP / AJP) parsing the byte stream according to the particular application layer protocol, to generate uniform Tomcat Request object.
  • The Tomcat Request object into a standard ServletRequest.
  • Servlet container calls, get ServletResponse.
  • The Tomcat Response ServletResponse turn into an object.
  • The Tomcat Response byte stream into a network switch.
  • The stream of bytes written response back to the browser.

As it can be seen from the above structure diagram, in ProtocolHandler Connector to process the request, which includes three main components, namely Endpoint, Processor, Adapter and the like. We interface and its subclasses look at ProtocolHandler class diagram:

Details on connector Connector will be described in detail separately at a later stage.

Container vessel

Tomcat designed four containers are Engine, Host, Context, and the Wrapper, which belongs to the parent-child relationship. Referring specifically mentioned in the above Tomcat conf / web.xml. Specific relationships illustrated in Figure 17 (Source: Baidu):

Applications for these four vessels:

  • Engine: the entire Catalina Servlet engine;
  • Host: host comprises one or more virtual containers Context;
  • Context: represents a Web application, may comprise a plurality of the Wrapper;
  • Wrapper: represents a separate Servlet;

Container on the specific content of the container will be described in detail separately at a later stage.

This paper describes the general architecture Tomcat, also generally describes the structure of Connector and Container, based on source code will be later detailed description of the related art and the contents of components therein implemented.

Reference material

  • "Thorough dismantling Tomcat_Jetty" Geek Time

Micro-channel public number: Source Bay

We welcome the focus on micro-channel public number: Source Bay. This number will from time to time the public associated source code and share relevant technology development, common development and common progress ~


Blog:

Guess you like

Origin www.cnblogs.com/zhiyouwu/p/11670694.html