Tomcat Source Analysis (i)

Source: Internet
Author: User

This period of time simply look at the source of Tomcat, here to make a note!

1. Tomcat Frame composition

Catalina: Tomcat's top-level container, in the main () method, creates a Catalina object instance to start or close tomcat;

Server: is a container that manages all components of Tomcat and contains one or more service;

Service: Service is a collection of connector and container, service with appropriate connector to receive the user's request, and then sent to the corresponding container to deal with;

Connector: The main function is ◇socket receive ◇ according to the Protocol type processing Socket◇ package corresponding request and response, to container;

The Container:engine container receives the request from the connector and passes the pipeline in turn to the pipeline of the child container;

engine: In the engine's pipeline, Valve's Invoke method, according to Request.gethost () to locate the next host;

Host: A Web server virtual machine, the management of the specific Web application;

Context: It is the contexts of the specific Web applications that we are subordinate to, and each request is handled in a specific context;

Wrapper: corresponds to each Servlet of the web;

Next, learn about the two most important containers in Tomcat, connector and container containers.

2. Connector container

Connector container mainly solves the problem is the socket receive, in order to be able to handle various protocols and concurrent asynchronous receive, connector added two components Protocolhandler and endpoint.

The main function of Protocolhandler is to encapsulate the request and the response object according to the definition of each protocol according to a certain format sentence analysis protocol header;

Abstractendpoint is committed to high concurrency to solve socket reception and processing;

2.1 Abstractendpoint

Two cooperative runnable in EndPoint:

(1) Accepter is responsible for using serversocket.accept () to receive customer requests, and the establishment of the connection after the socket to poller processing;

(2) Poller is responsible for receiving requests and processing;

protected class extends Implements Runnable)  Public class Implements Runnable

Specific writing of Accepter and Poller (personal humble opinion)

From this, we can find that acceptor receives a user's socket request, encapsulates the socket into a pollerevent, and puts it into the events queue. Poller actually, while (true), when the execution of the events queue has pollerevent, it gets a data channel from its own selector and gives it to the processkey () processing.

2.1 Protocolhandler

Each protocol has its own specific definition, and the specific protocol header format, then I do after receiving the customer request, it should be based on the type of protocol to adopt the corresponding parsing method.

The specific role of Protocolhandler:

Define the specific processing socket abstractendpoint;

Provide the abstractconnectionhandler of the parsing request to obtain the specific protocol header;

The associated init, start, stop methods

"References"

[1] http://blog.csdn.net/cutesource/article/details/5006062

[2] http://blog.csdn.net/yanlinwang/article/details/45648039

Tomcat Source Analysis (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.