ElasticSearch 源码分析技巧

2019-07-13  本文已影响0人  秦汉邮侠

技巧

建立索引流程

//client的入口,明确知道是要创建索引
    @Override
    public void index(final IndexRequest request, final ActionListener<IndexResponse> listener) {
        execute(IndexAction.INSTANCE, request, listener);
    }
//NodeClient继承AbstractClient,完成action到transportAction的转换,NodeClient维护了一个map
//map的映射关系在ActionModule#setupActions中
    public <    Request extends ActionRequest,
                Response extends ActionResponse
            > Task executeLocally(GenericAction<Request, Response> action, Request request, ActionListener<Response> listener) {
        return transportAction(action).execute(request, listener);
    }

TransportAction#execute:72

//该实例是TransportIndexAction
 public final Task execute(Request request, ActionListener<Response> listener) {

        Task task = taskManager.register("transport", actionName, request);
        if (task == null) {
            execute(null, request, listener);
        } else {
            execute(task, request, new ActionListener<Response>() {
               ...
            });
        }
        return task;
    }

* TransportAction类结构

image.png
上一篇下一篇

猜你喜欢

热点阅读