当前位置:网站首页>Cglib create proxy
Cglib create proxy
2022-07-28 22:55:00 【Mangxiao】
CGLIb To create the agent
Create callback


To create the agent ( Through the enhancer and callback interface )

Set callback

This proxyInstance Is our proxy 
Proxy objects implement interfaces Factory Of setCallBack Method

So how does the proxy object implement this method , We use UserServiceImpl Proxy object as an example , And expand the implementation principle of interception
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package com.example.tran.service.impl;
import java.lang.reflect.Method;
import org.aopalliance.aop.Advice;
import org.springframework.aop.Advisor;
import org.springframework.aop.SpringProxy;
import org.springframework.aop.TargetClassAware;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.framework.AopConfigException;
import org.springframework.cglib.core.ReflectUtils;
import org.springframework.cglib.core.Signature;
import org.springframework.cglib.proxy.Callback;
import org.springframework.cglib.proxy.Dispatcher;
import org.springframework.cglib.proxy.Factory;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;
import org.springframework.cglib.proxy.NoOp;
public class UserServiceImpl$$EnhancerBySpringCGLIB$$b2af7d61 extends UserServiceImpl implements SpringProxy, Advised, Factory {
private boolean CGLIB$BOUND;
public static Object CGLIB$FACTORY_DATA;
private static final ThreadLocal CGLIB$THREAD_CALLBACKS;
private static final Callback[] CGLIB$STATIC_CALLBACKS;
private MethodInterceptor CGLIB$CALLBACK_0;
private MethodInterceptor CGLIB$CALLBACK_1;
private NoOp CGLIB$CALLBACK_2;
private Dispatcher CGLIB$CALLBACK_3;
private Dispatcher CGLIB$CALLBACK_4;
private MethodInterceptor CGLIB$CALLBACK_5;
private MethodInterceptor CGLIB$CALLBACK_6;
private static Object CGLIB$CALLBACK_FILTER;
private static final Method CGLIB$accountStar$0$Method;
private static final MethodProxy CGLIB$accountStar$0$Proxy;
private static final Object[] CGLIB$emptyArgs;
private static final Method CGLIB$accountMoney$1$Method;
private static final MethodProxy CGLIB$accountMoney$1$Proxy;
private static final Method CGLIB$equals$2$Method;
private static final MethodProxy CGLIB$equals$2$Proxy;
private static final Method CGLIB$toString$3$Method;
private static final MethodProxy CGLIB$toString$3$Proxy;
private static final Method CGLIB$hashCode$4$Method;
private static final MethodProxy CGLIB$hashCode$4$Proxy;
private static final Method CGLIB$clone$5$Method;
private static final MethodProxy CGLIB$clone$5$Proxy;
static void CGLIB$STATICHOOK10() {
CGLIB$THREAD_CALLBACKS = new ThreadLocal();
CGLIB$emptyArgs = new Object[0];
Class var0 = Class.forName("com.example.tran.service.impl.UserServiceImpl$$EnhancerBySpringCGLIB$$b2af7d61");
Class var1;
Method[] var10000 = ReflectUtils.findMethods(new String[]{
"equals", "(Ljava/lang/Object;)Z", "toString", "()Ljava/lang/String;", "hashCode", "()I", "clone", "()Ljava/lang/Object;"}, (var1 = Class.forName("java.lang.Object")).getDeclaredMethods());
CGLIB$equals$2$Method = var10000[0];
CGLIB$equals$2$Proxy = MethodProxy.create(var1, var0, "(Ljava/lang/Object;)Z", "equals", "CGLIB$equals$2");
CGLIB$toString$3$Method = var10000[1];
CGLIB$toString$3$Proxy = MethodProxy.create(var1, var0, "()Ljava/lang/String;", "toString", "CGLIB$toString$3");
CGLIB$hashCode$4$Method = var10000[2];
CGLIB$hashCode$4$Proxy = MethodProxy.create(var1, var0, "()I", "hashCode", "CGLIB$hashCode$4");
CGLIB$clone$5$Method = var10000[3];
CGLIB$clone$5$Proxy = MethodProxy.create(var1, var0, "()Ljava/lang/Object;", "clone", "CGLIB$clone$5");
var10000 = ReflectUtils.findMethods(new String[]{
"accountStar", "()V", "accountMoney", "()V"}, (var1 = Class.forName("com.example.tran.service.impl.UserServiceImpl")).getDeclaredMethods());
CGLIB$accountStar$0$Method = var10000[0];
CGLIB$accountStar$0$Proxy = MethodProxy.create(var1, var0, "()V", "accountStar", "CGLIB$accountStar$0");
CGLIB$accountMoney$1$Method = var10000[1];
CGLIB$accountMoney$1$Proxy = MethodProxy.create(var1, var0, "()V", "accountMoney", "CGLIB$accountMoney$1");
}
final void CGLIB$accountStar$0() {
super.accountStar();
}
public final void accountStar() {
MethodInterceptor var10000 = this.CGLIB$CALLBACK_0;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_0;
}
if (var10000 != null) {
var10000.intercept(this, CGLIB$accountStar$0$Method, CGLIB$emptyArgs, CGLIB$accountStar$0$Proxy);
} else {
super.accountStar();
}
}
final void CGLIB$accountMoney$1() {
super.accountMoney();
}
public final void accountMoney() {
MethodInterceptor var10000 = this.CGLIB$CALLBACK_0;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_0;
}
if (var10000 != null) {
var10000.intercept(this, CGLIB$accountMoney$1$Method, CGLIB$emptyArgs, CGLIB$accountMoney$1$Proxy);
} else {
super.accountMoney();
}
}
final boolean CGLIB$equals$2(Object var1) {
return super.equals(var1);
}
public final boolean equals(Object var1) {
MethodInterceptor var10000 = this.CGLIB$CALLBACK_5;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_5;
}
if (var10000 != null) {
Object var2 = var10000.intercept(this, CGLIB$equals$2$Method, new Object[]{
var1}, CGLIB$equals$2$Proxy);
return var2 == null ? false : (Boolean)var2;
} else {
return super.equals(var1);
}
}
final String CGLIB$toString$3() {
return super.toString();
}
public final String toString() {
MethodInterceptor var10000 = this.CGLIB$CALLBACK_0;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_0;
}
return var10000 != null ? (String)var10000.intercept(this, CGLIB$toString$3$Method, CGLIB$emptyArgs, CGLIB$toString$3$Proxy) : super.toString();
}
final int CGLIB$hashCode$4() {
return super.hashCode();
}
public final int hashCode() {
MethodInterceptor var10000 = this.CGLIB$CALLBACK_6;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_6;
}
if (var10000 != null) {
Object var1 = var10000.intercept(this, CGLIB$hashCode$4$Method, CGLIB$emptyArgs, CGLIB$hashCode$4$Proxy);
return var1 == null ? 0 : ((Number)var1).intValue();
} else {
return super.hashCode();
}
}
final Object CGLIB$clone$5() throws CloneNotSupportedException {
return super.clone();
}
protected final Object clone() throws CloneNotSupportedException {
MethodInterceptor var10000 = this.CGLIB$CALLBACK_0;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_0;
}
return var10000 != null ? var10000.intercept(this, CGLIB$clone$5$Method, CGLIB$emptyArgs, CGLIB$clone$5$Proxy) : super.clone();
}
public static MethodProxy CGLIB$findMethodProxy(Signature var0) {
String var10000 = var0.toString();
switch(var10000.hashCode()) {
case -1179333386:
if (var10000.equals("accountStar()V")) {
return CGLIB$accountStar$0$Proxy;
}
break;
case -508378822:
if (var10000.equals("clone()Ljava/lang/Object;")) {
return CGLIB$clone$5$Proxy;
}
break;
case 448476162:
if (var10000.equals("accountMoney()V")) {
return CGLIB$accountMoney$1$Proxy;
}
break;
case 1826985398:
if (var10000.equals("equals(Ljava/lang/Object;)Z")) {
return CGLIB$equals$2$Proxy;
}
break;
case 1913648695:
if (var10000.equals("toString()Ljava/lang/String;")) {
return CGLIB$toString$3$Proxy;
}
break;
case 1984935277:
if (var10000.equals("hashCode()I")) {
return CGLIB$hashCode$4$Proxy;
}
}
return null;
}
public final int indexOf(Advisor var1) {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
return ((Advised)var10000.loadObject()).indexOf(var1);
}
public final int indexOf(Advice var1) {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
return ((Advised)var10000.loadObject()).indexOf(var1);
}
public final boolean isFrozen() {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
return ((Advised)var10000.loadObject()).isFrozen();
}
public final Class[] getProxiedInterfaces() {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
return ((Advised)var10000.loadObject()).getProxiedInterfaces();
}
public final boolean isInterfaceProxied(Class var1) {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
return ((Advised)var10000.loadObject()).isInterfaceProxied(var1);
}
public final String toProxyConfigString() {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
return ((Advised)var10000.loadObject()).toProxyConfigString();
}
public final boolean isProxyTargetClass() {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
return ((Advised)var10000.loadObject()).isProxyTargetClass();
}
public final boolean isExposeProxy() {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
return ((Advised)var10000.loadObject()).isExposeProxy();
}
public final void setPreFiltered(boolean var1) {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
((Advised)var10000.loadObject()).setPreFiltered(var1);
}
public final void setTargetSource(TargetSource var1) {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
((Advised)var10000.loadObject()).setTargetSource(var1);
}
public final boolean isPreFiltered() {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
return ((Advised)var10000.loadObject()).isPreFiltered();
}
public final TargetSource getTargetSource() {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
return ((Advised)var10000.loadObject()).getTargetSource();
}
public final void setExposeProxy(boolean var1) {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
((Advised)var10000.loadObject()).setExposeProxy(var1);
}
public final Advisor[] getAdvisors() {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
return ((Advised)var10000.loadObject()).getAdvisors();
}
public final void addAdvisor(Advisor var1) throws AopConfigException {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
((Advised)var10000.loadObject()).addAdvisor(var1);
}
public final void addAdvisor(int var1, Advisor var2) throws AopConfigException {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
((Advised)var10000.loadObject()).addAdvisor(var1, var2);
}
public final void removeAdvisor(int var1) throws AopConfigException {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
((Advised)var10000.loadObject()).removeAdvisor(var1);
}
public final boolean removeAdvisor(Advisor var1) {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
return ((Advised)var10000.loadObject()).removeAdvisor(var1);
}
public final boolean removeAdvice(Advice var1) {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
return ((Advised)var10000.loadObject()).removeAdvice(var1);
}
public final boolean replaceAdvisor(Advisor var1, Advisor var2) throws AopConfigException {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
return ((Advised)var10000.loadObject()).replaceAdvisor(var1, var2);
}
public final void addAdvice(int var1, Advice var2) throws AopConfigException {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
((Advised)var10000.loadObject()).addAdvice(var1, var2);
}
public final void addAdvice(Advice var1) throws AopConfigException {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
((Advised)var10000.loadObject()).addAdvice(var1);
}
public final Class getTargetClass() {
Dispatcher var10000 = this.CGLIB$CALLBACK_4;
if (var10000 == null) {
CGLIB$BIND_CALLBACKS(this);
var10000 = this.CGLIB$CALLBACK_4;
}
return ((TargetClassAware)var10000.loadObject()).getTargetClass();
}
public UserServiceImpl$$EnhancerBySpringCGLIB$$b2af7d61() {
CGLIB$BIND_CALLBACKS(this);
}
public static void CGLIB$SET_THREAD_CALLBACKS(Callback[] var0) {
CGLIB$THREAD_CALLBACKS.set(var0);
}
public static void CGLIB$SET_STATIC_CALLBACKS(Callback[] var0) {
CGLIB$STATIC_CALLBACKS = var0;
}
private static final void CGLIB$BIND_CALLBACKS(Object var0) {
UserServiceImpl$$EnhancerBySpringCGLIB$$b2af7d61 var1 = (UserServiceImpl$$EnhancerBySpringCGLIB$$b2af7d61)var0;
if (!var1.CGLIB$BOUND) {
var1.CGLIB$BOUND = true;
Object var10000 = CGLIB$THREAD_CALLBACKS.get();
if (var10000 == null) {
var10000 = CGLIB$STATIC_CALLBACKS;
if (var10000 == null) {
return;
}
}
Callback[] var10001 = (Callback[])var10000;
var1.CGLIB$CALLBACK_6 = (MethodInterceptor)((Callback[])var10000)[6];
var1.CGLIB$CALLBACK_5 = (MethodInterceptor)var10001[5];
var1.CGLIB$CALLBACK_4 = (Dispatcher)var10001[4];
var1.CGLIB$CALLBACK_3 = (Dispatcher)var10001[3];
var1.CGLIB$CALLBACK_2 = (NoOp)var10001[2];
var1.CGLIB$CALLBACK_1 = (MethodInterceptor)var10001[1];
var1.CGLIB$CALLBACK_0 = (MethodInterceptor)var10001[0];
}
}
public Object newInstance(Callback[] var1) {
CGLIB$SET_THREAD_CALLBACKS(var1);
UserServiceImpl$$EnhancerBySpringCGLIB$$b2af7d61 var10000 = new UserServiceImpl$$EnhancerBySpringCGLIB$$b2af7d61();
CGLIB$SET_THREAD_CALLBACKS((Callback[])null);
return var10000;
}
public Object newInstance(Callback var1) {
throw new IllegalStateException("More than one callback object required");
}
public Object newInstance(Class[] var1, Object[] var2, Callback[] var3) {
CGLIB$SET_THREAD_CALLBACKS(var3);
UserServiceImpl$$EnhancerBySpringCGLIB$$b2af7d61 var10000 = new UserServiceImpl$$EnhancerBySpringCGLIB$$b2af7d61;
switch(var1.length) {
case 0:
var10000.<init>();
CGLIB$SET_THREAD_CALLBACKS((Callback[])null);
return var10000;
default:
throw new IllegalArgumentException("Constructor not found");
}
}
public Callback getCallback(int var1) {
CGLIB$BIND_CALLBACKS(this);
Object var10000;
switch(var1) {
case 0:
var10000 = this.CGLIB$CALLBACK_0;
break;
case 1:
var10000 = this.CGLIB$CALLBACK_1;
break;
case 2:
var10000 = this.CGLIB$CALLBACK_2;
break;
case 3:
var10000 = this.CGLIB$CALLBACK_3;
break;
case 4:
var10000 = this.CGLIB$CALLBACK_4;
break;
case 5:
var10000 = this.CGLIB$CALLBACK_5;
break;
case 6:
var10000 = this.CGLIB$CALLBACK_6;
break;
default:
var10000 = null;
}
return (Callback)var10000;
}
public void setCallback(int var1, Callback var2) {
switch(var1) {
case 0:
this.CGLIB$CALLBACK_0 = (MethodInterceptor)var2;
break;
case 1:
this.CGLIB$CALLBACK_1 = (MethodInterceptor)var2;
break;
case 2:
this.CGLIB$CALLBACK_2 = (NoOp)var2;
break;
case 3:
this.CGLIB$CALLBACK_3 = (Dispatcher)var2;
break;
case 4:
this.CGLIB$CALLBACK_4 = (Dispatcher)var2;
break;
case 5:
this.CGLIB$CALLBACK_5 = (MethodInterceptor)var2;
break;
case 6:
this.CGLIB$CALLBACK_6 = (MethodInterceptor)var2;
}
}
public Callback[] getCallbacks() {
CGLIB$BIND_CALLBACKS(this);
return new Callback[]{
this.CGLIB$CALLBACK_0, this.CGLIB$CALLBACK_1, this.CGLIB$CALLBACK_2, this.CGLIB$CALLBACK_3, this.CGLIB$CALLBACK_4, this.CGLIB$CALLBACK_5, this.CGLIB$CALLBACK_6};
}
public void setCallbacks(Callback[] var1) {
this.CGLIB$CALLBACK_0 = (MethodInterceptor)var1[0];
this.CGLIB$CALLBACK_1 = (MethodInterceptor)var1[1];
this.CGLIB$CALLBACK_2 = (NoOp)var1[2];
this.CGLIB$CALLBACK_3 = (Dispatcher)var1[3];
this.CGLIB$CALLBACK_4 = (Dispatcher)var1[4];
this.CGLIB$CALLBACK_5 = (MethodInterceptor)var1[5];
this.CGLIB$CALLBACK_6 = (MethodInterceptor)var1[6];
}
static {
CGLIB$STATICHOOK10();
}
}
CGLib summary
The proxy object encapsulates the implementation of the target object by inheriting the target object



