Bridge--coyoteadapter for connectors and containers

Source: Internet
Author: User

If the entire Tomcat kernel is modular in the highest degree of abstraction, it can be seen as a connector connector and the container container, the connector is responsible for HTTP request reception and response, generating the Request object and response object and processed by the container, The container then finds the appropriate servlet for processing according to the request path. Requesting a response object from the connector to the container requires a bridge, which is the protagonist--coyoteadapter discussed in this section.

The structure of this component is very simple, contains only two tool classes, Urlencoder is responsible for the string URL encoding, Stringmanager responsible for the internationalization of the log, the two tools have been described in detail earlier. The function of this component is obviously to act as an adapter to connect the connector to the container. Its main work includes: ① the request and response used to generate connector based on the underlying request and response (using façade mode to implement the data isolation mechanism resulting in the existence of multiple request and response, details of the front " The "chapter of the Request"); ② invokes the container pipeline. It's not as simple as it needs to be discussed, but we need to delve into why this adapter is being introduced.


The first thing you need to know about adapter mode is simply to add an object between two objects so that two objects can be connected correctly. Simplifying Coyoteadapter and taking this as an example,

① defining the Adapter interface

Public interface Adapter {

Public Voidservice (Request req, Response res) throws Exception;

}

② adapter class, which is responsible for invoking the container

public class Coyoteadapter implements Adapter {

public void Service (Request req,response res) throws Exception {

Container.invoke (); Some operator about invoke container

}

}

③ connector, the initialization method uses the adapter and passes adapter as a parameter to the Protocolhandler,protocolhandler as an object, and must be guaranteed to pass in as a parameter adapter.

public class connector{

protected void initinternal () {

Adapter Adapter = new Coyoteadapter ();

Protocolhandler.setadapter (adapter);

}

}

④ the new adapter class, if a new container Newcontainer call method is defined as Newinvoke, simply redefine a new adapter and instantiate a Newadapter object into the Protocolhandler, The adapter is guaranteed to be passed in as a parameter without having to do a lot of other change actions.

public class Newadapter implements Adapter {

public void Service (Request req,response res) throws Exception {

Newcontainer.newinvoke ();

}

}

The call to the container could have been done directly in the connector, but for later expansion and adaptation to other containers, an adapter Coyoteadapter was added, and the introduction of the adapter added to the complexity of the code, but the benefits to it were completely worthwhile.

Bridge--coyoteadapter for connectors and containers

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.