Tomcat source code analysis-overall container structure, overall tomcat source code container
Tomcat is composed of multiple containers, and the Container and Connecter connector are the two core modules of Tomcat. The Connecter connector receives client requests, then, it passes the request from the client to the Container for processing and responds accordingly.
Tomcat has multiple levels of container objects: Engine, Host, Context, and Wrapper. These containers are hierarchical.
- Engine: The Servlet Engine of Tomcat. It can contain one or more sub-containers.
- Host: indicates a virtual Host that contains multiple Context
- Context: indicates a ServletContext, which contains one or more Wrappers containers.
- Wrappers: indicates an independent Servlet definition. It can be multiple servlets or one servlet instance.
All containers inherit the inerbase abstract class, And the inerbase abstract class implements the Container interface. The Container inherits the Lifecycle interface for unified management of the Container Lifecycle.
The Container interface defines static fields to indicate the event types when a sub-Container is added or removed (for example ):
The following figure shows the class structure of ContainerBase. Due to the limited space, the fields and methods of interfaces and classes are not listed here:
ContainerBase class diagram
1. Lifecycle interface: defines the interface used to control the Lifecycle of all Tomcat components. 2. LifecycleBase abstract class: implements the Lifecycle interface for managing the Lifecycle of all Tomcat components. 3. MBeanRegistration interface: Used to enable Tomcat to support interfaces defined by JMX. 4. LifecycleMBeanBase abstract class: inherits LifecycleBase and implements the MBeanRegistration interface to support JMX. 5. Container interface: it is the interface of all our containers. It defines the common fields of containers and methods. 6. ContainerBase abstract class: The base class of all containers, which implements some sub-container management methods (add, remove, and search ), sub-containers are started to manage container event listening objects, including the management of Loader, Logger, Manager, Realm, and Resources components, and the management of Pipeline and Valve objects.
The following figure shows all Tomcat containers (fields and methods are omitted ):
Container class diagram
This section analyzes each container in Tomcat in detail.
First Article address: Solinx
Http://www.solinx.co/archives/101