CGlib The implementation of interception —— Before executing the target method, determine whether the interceptor exists and intercept
You can see , Intercept first , Re execution targetClass.method This process ( adopt super.method To achieve )
边栏推荐
- Paper reading vision gnn: an image is worth graph of nodes
- Draem+sspcab [anomaly detection: block]
- Yolov5 improvement 4: add ECA channel attention mechanism
- MySQL foundation - data query
- 轮子七:TCP客户端
- Yolov5 improvement 15: network lightweight method deep separable convolution
- LeetCode练习3——回文数
- DIP-VBTV: Color Image Restoration Model Combining Deep Image Prior and Vector Bundle Total Variation
- Symbol符号类型
- WebApplicationType#deduceFromClasspath
猜你喜欢
![Fastflow [abnormal detection: normalizing flow]](/img/5e/984e5bd34c493039e3c9909fc4df05.png)
Fastflow [abnormal detection: normalizing flow]

《Shortening passengers’ travel time A dynamic metro train scheduling approach using deep reinforcem》

Paper reading vision gnn: an image is worth graph of nodes
![Stm32f4 serial port burning [flymcu]](/img/5b/0e35c3c58354f911631a3affd3909b.png)
Stm32f4 serial port burning [flymcu]

Anaconda environment installation skimage package

