The previous article introduced the client structure of elasticsearch, the client is just a façade, there is an action behind each method to undertake the corresponding Function. But action is not really a function of the implementation, it is just a proxy, its true implementation is transportaction. this article makes a simple analysis of action and Transportaction implementation,
Most of the operations in Elasticsearch are through the corresponding action, which is in the action Package. Its structure is as follows:
Is the part of the action package, where the action of each function is Faced. The packages for each action are also very similar to Index. The implementations of these actions are very similar, all of which are based on the action, which is the inheritance relationship of Indexaction:
Because these actions do not really implement the corresponding functions, just a proxy, so the implementation is also very simple. Their main function is to provide new response and request methods and corresponding action Names. Also take Indexaction as an example, its method diagram is as Follows:
You can see that it just provides two new response and request methods, and a Word name field that will be used in subsequent action Calls. Each action corresponding to the function implementation is in the corresponding Transportaction.
These tansportaction are based on the transportaction interface. When the client invokes the related interface of the clients, the customer sends the request to Transportaction's Execute. Each function of the transportaction implementation of the Doexecute method, the logic of the function is implemented in this method, the first is not mentioned here, the following functional analysis will see the corresponding Implementation.
There is a piece of code in the client analysis:
transportaction<request, response> transportaction = actions.get ((clientaction) Action) Its role is to obtain transportaction according to the Action. Because the action is just an Agent. These associations are implemented in actionmodule, and the code is as Follows:
Registeraction (nodesinfoaction.instance, Transportnodesinfoaction.class); Registeraction (nodesstatsaction.instance, Transportnodesstatsaction.class); Registeraction (nodesshutdownaction.instance, Transportnodesshutdownaction.class); Registeraction (nodesrestartaction.instance, Transportnodesrestartaction.class); Registeraction (nodeshotthreadsaction.instance, Transportnodeshotthreadsaction.class); Registeraction (clusterstatsaction.instance, Transportclusterstatsaction.class); Registeraction (clusterstateaction.instance, Transportclusterstateaction.class); Registeraction (clusterhealthaction.instance, Transportclusterhealthaction.class)
This is only a small part, and you can see that the corresponding action and transportaction are bound in the Module. This way, when the client needs to receive the request, the corresponding Tansportaction instances are found based on the action instance, and the final request is processed below Them.
Summary: here is a simple analysis of action and Transportaction. As part of Elasticsearch's external Java client, The action action is to receive the corresponding request in the appropriate method of the client and forward it to the corresponding transportaction for processing. The proxy mode is used again, and decoupling is injected via guice.
Elasticsearch Java Client Action Brief