Spark Netty and jetty (source read 11)

Source: Internet
Author: User

Spark, to the Netty API another layer of encapsulation , then Netty is what it is a ghost. It is based on the NIO Server client framework, which is no longer the case, starting with the following.

A thread factory is created, and the generated thread is given a prefix name.

  

Like the general Netty Framework, create a Netty eventloopgroup:

  

In a common Netty framework, you create a client-side helper class that sets Socketchannel:

  Bootstrap B = new Bootstrap ();  B.group (Group). Channel (Niosocketchannel.class)

What about spark? According to the parameter IOMode, return the correct client Socketchannel:

Return the correct service-side socketchannel:

  

Return to the far end of the channel address:

  

Creates a bytebuf allocator that is disabled for the local thread cache . Bytebuf is allocated by the event loop thread , so the thread-local cache is disabled for Transportclient , Bytebuf release is done by the executor thread, not the event loop thread. Local thread caches often delay bytebuf recycling, resulting in significant memory consumption.

  

Spark, the Beast, also encapsulates the jetty, what is jetty? It is a servlet container with Java as the development language, and its API is published as a set of jar packages, providing network and Web services . In my understanding, Netty is to use Socket~jetty it is http~ so down, we look at Jettyutils:

  

Createservlet, generates an HttpServlet anonymous inner class , which is implicitly converted to a function parameter passed into the user by the responder type.

To create a servlet for jetty, it involves the use of Servletcontexthandler APIs, generating Servletcontexthandler:

  

Creates a response processing for a request prefixed by a given path, adding all handler in Sparkui to contexthandlercollection. If you use configuration spark.ui.filters Filter is specified, the filter is added to all handler. Then call Startserviceonport, the final callback function connect:

  

Spark Netty and jetty (source read 11)

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.