Figure proxy mode
Only dealers beginning, no agents, users can find a dealer that is directly Producer to purchase products
Dynamic agent, as used with the bytecode used, with a loading who
reinforcing the foundation is not modify the source code to source code
classification: the first type based on the second type of dynamic agent interface based on dynamic proxy subclass
Dynamic proxy interface of
the class involved: Proxy
Provider: JDK official
if you create a proxy object;
using the methods of the Proxy class newProxyInstance
Creating a proxy object request by the proxy class implements an interface least, if not not use
parameters newProxyInstance method:
ClassLoader class loader for loading loads byte code written proxy object proxy object is fixed wording
对象.geClass().getClassLoader();
Class []: bytecode array, and a proxy object with a proxy object in the same manner, the fixed wording
对象.geClass().getInterfaces();
InvocationHandler provide enhanced code, let's write how agents, generally the interface implementation class, are usually anonymous inner classes
There is only one way to invoke, the role of the proxy object executes any interface method goes through the process
method Definition
Object proxy proxy object reference
method Method method currently performed
Object [] args current required method parameters
return and the agent the method returns the object has the same value
Acting successful, the amount of money returned after treatment
but the above methods, the proxy class must implement an interface
there a method to make a normal class has agents
cglib
based dynamic proxy subclass of
class Enhancer involved
providers cglib third-party libraries
how to create a proxy object: Enhancer classes create methods
to create a proxy object request: The proxy class can not be the final class
create method parameter
class byte code which is used to specify the proxy object bytecode
callback code for providing enhanced
sub-interface implementation class we generally are written to the interface: MethodInterceptor
Any method of any of the proxy object goes through the process
parameters:
Proxy Method args
above three parameters, and an interface based on dynamic parameters agent invoke method is the same
proxy object is currently executing method methodProxy