Tomcat principle series of six: to explain how to encapsulate socket request (on)

table of Contents

@ (Explanation of how to package socket request)

Although we can not see the source code immediately improve your level. But make you a better understanding of programming.

Because we are multi-tomcat NIO to process the request form, so this series is telling the treatment related components NIO type of request.

Prior to explain the process, understanding the concepts is critical .

Participants

tomcat in Connector is responsible for processing the request.

Protocol processing ProtocolHandler

Connector using ProtocolHandler processor to process the request. Different ProtocolHandler represent different connection types.

The processor may be considered ProtocolHandler protocol processing co-ordinator , the requested processing is achieved by other work management component. ProtocolHandler contains three important components:

  • Endpoint: responsible for receiving, processing network socket connection

  • Processor: Endpoint responsible for receiving from the socket connection request encapsulated into protocol type

  • Adapter: is responsible for the encapsulated Container Request to be processed.

Socket package

  • NioChannel: SocketChannel basis wrapper class, use EndPonit in.

  • SocketWrapper: socket wrapper class for carrying (NioChannel) socket delivery.

Difference: NioChannel is the basic package, SocketWrapper further packaging NioChannel of.

Multiple buffer

  • Socket input stream the InputStream : io belonging to the jdk package. Serving as operating system reads bytes from the underlying channel socket
  • SokcetBuffer namely ByteBuffer. Java.nio located under the package, NIO-level buffer. Tomcat default when you create such a size 8 when Buffer * 1024, which is 8K
  • InputBuffer Interface (internal buffer) : Under coyote packet, the Tomcat Request for internal buffer. A socket input buffer means, i.e. to provide a buffer byte stream mode read from the socket. By looking at the source code I feel he is a tool interface, more biased in favor of a toolbar such as: implementation class Http11InputBuffer, with a request to provide analytical head and escaping.
  • InputBuffer categories : connector under clad. Request Servlet specification for the internal buffer
  • MessageBytes message bytes : tomcat after receiving socket incoming bytes and not transcoding immediately, but keep the byte [] array, and then convert the place used. It MessageBytes byte [] abstraction
  • Sub-block section of the operating tool ByteChunk : First, he is a tool, a tool buffer operation. Second, there are two internal interfaces: ByteInputChannel ByteOutputChannel and write data. There is also a convenient target Chartset coding. So he offers is a coding function, caching tool operations.

Two pairs of request, response

There are two sets request, respone tomcat in

  • : Under org.apache.coyote packet
    belonging to a defined internal Tomcat open request, final type class does developer. The main function is to resolve the header content package socket http protocol.
  • : Under org.apache.catalina.connector packet
    belonging to the implementation specification of servlet. We also developed a common request object.

So there will be a tomcat process involves the conversion request and the request, these processes are put follow-speak, this post will explain the concept of assembly.

Tomcat uses Apache Coyote library to handle network I / O's. Connector for Multi Serlvet package specification.

Multiple processors

Tomcat named are a lot of internal processor. Here to talk about talk about the difference mention a few:

  • ProtocolHandler Processor: co-ordination or management-level processor. Connector to request processing work to the ProtocolHandler to deal with. The rest is ProtocolHandler co-ordination. This shows that he is a management processor sector
  • ConnectionHandler: connect the processor, internal maintenance Processor for reuse SocketProcessor the map to create Processor ProtocolHandler work to do...

    SocketProcessor processor invokes ConnectionHandler.process () The incoming request content socket Processor.process () processing.

    Thus ConnectionHandler with a connecting role.
  • SocketBufferHandler: socketBuffer processor. It comprises two SocketBuffer, for buffering read and write socket.
  • SocketProcessor: socket processor for socket processors. Itself is a worker, the socket processing content to the Processor
  • (Processor) Http11Processor: HTTP protocol 1.1 is the most current version of an HTTP protocol. Since then, the name of the processor, we can also see that he is treated for this agreement. This processor is a key component of the socket into the request, he will parse the content of the HTTP protocol from the socket out, but in the tomcat, he is only responsible for the http request line, request to resolve header; resolution request to delay the body of the servlet to resolve the . Http11Processor created by ConnectionHandler, tomcat key classes implement reuse to reduce the overhead of frequent creation and destruction, will pop out in recycledProcessors

to sum up

Mastered these concepts related components after. Under chapter explains how to become a socket request.

Guess you like

Origin www.cnblogs.com/smallstudent/p/11512798.html