Java Agent Summary

Source: Internet
Author: User

First, the agent

Provides a proxy for other objects to control access to this object.

(1) Static agent

(2) Dynamic agent

1) The JDK's own dynamic agent

2) Javaassist byte code operation library Implementation

3) CGLIB

4) ASM (lower level instruction, poor maintainability)

Second, static agent

A static proxy mode typically has three roles:

Abstract role: A public method that is provided externally by the agent role and the real role, typically an interface

Real role: You need to implement an abstract role interface that defines the business logic to be implemented by the real role for the proxy role to invoke. That is the real business logic here.

Proxy role: the need to implement an abstract role interface, is the real role of the agent, through the real role of the business logic method to implement the abstract method, and can attach their own operations.

Third, dynamic agent (1) Proxy

Invocationhandler interface

. Invoke (Object Proxy,method moehtod,object[] args) Proxy execution interface interception method

Proxy

. Newproxyinstance (ClassLoader loader,class[] Interfaces,invcationhandler handler) Creating a dynamic proxy instance

(2) CGLIB

Methodinterceptor

    • Intercept (Object Obj,method method,object[] Args,methodproxy proxy) Object interception method

Enhancer

    • Setsuperclass (class superclass) Set parent class
    • Setcallback (CallBack CallBack) set callback blocker
    • Setclassloader (ClassLoader loader)
    • Create () object creates a proxy object

Methodproxy

    • Invokesuper (Object obj,object[] args) object executes proxy object
    • Invoke (Object target,object[] args) object to execute the proxied objects

Java Agent Summary

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.