You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by jo...@apache.org on 2023/02/01 11:06:32 UTC
[incubator-eventmesh] branch master updated: [ISSUE #2942] Config Annotation add reloadMethodName attribute (#2943)
This is an automated email from the ASF dual-hosted git repository.
jonyang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git
The following commit(s) were added to refs/heads/master by this push:
new 4671e55d6 [ISSUE #2942] Config Annotation add reloadMethodName attribute (#2943)
4671e55d6 is described below
commit 4671e55d63f835009655077f4bb4e7bda90be87f
Author: jonyangx <ya...@gmail.com>
AuthorDate: Wed Feb 1 19:06:26 2023 +0800
[ISSUE #2942] Config Annotation add reloadMethodName attribute (#2943)
* fix issue2942
* fix license check error
---------
Co-authored-by: jonyangx <jo...@gmail.com>
---
.../main/java/org/apache/eventmesh/common/config/Config.java | 2 ++
.../java/org/apache/eventmesh/common/config/ConfigInfo.java | 2 ++
.../java/org/apache/eventmesh/common/config/ConfigService.java | 2 ++
.../common/config/convert/converter/ObjectConverter.java | 10 +++++++---
4 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/Config.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/Config.java
index b6c7cc132..f535a72cf 100644
--- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/Config.java
+++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/Config.java
@@ -43,6 +43,8 @@ public @interface Config {
boolean monitor() default false;
+ String reloadMethodName() default "reload";
+
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@interface Configs {
diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigInfo.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigInfo.java
index 39c4624cd..c37aa10b7 100644
--- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigInfo.java
+++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigInfo.java
@@ -44,6 +44,8 @@ public class ConfigInfo {
private Object object;
private String filePath;
+ private String reloadMethodName;
+
Field objectField;
Object instance;
}
\ No newline at end of file
diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigService.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigService.java
index a2250a2d4..4d1fbfce3 100644
--- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigService.java
+++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigService.java
@@ -95,6 +95,7 @@ public class ConfigService {
configInfo.setHump(config.hump());
configInfo.setPrefix(config.prefix());
configInfo.setMonitor(config.monitor());
+ configInfo.setReloadMethodName(config.reloadMethodName());
return this.getConfig(configInfo);
} catch (Exception e) {
@@ -151,6 +152,7 @@ public class ConfigService {
ConfigInfo configInfo = new ConfigInfo();
configInfo.setField(config.field());
configInfo.setMonitor(config.monitor());
+ configInfo.setReloadMethodName(config.reloadMethodName());
Field field = clazz.getDeclaredField(configInfo.getField());
Class<?> fieldClazz = field.getType();
diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/converter/ObjectConverter.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/converter/ObjectConverter.java
index 421707a8d..e1f860c5e 100644
--- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/converter/ObjectConverter.java
+++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/converter/ObjectConverter.java
@@ -49,6 +49,8 @@ public class ObjectConverter implements ConvertValue<Object> {
private Class<?> clazz;
+ private String reloadMethodName;
+
private void init(ConfigInfo configInfo) {
String prefix = configInfo.getPrefix();
if (Objects.nonNull(prefix)) {
@@ -57,6 +59,7 @@ public class ObjectConverter implements ConvertValue<Object> {
this.hump = Objects.equals(configInfo.getHump(), ConfigInfo.HUMP_ROD) ? '_' : '.';
this.clazz = convertInfo.getClazz();
this.convertInfo.setHump(this.hump);
+ this.reloadMethodName = configInfo.getReloadMethodName();
}
@Override
@@ -82,6 +85,7 @@ public class ObjectConverter implements ConvertValue<Object> {
this.prefix = prefix.endsWith(".") ? prefix : prefix + ".";
this.hump = Objects.equals(configArray[0].hump(), ConfigInfo.HUMP_ROD) ? '_' : '.';
this.convertInfo.setHump(this.hump);
+ this.reloadMethodName = configArray[0].reloadMethodName();
}
this.setValue();
@@ -139,12 +143,12 @@ public class ObjectConverter implements ConvertValue<Object> {
private void reloadConfigIfNeed(boolean needReload) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
if (needReload) {
- Method method = this.clazz.getDeclaredMethod("reload", null);
+ Method method = this.clazz.getDeclaredMethod(this.reloadMethodName == null ? "reload" : this.reloadMethodName);
boolean isAccessible = method.isAccessible();
try {
method.setAccessible(true);
- method.invoke(this.object, null);
+ method.invoke(this.object);
} finally {
method.setAccessible(isAccessible);
}
@@ -188,7 +192,7 @@ public class ObjectConverter implements ConvertValue<Object> {
if (needReload) {
try {
- this.clazz.getDeclaredMethod("reload", null);
+ this.clazz.getDeclaredMethod(this.reloadMethodName == null ? "reload" : this.reloadMethodName);
} catch (NoSuchMethodException e) {
throw new RuntimeException("The field needs to be reloaded, but the reload method cannot be found.", e);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org