Java Dynamic Agent mechanism

Source: Internet
Author: User

Classes and interfaces that need to be used:

    1. Class: Proxy
    2. Interface: Invocationhandler

Invocationhandler:

  1. Interface method:
    throws Throwable
  2. Method Parameters:
    Object Proxy: Instance of the proxy invocation method: Method object[] args: An array of parameter objects when executing a method
  3. Return value: Returns the result of the proxy object's execution method
    • You must implement Invocationhandler this interface

  4. JDK Comment (partial interception):
      @param proxy the proxy instance that the method was invoked On@param Method the {@code method} instance corresponding to the  interface  method Invoked on the proxy instance.  @param args an array of objects containing the values of the arguments passed in the Metho D invocation on the proxy instance, or {@code  null } if  interface   method takes no arguments.  @  return  the value to  from the method invocation on the proxy instance. 

Proxy:

  1. The method to use:
     Public Static Object newproxyinstance (ClassLoader loader, class<?>[] interfaces,  invocationhandler h)  throws illegalargumentexception
  2. Method Parameters:
    The ClassLoader Loader:classloader object, which is used to load the generated proxy objectinto an array of Class <?> [] Interfaces:interface objects, Proxy object Implementation method Invocationhandler H:invocationhandler object, loaded with the specified loader, and implements a proxy instance of Invocationhandler for the specified interface 
  3. Role: To get a dynamic proxy object
  4. JDK notes:
    @param   classclass@param   forclass to Implement@param   h the invocation handler to dispatch method invocations to@ return  class class
    implements the specified interfaces

Java Dynamic Agent mechanism

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.