当前位置:网站首页>Agent mode - power node of station B
Agent mode - power node of station B
2022-07-19 03:35:00 【KK-Greyson】
List of articles
001- The proxy pattern



002- Static proxy

2.1 Implementation of static proxy





If there are multiple stars to perform , Then use interface oriented programming :






2.2 The flaw of static proxy


003- A dynamic proxy

3.1 JDK A dynamic proxy ( master )

(1)JDK Classes and interfaces used by dynamic proxy


(2) Realization JDK A dynamic proxy




package com.bjpowernode.proxy;
import com.bjpowernode.service.Service;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/** * */
public class ProxyFactory {
// The member variables in the class are designed as interfaces , Target audience
Service target;
// Incoming target object
public ProxyFactory(Service target){
this.target = target;
}
// Returns the dynamic proxy object
public Object getAgent(){
return Proxy.newProxyInstance(
//ClassLoader loader, Class loader , Finish loading the target object
target.getClass().getClassLoader(),
//Class<?>[] interfaces, All interfaces implemented by the target object
target.getClass().getInterfaces(),
//InvocationHandler h, Interface to implement proxy function , What we passed in is an anonymous internal implementation
new InvocationHandler() {
@Override
public Object invoke(
// Create proxy object
Object proxy,
//method It's the target method sing(),show()
Method method,
// Parameters of the target method
Object[] args) throws Throwable {
// Agent function
System.out.println(" Booking time ........");
// Agent function
System.out.println(" Booking a venue ........");
// The main business function is realized
//target.sing(); Or write dead the method call , no
//sing(),show(),one()
Object obj = method.invoke(target,args);
// Agent function
System.out.println(" Settle the expenses ........");
return obj; // Bear in mind : This is the return value of the target method
}
}
);
}
}








3.2 CGLib A dynamic proxy ( understand )
(1) characteristic

(2)CGLib Dynamic agent implementation
The simplified version implements :



Complete the implementation :




004- summary

边栏推荐
- How to read and write a single document based on MFC
- Powertor500t reports an error 0x01806803
- 洛谷每日三题之第四天
- 05_ Service call ribbon
- Wechat applet
- 2022-07-16: what is the output of the following go language code? A:[]; B:[5]; C:[5 0 0 0 0]; D:[0 0 0 0 0]。 package main import ( “fmt“ )
- leetcode 222. 完全二叉树的节点个数(必会)
- 神经网络学习笔记2.2 ——用Matlab写一个简单的卷积神将网络图像分类器
- MySQL multi table query
- JDBC connection to MySQL database
猜你喜欢

2002 - Can‘t connect to server on ‘127.0.0.1‘ (36)

Powertor500t reports an error 0x01806803

How to read and write a single document based on MFC

ES6学习笔记——B站小马哥

Win10 onedrive failure reinstallation

Browser cannot open tensorboard

Polynomial interpolation fitting (III)

Can't access this website can't find DNS address DNS_ PROBE_ What about started?

XX市高中网络拓扑整体规划配置

Graphql first acquaintance
随机推荐
爬虫学习(5):手把手教你爬虫requests实战演练
Use RZ, SZ commands to upload and download files through xshell7
leetcode 222. 完全二叉树的节点个数(必会)
箭头函数与this指向详解
Leetcode: subsequence problem in dynamic programming
[NoSQL] redis high availability and persistence
367. 有效的完全平方数(入门必会)
Ncnn mat matrix class
Using gatekeeper to restrict kubernetes to create specific types of resources
Bisenetv2 face segmentation ncnn reasoning
How to use iota keyword in go language
Flutter开发:运行flutter upgrade命令报错Exception:Flutter failed to create a directory at…解决方法
Automatic assembly & set injection
Cmake common commands
D. Permutation restoration (greedy / double pointer /set)
Through openharmony compatibility evaluation, the big brother development board and rich teaching and training resources have been ready
zsh: command not found: mysql
Display zabbix6.0 information using grafana8.5.2
Gdb+vscode for debugging 8 - use core to analyze dead cycles, deadlocks, and segment errors
MYSQL主从搭建