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)