PCA学习

frontiers出版社投稿记录(附状态变化)

Summary of the problem that MathType formula does not correspond in word
![[reprint] the token token is used in the login scenario](/img/84/77dc2316e2adc380a580e2456c0e59.png)
[reprint] the token token is used in the login scenario

Anomaly detection summary: intensity_ based/Normalizing Flow
随机推荐
Migration from IPv4 to IPv6
The simple neural network model based on full connection layer MLP is changed to the model based on CNN convolutional neural network
STM32 - interrupt overview (interrupt priority)
npm run dev,运行项目后自动打开浏览器
Find out the maximum value of all indicators in epoch [tips]
【数据库】
Configuration and official document of Freia library [tips]
OSV-q The size of tensor a (3) must match the size of tensor b (320) at non-singleton dimension 3
软件测试面试笔试题及答案(软件测试题库)
MySQL foundation - advanced functions
STM32CUBEIDE(10)----ADC在DMA模式下扫描多个通道
RuntimeError: set_ sizes_ contiguous is not allowed on a Tensor created from .data or .detach().
无代码开发平台通讯录导出入门教程
美国FCC提供16亿美元资助本国运营商移除华为和中兴设备
TypeError: can‘t convert cuda:0 device type tensor to numpy. Use Tensor. cpu() to copy the tensor to
Binary source code, inverse code, complement code
Yolov5 improvement 4: add ECA channel attention mechanism
【三维目标检测】3DSSD(二)
Ocr-gan [anomaly detection: Reconstruction Based]
Padim [anomaly detection: embedded based]