[Tomcat篇1--基础架构]

    xiaoxiao2022-06-25  218

    先挖个坑,后面过来填~!

    BootStrap类

    Connector–连接器

    连接器负责外部交流 连接器处理Socket通信和应用层协议的解析得到Servlet请求 容器负责内部处理 容器负责处理Servlet请求 容器,顾名思义就是用来装载东西的器具,在 Tomcat 里,容器就是用来装载Servlet的。那Tomcat的Servlet容器是如何设计的呢? Tomcat容器层次结构 tomcat设计了4种容器,分别是Engine、Host、Context、Wrapper。这四种容器不是平行关系,而是父子关系。如下图所示。 Tomcat通过一种分层的架构,使得Servlet容器具有很好的灵活性。 Conteext表示一个Web应用程序; Wrapper表示一个Servlet,一个Web应用程序中可能会有多个Servlet; Host代表的是一个虚拟主机,或者说是一个站点,可以给Tomcat配置多个虚拟主机,而一个虚拟主机下可以部署多个web应用程序; Engine表示引擎,用来管理多个虚拟站点,一个Service最多只能有一个Engine。 Server.xml Tomcat采用了组件化的设计,它的构成组件都是可配置的,其中最外层的是Server,其他组建按照一定的格式要求配置在这个顶层容器中。

    <Server port="8005" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> <Listener className="org.apache.catalina.core.JasperListener" /> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> <GlobalNamingResources> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml" /> </GlobalNamingResources> <Service name="Catalina"> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host> </Engine> </Service> </Server>

    1.Connector和Engine是平级关系 2.Tomcat是用组合模式来管理这些容器的。 3.具体方法是:所有容器组建都实现了Container接口,因此组合模式可以使得用户对单容器和组合容器的使用具有一致性。这里单容器对象指的是最底层Wrapper,组合容器对象指的是上面的Context、Host、Engine. 4.Container接口定义: public interface Container **extends Lifecycle** { public void setName(String name); public Container **getParent**(); public void **setParent**(Container container); public void **addChild**(Container child); public void **removeChild**(Container child); public Container **findChild**(String name); } Lifecycle接口用来统一管理各组件的生命周期。

    Server

    Service

    Adaptor

    ProtocalHandler

    SockerServer

    org.apache.catalina.startup.Bootstrap#main

    几篇其他博文

    https://blog.csdn.net/peng5007/article/details/80104091 https://blog.csdn.net/lppl010_/article/details/80476124 https://blog.csdn.net/w1992wishes/article/details/79242797 https://blog.csdn.net/cutesource/article/details/5006062 https://blog.csdn.net/beliefer/article/details/51473807 https://blog.csdn.net/beliefer/article/details/51645799


    最新回复(0)