tomcat 7 源码分析-14 tomcat的container设计

                 实现
container←-----containerBase
    ↑                          ↑
    |继承                    |继承
    |                          |
    |         实现           |
Engine←-----—-- StandardEngine
context               Standardcontext
host                    Standardhost
wrapper              Standardwrapper

 

四种container分别是Engine,context,host和wrapper。

containerBase是对container相同部分的实现,四个interface又继承了container,增加了不同的部分。

如此StandardEngine,Standardcontext,Standardhost和Standardwrapper继承了相同的部分,同时实现了差异性的部分。

 

Engine:An Engine is a Container that represents the entire Catalina servlet engine.

 

Host:A Host is a Container that represents a virtual host in the Catalina servlet engine.

 

Context:A Context is a Container that represents a servlet context, and therefore an individual web application, in the Catalina servlet engine.

 

Wrapper: A Wrapper is a Container that represents an individual servlet definition from the deployment descriptor of the web application.

 

补充:写了一个简单的servlet,然后跟踪下发现如下

Engine=StandardEngine[Catalina]

host=StandardEngine[Catalina].StandardHost[localhost]
context=StandardEngine[Catalina].StandardHost[localhost].StandardContext[/WelcomeServlet]
wrapper=StandardEngine[Catalina].StandardHost[localhost].StandardContext[/WelcomeServlet].StandardWrapper[com.hotnosh.ServletTest.FirstServlet]

 

可以看出:

host实际是虚拟主机

context是webapplication,发布的web应用的根目录名

wrapper是具体处理servlet的

如此我在浏览器上输入http://localhost:8080/WelcomeServlet/FisrtServlet

 

 

GET /WelcomeServlet/FisrtServlet HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
ThreadID: 4936
Accept-Language: zh-cn
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SE 2.X; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; SE 2.X)
Host: localhost:8080
Connection: Keep-Alive

 

 

向tomcat发出http的request,tomcat解析请求后,一步步直到具体的servlet处理函数。

调用栈:

Http11Processor.process(SocketWrapper<Socket> socketWrapper)

adapter.service(request, response);

connector.getService().getContainer().getPipeline().getFirst().invoke(request, response);

//调用StandardEngine的StandardEngineValve.invoke

host.getPipeline().getFirst().invoke(request, response);

//调用StandardHost的StandardHostValve.invoke

context.getPipeline().getFirst().invoke(request, response);

//调用Standardcontext的StandardcontextValve.invoke

wrapper.getPipeline().getFirst().invoke(request, response);

//调用StandardWrapper的StandardWrapperValve.invoke

Http11Processor.process(SocketWrapper<Socket> socketWrapper)

adapter.service(request, response);

connector.getService().getContainer().getPipeline().getFirst().invoke(request, response);

//调用StandardEngine的StandardEngineValve.invoke

host.getPipeline().getFirst().invoke(request, response);

//调用StandardHost的StandardHostValve.invoke

context.getPipeline().getFirst().invoke(request, response);

//调用Standardcontext的StandardcontextValve.invoke

wrapper.getPipeline().getFirst().invoke(request, response);

//调用StandardWrapper的StandardWrapperValve.invoke
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值