当前位置:网站首页>ES source code API call link source code analysis
ES source code API call link source code analysis
2022-07-31 04:55:00 【spirit of water】
Regarding the API call link, let's start with the familiar three-tier MVC architecture.Those who are doing development are more familiar with spring springMVC. The routine we are familiar with is that the request goes to the controller layer first, then the controller calls the service layer, and then the result is returned.Usually, we also have tomcat as a server to receive requests, and the received requests call the controller layer.A user's request, such as an http request, usually goes to the tomcat service first, and then calls the program's controller.
Then look at how es play, es does not use spring spingMVC, only Guice is used for container management, es does not choose to use a server similar to tomcat to receive requests, but chooses netty to implement the server,Complete the receiving and sending of requests.This corresponds to the RestController in the figure below. This layer has the same function as tomcat.The BaseRestHandler in the figure below can actually be understood as selecting a controller router, which selects a controller according to the url path in the request.The RestSearchAction in the third step in the figure below is the controller layer in the MVC that we understood before. Different functions are placed in different RestActions. In fact, some logic is also placed here.The NodeClient layer actually has a taste of service, and it is where the logic is really executed.Unlike traditional services, es is a natural distributed application.
Netty4HttpServerTransport.dispatchRequest()
RestController.dispatchRequest().tryAllHandlers()
RestController.dispatchRequest() calls wrappedHandler.handleRequest() in the method
BaseRestHandler.handleRequest() Then call the prepareRequest() method in the method. At this point, a specific action will actually be selected according to the request.prepareRequest() is actually an interface. You can see the implementation class below. The red box is just a case (this is an Action corresponding to deleting an index). In prepareRequest, the rest request is converted into a request recognized by es.

Analyze with a case (RestDeleteIndexAction)
Then see:
@Overridepublic RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(Strings.splitStringByCommaToArray(request.param("index"))); deleteIndexRequest.timeout(request.paramAsTime("timeout", deleteIndexRequest.timeout())); deleteIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", deleteIndexRequest.masterNodeTimeout())); deleteIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, deleteIndexRequest.indicesOptions())); return channel -> client.admin().indices().delete(deleteIndexRequest, new RestToXContentListener<>(channel));}Follow the delete in the fifth step and go down to ElasticsearchClient.execute(), which is another interface, and then follow its implementation class, come to AbstractClient.execute(), and call doExecute(), this is an abstract method, its implementation class NodeClient.doExecute(), calls executeLocally() in the method, this method will call transportAction(action).execute(), you can see that the action is executed!
Continue to step 6, click in transportAction(action).execute() and come to TransportAction.execute() In this class, continue to click execute(), which calls requestFilterChain.proceed(), inGo down to proceed() and call this.action.doExecute(task, request, listener), this doExecute() is a method in the TransportAction class, and this class is an abstract class, so look at it according to doExecuteImplementation class, different functions correspond to different actions, or take the example of deleting the index,

边栏推荐
猜你喜欢

centos7安装mysql5.7

从零开始,一镜到底,纯净系统搭建除草机(Grasscutter)

prompt.ml/15中<svg>标签使用解释

MySQL常见面试题汇总(建议收藏!!!)

ERP Production Operation Control Kingdee

sql statement - how to query data in another table based on the data in one table

CentOS7 安装MySQL 图文详细教程

Puzzle Game Level Design: Reverse Method--Explaining Puzzle Game Level Design

Unity手机游戏性能优化系列:针对CPU端的性能调优

Lua,ILRuntime, HybridCLR(wolong)/huatuo hot update comparative analysis
随机推荐
ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)解决办法
ERP生产作业控制 金蝶
DVWA installation tutorial (understand what you don't understand · in detail)
ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)
Open Source Smart Future | 2022 OpenAtom Global Open Source Summit OpenAtom openEuler sub-forum was successfully held
mysql数据库安装(详细)
30 Years of Open Source Community | 2022 Open Atom Global Open Source Summit 30 Years of Open Source Community Special Event Held Successfully
Unity打灵狐者
重磅 | 基金会为白金、黄金、白银捐赠人授牌
Error EPERM operation not permitted, mkdir 'Dsoftwarenodejsnode_cache_cacach Two solutions
[py script] batch binarization processing images
Two address pools r2 are responsible for managing the address pool r1 is responsible for managing dhcp relays
The idea project obviously has dependencies, but the file is not displayed, Cannot resolve symbol 'XXX'
ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
Industry-university-research application to build an open source talent ecosystem | 2022 Open Atom Global Open Source Summit Education Sub-Forum was successfully held
【R语言】【3】apply,tapply,lapply,sapply,mapply与par函数相关参数
【wpf】wpf中的那些模板之深度解析
MySQL常见面试题汇总(建议收藏!!!)
HCIP第十天_BGP路由汇总实验
Go language study notes - dealing with timeout problems - Context usage | Go language from scratch