当前位置:网站首页>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,
边栏推荐
- sql语句之多表查询
- Open Source Database Innovation in the Digital Economy Era | 2022 Open Atom Global Open Source Summit Database Sub-Forum Successfully Held
- STM32 - DMA
- View source and switch mirrors in two ways: npm and nrm
- Minio上传文件ssl证书不受信任
- MySQL database addition, deletion, modification and query (detailed explanation of basic operation commands)
- 剑指offer专项突击版第15天
- Visual studio shortcuts that improve efficiency, summary (updated from time to time)
- unity2d game
- Summary of MySQL common interview questions (recommended collection!!!)
猜你喜欢
Hand in hand to realize the picture preview plug-in (3)
HCIP第十天_BGP路由汇总实验
ERP生产作业控制 金蝶
SOLVED: After accidentally uninstalling pip (two ways to manually install pip)
打造基于ILRuntime热更新的组件化开发
Open Source Database Innovation in the Digital Economy Era | 2022 Open Atom Global Open Source Summit Database Sub-Forum Successfully Held
扫雷小游戏——C语言
DVWA shooting range environment construction
[debug highlights] Expected input batch_size (1) to match target batch_size (0)
PWN ROP
随机推荐
SQL injection of DVWA
WPF WPF 】 【 the depth resolution of the template
visual studio 那些提高效率的快捷键,总结(不时更新)
Lua,ILRuntime, HybridCLR(wolong)/huatuo hot update comparative analysis
The input input box displays the precision of two decimal places
Gaussian distribution and its maximum likelihood estimation
XSS靶场(三)prompt to win
prompt.ml/15中<svg>标签使用解释
简易网络文件拷贝的C实现
重磅 | 基金会为白金、黄金、白银捐赠人授牌
Unity Fighter
WeChat applet uses cloud functions to update and add cloud database nested array elements
CentOS7 —— yum安装mysql
【C语言】操作符详解
mysql使用on duplicate key update批量更新数据
MySQL开窗函数
Sun Wenlong, Secretary General of the Open Atom Open Source Foundation |
MySQL window function
Error EPERM operation not permitted, mkdir 'Dsoftwarenodejsnode_cache_cacach Two solutions
STM32HAL library modifies Hal_Delay to us-level delay