Spring Proxy mode service Remote call, plug-in execution

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.