You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by ji...@apache.org on 2024/03/02 09:08:27 UTC

(incubator-seata) branch 2.x updated: optimize: replace `byte-buddy` to JDK proxy in `ConfigurationCache` (#6386)

This is an automated email from the ASF dual-hosted git repository.

jianbin pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git


The following commit(s) were added to refs/heads/2.x by this push:
     new be1157dc95 optimize: replace `byte-buddy` to JDK proxy in `ConfigurationCache` (#6386)
be1157dc95 is described below

commit be1157dc9554fef123b633d067846965162f9920
Author: WangLiang/王良 <84...@qq.com>
AuthorDate: Sat Mar 2 17:08:22 2024 +0800

    optimize: replace `byte-buddy` to JDK proxy in `ConfigurationCache` (#6386)
---
 changes/en-us/2.x.md                                      |  1 +
 changes/zh-cn/2.x.md                                      |  1 +
 config/seata-config-core/pom.xml                          |  4 ----
 .../java/org/apache/seata/config/ConfigurationCache.java  | 15 ++++++++-------
 4 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index b831f723a4..15f9f2bd46 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -99,6 +99,7 @@ Add changes here for all PR submitted to the 2.x branch.
 - [[#6356](https://github.com/apache/incubator-seata/pull/6356)] remove authentication from the health check page
 - [[#6360](https://github.com/apache/incubator-seata/pull/6360)] optimize 401 issues for some links
 - [[#6369](https://github.com/apache/incubator-seata/pull/6369)] optimize arm64 ci
+- [[#6386](https://github.com/apache/incubator-seata/pull/6386)] replace `byte-buddy` to JDK proxy in `ConfigurationCache`
 
 ### refactor:
 - [[#6269](https://github.com/apache/incubator-seata/pull/6269)] standardize Seata Exception
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index 2997bbf7dd..423ef759c3 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -103,6 +103,7 @@
 - [[#6360](https://github.com/apache/incubator-seata/pull/6360)] 优化部分链接 401 的问题
 - [[#6350](https://github.com/apache/incubator-seata/pull/6350)] 移除 enableDegrade 配置
 - [[#6369](https://github.com/apache/incubator-seata/pull/6369)] 优化 arm64 ci
+- [[#6386](https://github.com/apache/incubator-seata/pull/6386)] 在 `ConfigurationCache` 类中,将 `byte-buddy` 替换为JDK代理
 
 
 ### refactor:
diff --git a/config/seata-config-core/pom.xml b/config/seata-config-core/pom.xml
index 8c2a9c9417..896a7070fe 100644
--- a/config/seata-config-core/pom.xml
+++ b/config/seata-config-core/pom.xml
@@ -43,10 +43,6 @@
             <groupId>org.yaml</groupId>
             <artifactId>snakeyaml</artifactId>
         </dependency>
-        <dependency>
-            <groupId>net.bytebuddy</groupId>
-            <artifactId>byte-buddy</artifactId>
-        </dependency>
     </dependencies>
 
 </project>
diff --git a/config/seata-config-core/src/main/java/org/apache/seata/config/ConfigurationCache.java b/config/seata-config-core/src/main/java/org/apache/seata/config/ConfigurationCache.java
index faa4cf90b9..889e59bc74 100644
--- a/config/seata-config-core/src/main/java/org/apache/seata/config/ConfigurationCache.java
+++ b/config/seata-config-core/src/main/java/org/apache/seata/config/ConfigurationCache.java
@@ -16,6 +16,7 @@
  */
 package org.apache.seata.config;
 
+import java.lang.reflect.Proxy;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -24,10 +25,10 @@ import java.util.concurrent.ConcurrentHashMap;
 import org.apache.seata.common.util.CollectionUtils;
 import org.apache.seata.common.util.DurationUtil;
 import org.apache.seata.common.util.StringUtils;
-import net.bytebuddy.ByteBuddy;
-import net.bytebuddy.implementation.InvocationHandlerAdapter;
-import net.bytebuddy.matcher.ElementMatchers;
 
+/**
+ * @author funkye
+ */
 public class ConfigurationCache implements ConfigurationChangeListener {
 
     private static final String METHOD_PREFIX = "get";
@@ -99,8 +100,8 @@ public class ConfigurationCache implements ConfigurationChangeListener {
     }
 
     public Configuration proxy(Configuration originalConfiguration) throws Exception {
-        return new ByteBuddy().subclass(Configuration.class).method(ElementMatchers.any())
-            .intercept(InvocationHandlerAdapter.of((proxy, method, args) -> {
+        return (Configuration)Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[]{Configuration.class}
+            , (proxy, method, args) -> {
                 String methodName = method.getName();
                 if (methodName.startsWith(METHOD_PREFIX) && !methodName.equalsIgnoreCase(METHOD_LATEST_CONFIG)) {
                     String rawDataId = (String)args[0];
@@ -124,8 +125,8 @@ public class ConfigurationCache implements ConfigurationChangeListener {
                     return wrapper == null ? null : wrapper.convertData(type);
                 }
                 return method.invoke(originalConfiguration, args);
-            })).make().load(originalConfiguration.getClass().getClassLoader()).getLoaded().getDeclaredConstructor()
-            .newInstance();
+            }
+        );
     }
 
     private static class ConfigurationCacheInstance {


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org