Recently, the process of remote call of platform was studied, and the principle of service layer plug-in execution was recorded.
1. Remote Service Call procedure
First look at the inheritance structure of the class
Encapsulation Call handling Process
Encapsulating the Service invocation interface
Encapsulating Service Request Information
Encapsulation Request Information Processing class
Describe a calling procedure first:
The platform gets the service in the controller by means of lookup (that is, the proxy object of the Bean object that uses spring to find the service), and the remote service is configured in the configuration file, so in lookup, If there is a service in the configuration file, when the proxy object is returned, Invocationhandler is actually a subclass Remoteinvocationhandler, if it is a local service, That Invocationhandler is actually a subclass of Localinvocationhandler.
When the service executes the related method, it calls the Abstractinvocationhandler invoke method, what does this method do? This method encapsulates the Servicerequest object, if the remote service is actually remoteservicerequest, the local service is Localservicerequest object, Then call Serviceinvoker's Invokeservice method, and the argument is the Servicerequest object.
What does the Serviceinvoker Invokeservice method do? This method calls Abstractservicerequesthandler's Handlereuqest method, with the parameter Servicerequest object. Depending on whether the Servicerequest object is a remote request, if the Abstractservicerequesthandler instance is actually pointing to the Remoteservicerequesthandler object.
2. Service layer plug-in execution
This is actually in the above described in the Abstractservicerequesthandler Handlereuqest method, find the method before the execution of the plug-in, the method after the execution of the plug-in, are executed once. A plug-in is some logical processing to be done before and after the service method executes.
Finally cleared up the idea, record.
Spring Proxy mode service Remote call, plug-in execution