Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize: replace byte-buddy to JDK proxy in ConfigurationCache #6386

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 0 additions & 4 deletions config/seata-config-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,10 +25,10 @@
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";
Expand Down Expand Up @@ -99,8 +100,8 @@ public void onChangeEvent(ConfigurationChangeEvent event) {
}

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];
Expand All @@ -124,8 +125,8 @@ public Configuration proxy(Configuration originalConfiguration) throws Exception
return wrapper == null ? null : wrapper.convertData(type);
}
return method.invoke(originalConfiguration, args);
})).make().load(originalConfiguration.getClass().getClassLoader()).getLoaded().getDeclaredConstructor()
.newInstance();
}
);
}

private static class ConfigurationCacheInstance {
Expand Down
Loading