Tomcat 总体结构分析

1. 总体概念

tomcat作用可以简单概括成:通过接收到的请求寻找到对应的servlet。


tomcat把功能的实现分解成两个大块:connector和container。

connectors:负责请求的接收并转发给container

container:管理整个项目。具体对请求处理是丢给了Valve。


2. 主要接口

与server.xml中的配置相关

  • Server/Service:
Server: 最高级别的抽象。
Service:共享同一container的一个或一组connectors的一个抽象。

  • Engine/Host/Context/Wrapper(与Server/Service区分开,是因为它们继承了Container接口,能够接收并处理请求)
Engine: 代表整个Catalina servlet的引擎,具体用处如下

  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. 

Host:代表虚拟主机,具体用处如下:

  It is useful in the following types of scenarios:

You wish to use Interceptors that see every single request processedby this particular virtual host.

You wish to run Catalina in with a standalone HTTP connector, but still want support for multiple virtual hosts. 

Context:代表servlet context。
It provides a convenient mechanism to use Interceptors that see every request processed by this particular web application.
Wrapper:对servet的包装。
It provides a convenient mechanism to use Interceptors that see every single request to the servlet represented by this definition.

  • Connector
Connector:主要负责接收请求,并将请求转发给Container来处理

  • Valve
Valve: 对应请求处理的最小单元,每个container对应一个或者多个Valve,由pipeline来管理。不同的pipeline串联采用了责任链模式。


其他重要接口
  • ServletRequest/ServletResponse
ServletRequest:代表请求
ServletResponse:代表返回结果

  • Container
Container: 一种处理请求的容器

  • Lifecycle
Lifecycle:用来管理整个项目的生命周期。同时还负责注册对生命周期的监听(监听者模式)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值