Skip to content

Commit be1157d

Browse files
optimize: replace byte-buddy to JDK proxy in ConfigurationCache (#6386)
1 parent 575ac12 commit be1157d

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

changes/en-us/2.x.md

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Add changes here for all PR submitted to the 2.x branch.
9999
- [[#6356](https://github.com/apache/incubator-seata/pull/6356)] remove authentication from the health check page
100100
- [[#6360](https://github.com/apache/incubator-seata/pull/6360)] optimize 401 issues for some links
101101
- [[#6369](https://github.com/apache/incubator-seata/pull/6369)] optimize arm64 ci
102+
- [[#6386](https://github.com/apache/incubator-seata/pull/6386)] replace `byte-buddy` to JDK proxy in `ConfigurationCache`
102103

103104
### refactor:
104105
- [[#6269](https://github.com/apache/incubator-seata/pull/6269)] standardize Seata Exception

changes/zh-cn/2.x.md

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
- [[#6360](https://github.com/apache/incubator-seata/pull/6360)] 优化部分链接 401 的问题
104104
- [[#6350](https://github.com/apache/incubator-seata/pull/6350)] 移除 enableDegrade 配置
105105
- [[#6369](https://github.com/apache/incubator-seata/pull/6369)] 优化 arm64 ci
106+
- [[#6386](https://github.com/apache/incubator-seata/pull/6386)]`ConfigurationCache` 类中,将 `byte-buddy` 替换为JDK代理
106107

107108

108109
### refactor:

config/seata-config-core/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@
4343
<groupId>org.yaml</groupId>
4444
<artifactId>snakeyaml</artifactId>
4545
</dependency>
46-
<dependency>
47-
<groupId>net.bytebuddy</groupId>
48-
<artifactId>byte-buddy</artifactId>
49-
</dependency>
5046
</dependencies>
5147

5248
</project>

config/seata-config-core/src/main/java/org/apache/seata/config/ConfigurationCache.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.seata.config;
1818

19+
import java.lang.reflect.Proxy;
1920
import java.util.HashMap;
2021
import java.util.HashSet;
2122
import java.util.Map;
@@ -24,10 +25,10 @@
2425
import org.apache.seata.common.util.CollectionUtils;
2526
import org.apache.seata.common.util.DurationUtil;
2627
import org.apache.seata.common.util.StringUtils;
27-
import net.bytebuddy.ByteBuddy;
28-
import net.bytebuddy.implementation.InvocationHandlerAdapter;
29-
import net.bytebuddy.matcher.ElementMatchers;
3028

29+
/**
30+
* @author funkye
31+
*/
3132
public class ConfigurationCache implements ConfigurationChangeListener {
3233

3334
private static final String METHOD_PREFIX = "get";
@@ -99,8 +100,8 @@ public void onChangeEvent(ConfigurationChangeEvent event) {
99100
}
100101

101102
public Configuration proxy(Configuration originalConfiguration) throws Exception {
102-
return new ByteBuddy().subclass(Configuration.class).method(ElementMatchers.any())
103-
.intercept(InvocationHandlerAdapter.of((proxy, method, args) -> {
103+
return (Configuration)Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[]{Configuration.class}
104+
, (proxy, method, args) -> {
104105
String methodName = method.getName();
105106
if (methodName.startsWith(METHOD_PREFIX) && !methodName.equalsIgnoreCase(METHOD_LATEST_CONFIG)) {
106107
String rawDataId = (String)args[0];
@@ -124,8 +125,8 @@ public Configuration proxy(Configuration originalConfiguration) throws Exception
124125
return wrapper == null ? null : wrapper.convertData(type);
125126
}
126127
return method.invoke(originalConfiguration, args);
127-
})).make().load(originalConfiguration.getClass().getClassLoader()).getLoaded().getDeclaredConstructor()
128-
.newInstance();
128+
}
129+
);
129130
}
130131

131132
private static class ConfigurationCacheInstance {

0 commit comments

Comments
 (0)