Undertow Anatomy of a servlet container with a graphical WildFly8

Source: Internet
Author: User
Tags jboss

Undertow Introduction

Undertow is an open source product of Redhat (Red Hat), with a flexible, high-performance WEB server developed in Java, that includes blocking and NIO-based non-clogging mechanisms.

The default servlet container for WildFly8 is not Tomcat, nor jetty, but JBoss's own open source Undertow,undertow is a flexible servlet container written in Java. The low-level, high-performance NIO framework Xnio,xnio is also a JBoss open source product, and the JBoss Open source High performance NIO framework has a very famous: Netty. the role of Undertow in WildFly8


The architecture of the undertow is similar to the jetty, which is embedded in the application, which is why it has flexible performance reasons, using Undertow can quickly build a small application service, the implementation code is as follows:

Import Io.undertow.handlers;import Io.undertow.undertow;import Io.undertow.server.httphandler;import Io.undertow.server.handlers.pathhandler;import Io.undertow.servlet.servlets;import Io.undertow.servlet.api.deploymentinfo;import Io.undertow.servlet.api.deploymentmanager;import    Io.undertow.servlet.api.servletcontainer;import Io.undertow.servlet.api.servletinfo;public class WildFlyServer { public static void Main (final string[] args) throws Exception {//Create Servletinfo, First name "Myservlet" must be unique S        Ervletinfo Servlet1 = Servlets.servlet ("Myservlet", Myservlet.class);        Sets the data servlet1.addinitparam ("message", "Hello World") required to execute the servlet's Init method;                The binding map is/hello servlet1.addmapping ("/hello");         Create the name Messageservlet for the servletinfo servletinfo Servlet2 = Servlets.servlet ("Messageservlet", Messageservlet.class);        Servlet2.addinitparam ("message", "Myservlet");      The binding map is/myservlet servlet2.addmapping ("/qrcode");          Create Deploymentinfo Application Deployment Deploymentinfo deployment = Servlets.deployment ();        Designation ClassLoader Deployment.setclassloader (WildFlyServer.class.getClassLoader ());        The application context (must be consistent with the mapping path, otherwise SessionID will have problems, new each time) Deployment.setcontextpath ("/myapp");        Set the deployment package name Deployment.setdeploymentname ("Test.war");        Add Servletinfo deployment.addservlets (Servlet1,servlet2);        Create DeploymentInfo2 application Deployment Deploymentinfo Deployment2 = Servlets.deployment ();        Deployment2.setclassloader (WildFlyServer.class.getClassLoader ());        Deployment2.setcontextpath ("/myapp2");        Deployment2.setdeploymentname ("Test2.war");                Deployment2.addservlets (Servlet1,servlet2);        Use the default Servlet container and add the deployment to the container servletcontainer container = Servlets.defaultcontainer ();        Add the deployment to the container, generate the layout corresponding manager Deploymentmanager manager = container.adddeployment (deployment); Deploymentmanager Manager2 = Container.adddeploymenT (Deployment2);        Implementation of the deployment of the Manager.deploy ();                Manager2.deploy ();        Generate Path Processor (dispatch servlet), default return "/*" Processor Pathhandler path = Handlers.path ();                Generate path processor, return "/*" Automatically redirect to "/myapp" processor//Pathhandler path = Handlers.path (Handlers.redirect ("/myapp"));        Start the container, generate the request processor HttpHandler MyApp = Manager.start ();        HttpHandler myapp2 = Manager2.start ();        Binding mapping Relationship Path.addprefixpath ("/myapp", MyApp);                Path.addprefixpath ("/myapp2", MYAPP2);                Undertow Server = Undertow.builder ()//Bind port with host. Addhttplistener (8080, "localhost")        Set the distribution processor Pathhandler. SetHandler (Path). build ();            Start Server Server.start (); }}

from the source code, we can abstract out the architecture of the Undertow build application,


Using Run-through debugging, we can gain a deeper understanding of some of the concepts in Undertow:
servletinfo: The smallest unit of the servlet, which is the re-encapsulation of the specific implementation of the Javax.servlet.Servlet

FilterInfo: Filter Package
deploymentinfo: Package Deployment Object containing multiple servletinfo, which can be said to be a collection of servletinfo
servletcontainer: Container for managing Deploymentinfo, one container can add multiple Deploymentinfo
Deploymentmanager: Management of the package deployment is a reference to the Deploymentinfo added to Servletcontainer for running the publishing and launching containers
HttpHandler: servlet path processor, Deploymentmanager the servlet processor returned after startup, usually Httpcontinuereadhandler (continuous read processor)
Pathhandler: A dispatcher that distributes user requests to the corresponding HttpHandler
httpserverexchange: Data interchange encapsulation, can be converted into servletrequest and servletresponse
The debug run stack for the sample code is as follows:


Connecting channels


The structure of the entity Httpserverexchange that is converted as a Servlet protocol protocol is as follows:


Performance of Undertow

The data for the professional assessment results are as follows:


Undertow Anatomy of a servlet container with a graphical WildFly8

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.