是一个开源的servlet窗器,它为基于java的web内容,例如jsp和servlet提供运行环境。是使用JAVA编写的。
Jetty在servlet容器中算不上一个新面孔;它从1998年就已经崭露头角。Jetty的发布遵循了Apache 2.0的开源协议,你可以在免费软件和商业软件中使用Jetty而不用支付版税。
1. Java的服务器端架构V2:linux+jetty+hessian+spring+struts+servlet;
涉及到问题,调用.net服务器,客户端的构建,这是一个多余的工作量。(题外话)
本研究的jetty7.3.1版本。
整体上感觉,整个架构比较简单,极急读懂(继承不超三层)。但是感觉代码还是相当粗糙,推荐还是读读tomcat.小提示一下,研究tomcat时,先研究一下tomcat4.*的版本,再研究一下tomcat6.*的版本,你的就会有历史的眼光分析源码。本人tomcat的研究总结文档,请参阅。
谁的大工程不是这样,从DEMO到0.9,再改版到改版。
A. Jetty架构图
http://docs.codehaus.org/display/JETTY/Architecture
http://docs.codehaus.org/display/JETTY/Jetty+Documentation
B. 精要分析
服务器端组成
The Jetty Server is the plumbing between a collection of Connectors that accept HTTP connections, and a collection of Handlers that service requests from the connections and produce responses, with the work being done by threads taken from a thread pool.
连接器代表协议处理器,用于接收连接,解析请求及生成响应等,不同连接器类型根据不同的协议、调度模型及IO API 分类如下:
- SocketConnector - for few busy connections or when NIO is not available.
- BlockingChannelConnector - for few busy connections when NIO is available
- SelectChannelConnector - for many mostly idle connections or asynchronous handling of Ajax requests.
- SslSocketConnector - SSL without NIO
- SslSelectChannelConnector - SSL with non blocking NIO support.
- AJPConnector AJP protocol support for connections from apache mod_jk or mod_proxy_ajp
处理器是处理接受的请求的组件,处理器的核心方法如下:
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch)
throws IOException, ServletException;
实现这个方法可能是对请求的处理,传输请求到另外一个处理器,也可能是修改或者包装请求再传递下去。可以总结为三种风格的处理器:
- Coordinating Handlers - Handlers that route requests to other handlers (eg HandlerCollection, ContextHandlerCollection)(协调处理器)
- Filtering Handlers - Handlers that augment a request and pass it on to other handlers (eg. HandlerWrapper, ContextHandler, SessionHandler)(过滤包装处理器)
- Generating Handlers - Handlers that produce content (eg ResourceHandler and ServletHandler)(生成处理器??[TODO])