Reprinted from The Fall of the column http://blog.csdn.net/quhongwei_zhanqiu/article/details/41577159
One: Proxyfactory's interface definition
Importcom.alibaba.dubbo.common.Constants;ImportCom.alibaba.dubbo.common.URL;Importcom.alibaba.dubbo.common.extension.Adaptive;ImportCom.alibaba.dubbo.rpc.Invoker;Importcom.alibaba.dubbo.rpc.RpcException;/*** @ClassName: Proxyfactory * @Description: *@authorWILLIAM.LIANGF Add by Rayhong * @date 2015-7-5 20:24:58*/@SPI ("Javassist") Public InterfaceProxyfactory {@Adaptive ({Constants.proxy_key})<T> T getproxy (invoker<t> Invoker)throwsrpcexception; @Adaptive ({Constants.proxy_key})<T> invoker<t> Getinvoker (T proxy, class<t> type, url url)throwsrpcexception; }
1. @SPI Specifies that proxy objects are generated by default using Javassist bytecode technology
2. The interface defines the method that generates the proxy object GetProxy, the entry parameter is the Invoker object
3. The interface defines the get Invoker object, Invoker object is an executable object, here the Inovker object's Invoke method actually executes
A call to the entity object of the first entry, based on the method obtained by the URL, that is: If the URL is known to call Method SayHello,
The entry proxy implements test for the empty test object, which Invoker.invoke () is Test.sayhello ()
Abstractproxyfactory: The public abstraction of the Agent factory, where the abstract implementation is mainly to obtain the interface that needs the agent, the proxy interface can be set in the URL key is interfaces,
If multiple interfaces are separated by commas, if not specified in the URL, the proxy invoker gets the and EchoService interfaces
Jdkproxyfactory: Using the JDK dynamic Agent to create the agent, the implementation is relatively simple
JDK Dynamic agent Gets the proxy object
public <T> T getproxy (invoker<t> invoker,class<?>[] interfaces) { return
New Invokerinvocationhandler (Invoker));}
Invokerinvocationhandler is the JDK dynamic agent to create the parameters must be built, here its Invoke method is simply called the Invoker.invoke method,
Invoker represents an executable in Dubbo, and everything moves closer to it.
Get Invoker Object
Import Java.lang.reflect.Method;
Import Com.alibaba.dubbo.common.URL;
Import Com.alibaba.dubbo.rpc.Invoker;
Import Com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker;
public <T> invoker<t> Getinvoker (T proxy, Class<t> return new abstractproxyinvoker<t> PR otected Object Doinvoke (T proxy, String methodName, Class <?>[ ] Parametertypes, object[] arguments) throws Throwable {Method method = Proxy.getclass (). GetMethod (MethodName, par Ametertypes); return Method.invoke (proxy, arguments) ; } }; }
The Invoker object that is created here, executes the Invoke method, is actually the corresponding method that uses the reflection to execute the corresponding object with the parameter.
4. Dubbo principle Analysis-agent Interface definition (GO)