1.tomcat顶层结构

tomcat的结构可以从server.xml看出来。

 

一个server

--》包含多个service

--》每个service包含多个connector(处理连接,socket与request、response的转换),一个container(封装servlet)

183154_fJvW_2773342.png

 

container分解如下:

一个Engine

--》包含多个host

--》每个host包含多个context(context只web应用)

--》每个context包含多个wrapper(wrapper是真正包装servlet的container)

183435_xbtz_2773342.png

 

以下接口均在org.apache.catalina包中

1.server

Server element represents the entire Catalina servlet container. Its attributes represent the characteristics of the servlet container as a whole. A Server may contain one or more Services, and the top level set of naming resources.

Normally, an implementation of this interface will also implement Lifecycle, such that when the start() and stop() methods are called, all of the defined Services are also started or stopped.

In between, the implementation must open a server socket on the port number specified by the port property. When a connection is accepted, the first line is read and compared with the specified shutdown command. If the command matches, shutdown of the server is initiated.

NOTE - The concrete implementation of this class should register the (singleton) instance with the ServerFactory class in its constructor(s).

 

1.1.一个server是全局容器,因此是唯一的,他可以包含多个service,以及一些资源。

    server.xml中naming resources配置

    <!-- Global JNDI resources

       Documentation at /docs/jndi-resources-howto.html

  -->

  <GlobalNamingResources>

    <!-- Editable user database that can also be used by

         UserDatabaseRealm to authenticate users

    -->

    <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>

1.2.这个接口继承Lifecycle,实现这个接口同时要实现生命周期,start和stop方法用来启动关闭services。

1.3.为server指定一个端口,用于shutdown

server.xml中

<Server port="8005" shutdown="SHUTDOWN">

 

2.service

Service is a group of one or more Connectors that share a single Container to process their incoming requests. This arrangement allows, for example, a non-SSL and SSL connector to share the same population of web apps.

A given JVM can contain any number of Service instances; however, they are completely independent of each other and share only the basic JVM facilities and classes on the system class path.

 

2.1.service处理请求,多个connector共享一个container,这使得非SSL或者SSL能共享相同的web应用。

2.2在JVM中,services是多个实例,相互独立

2.3同样要实现Lifecycle,因此connector和container的初始化启动关闭由service完成。

2.4service中啊还有线程池

 

3.container

Container is an object that can execute requests received from a client, and return responses based on those requests. A Container may optionally support a pipeline of Valves that process the request in an order configured at runtime, by implementing the Pipeline interface as well.

Containers will exist at several conceptual levels within Catalina. The following examples represent common cases:

  • Engine - Representation of the entire Catalina servlet engine, most likely containing one or more subcontainers that are either Host or Context implementations, or other custom groups.
  • Host - Representation of a virtual host containing a number of Contexts.
  • Context - Representation of a single ServletContext, which will typically contain one or more Wrappers for the supported servlets.
  • Wrapper - Representation of an individual servlet definition (which may support multiple servlet instances if the servlet itself implements SingleThreadModel).

A given deployment of Catalina need not include Containers at all of the levels described above. For example, an administration application embedded within a network device (such as a router) might only contain a single Context and a few Wrappers, or even a single Wrapper if the application is relatively small. Therefore, Container implementations need to be designed so that they will operate correctly in the absence of parent Containers in a given deployment.

A Container may also be associated with a number of support components that provide functionality which might be shared (by attaching it to a parent Container) or individually customized. The following support components are currently recognized:

  • Loader - Class loader to use for integrating new Java classes for this Container into the JVM in which Catalina is running.
  • Logger - Implementation of the log() method signatures of the ServletContext interface.
  • Manager - Manager for the pool of Sessions associated with this Container.
  • Realm - Read-only interface to a security domain, for authenticating user identities and their corresponding roles.
  • Resources - JNDI directory context enabling access to static resources, enabling custom linkages to existing server components when Catalina is embedded in a larger server. 

 

3.1engine,host,context,wrapper都继承container,因此都是container

3.2engine用来管理host,一个service只能由一个engine

    一个engine包含多个host,一个host包含多个context,一个context包含多个wrapper

3.3host,主机吧

3.4context,代表一个web应用

3.5wrapper,封装servlet

3.6container都要实现Lifecycle

 

4.engine

An Engine is a Container that represents the entire Catalina servlet engine. It is useful in the following types of scenarios:

  • You wish to use Interceptors that see every single request processed by the entire engine.
  • You wish to run Catalina in with a standalone HTTP connector, but still want support for multiple virtual hosts.

In general, you would not use an Engine when deploying Catalina connected to a web server (such as Apache), because the Connector will have utilized the web server's facilities to determine which Context (or perhaps even which Wrapper) should be utilized to process this request.

The child containers attached to an Engine are generally implementations of Host (representing a virtual host) or Context (representing individual an individual servlet context), depending upon the Engine implementation.

If used, an Engine is always the top level Container in a Catalina hierarchy. Therefore, the implementation's setParent() method should throw IllegalArgumentException.

 

4.1.engine的子容器通常是host或者context,取决于engine实现。??好吧,既然作者这么说,我也没什么反驳的,但是应用过程中,context应该是host的子容器呀。

 

4.2.engine是顶层容器,setParent() 要抛异常。

 

5.host

Host is a Container that represents a virtual host in the Catalina servlet engine. It is useful in the following types of scenarios:

  • You wish to use Interceptors that see every single request processed by this particular virtual host.
  • You wish to run Catalina in with a standalone HTTP connector, but still want support for multiple virtual hosts.

In general, you would not use a Host when deploying Catalina connected to a web server (such as Apache), because the Connector will have utilized the web server's facilities to determine which Context (or perhaps even which Wrapper) should be utilized to process this request.

The parent Container attached to a Host is generally an Engine, but may be some other implementation, or may be omitted if it is not necessary.

The child containers attached to a Host are generally implementations of Context (representing an individual servlet context).

 

5.1父容器可能是engine,也可能是其他的实现,也可能被忽略???

 

5.2子容器是context

 

6.context

Context is a Container that represents a servlet context, and therefore an individual web application, in the Catalina servlet engine. It is therefore useful in almost every deployment of Catalina (even if a Connector attached to a web server (such as Apache) uses the web server's facilities to identify the appropriate Wrapper to handle this request. It also provides a convenient mechanism to use Interceptors that see every request processed by this particular web application.

The parent Container attached to a Context is generally a Host, but may be some other implementation, or may be omitted if it is not necessary.

The child containers attached to a Context are generally implementations of Wrapper (representing individual servlet definitions).

 

6.1.context代表servlet上下文,确定哪个wrapper来处理请求

 

7.wrapper

Wrapper is a Container that represents an individual servlet definition from the deployment descriptor of the web application. It provides a convenient mechanism to use Interceptors that see every single request to the servlet represented by this definition.

Implementations of Wrapper are responsible for managing the servlet life cycle for their underlying servlet class, including calling init() and destroy() at appropriate times, as well as respecting the existence of the SingleThreadModel declaration on the servlet class itself.

The parent Container attached to a Wrapper will generally be an implementation of Context, representing the servlet context (and therefore the web application) within which this servlet executes.

Child Containers are not allowed on Wrapper implementations, so the addChild() method should throw an IllegalArgumentException.

 

7.1.wrapper的实现需要管理servlet的生命周期,包括init() and destroy(),同时也要考虑servlet是否声明单线程模式。

7.2.wrapper没有子容器,addChild()抛异常

转载于:https://my.oschina.net/hellojavaweb/blog/693621

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值