- Event management
The extension mechanism of Tomcat is extended by corresponding listeners in various scenarios for containers and business requests
- Connection management
- Request management
- Container management
- Application management
This section describes how the application is recognized, loaded, and requested by Tomcat
- The overall architecture
Component-oriented, JMX-based, event listening
- Server: the entire Tomcat Server, which contains multiple groups of services, manages and starts each Service, and listens for the shutdown command sent from port 8005 to shutdown the entire container. Server is the top-level component that represents a running instance of Tomcat. There is only one Server in a JVM that controls the entire Tomcat life cycle. Throughout the life cycle of a Server, different phases have different things to accomplish. For easy extension, it introduces a Listener mode, so it also includes a Listener component. In addition, to facilitate JNDI integration in Tomcat, the GlobalNamingResources component was introduced. The Tomcat kernel is highly abstract and consists of Connector components and Container components. The Connector component is responsible for processing client requests and parsing messages on the server, while the Container component is responsible for logical processing of client requests and returning the results to the client.
- Service: Tomcat encapsulates and provides complete component-based Web services externally, including Connectors and Container, and multiple functional components. Services are independent of each other, but share resources of the same JVM. A Service is an abstraction of a Service. It represents a collection of all components of a request from receiving to processing, forming an independent and complete processing unit to provide services externally. Each Service component contains a Connector component for receiving client messages and an Engine component for processing requests. Different Connector components use different communication protocols, such as HTTP and AJP. In addition, the Service component contains several Executor components, each of which is a thread pool that provides a thread pool for all components within the Service to perform tasks. Generally, you do not need to configure multiple services. Tomcat has one Catalina
configured by default.
- Connector: Tomcat connects to the outside world. It monitors fixed ports to receive external requests, encapsulates data exchange of Request and Response objects based on protocols, sends the requests to Containers, and returns the processing results to the outside world. It receives client connections and receives message packets, which it parses and sends to the container for processing. Different communication protocols, such as HTTP and AJP, correspond to a Connector.
- Protocol: a Protocol abstraction. It includes the entire process of receiving client connections, receiving client messages, parsing packets, and responding to clients. It mainly contains the Endpoint component and Processor component. Upon startup, the Acceptor component inside the Endpoint component starts a listener for a port. When an incoming request is received, it is thrown to the Executor thread pool, which processes the task. The protocol is parsed by the Processor and forwarded to the Engine container for further processing. The Mapper component, the client request routing navigation component, can route a complete request address, that is, it can find the corresponding Servlet through the request address. CoyoteAdaptor component, an adapter that ADAPTS the Connector and Container
- Container: A Servlet Container consisting of multi-layer containers that manage the Servlet lifecycle and invoke servlet-related methods.
Engine
The Host component represents virtual hosts that can hold abstractions of several Web applications.
- AccessLog component: client AccessLog, all client access is logged.
- The Cluster component: It provides clustering capabilities to synchronize data that the Engine container needs to share to other Tomcat instances in the Cluster.
- Pipeline component: The Pipeline that the Engine container processes requests.
- Realm component: Engine container-level user-password-permission data objects for use with the resource authentication module.
Context container is an abstraction of The Web application. When the Web application is deployed to Tomcat and run, it will be transformed into Context object, which contains various static resources, several servlets (Wrapper containers) and various other dynamic resources.
- Loader component: A Web application Loader that encapsulates Java ClassLoader and is used to load class files. It is used to mount the resources of Web applications. It ensures resource isolation between different Web applications.
- Manage component: Session manager for managing sessions for the corresponding Web container, including maintenance session generation, update, and destruction.
- NamingResource component: Named resource that maps the server. XML resources and attributes of the Tomcat configuration file and the Context.xml resources and attributes of the Web application into memory
- Mapper component: Servlet Mapper, which belongs to the route Mapper inside the Context and is only responsible for the route navigation of the Context container
The Wrapper container corresponds to servlets, one Wrapper for each Servlet
- Servlet component: Servlet is the Servlet commonly used in Web application development. We will write the logical processing of the request in the Servlet.
- ServletPool component: Servlet object pool, which is generated in the Wrapper when a Web application’s Servlet implements a SingleThreadModel interface. The ServletPool component ensures that the Servlet object is thread-safe.
- Pipeline component: Wrapper container The Pipeline for processing requests
Class diagram: www.processon.com/view/link/5…
Start stop: www.processon.com/view/link/5…