From af566233dbb9673c9da18b545133bfaca0bd5bf5 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Sun, 3 Sep 2023 10:36:26 +0800 Subject: [PATCH] Support ignore refresh config (#12998) --- .../apache/dubbo/config/AbstractConfig.java | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java index 75a80c89997..cda3390abd1 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractConfig.java @@ -103,6 +103,11 @@ public abstract class AbstractConfig implements Serializable { protected final AtomicBoolean refreshed = new AtomicBoolean(false); + /** + * Indicate that if current config needs to being refreshed, default is true + */ + protected transient volatile boolean needRefresh = true; + /** * Is default config or not */ @@ -679,16 +684,18 @@ public void overrideWithConfig(AbstractConfig newOne, boolean overrideAll) { * Dubbo config property override */ public void refresh() { - try { - // check and init before do refresh - preProcessRefresh(); - refreshWithPrefixes(getPrefixes(), getConfigMode()); - } catch (Exception e) { - logger.error(COMMON_FAILED_OVERRIDE_FIELD, "", "", "Failed to override field value of config bean: " + this, e); - throw new IllegalStateException("Failed to override field value of config bean: " + this, e); - } + if (needRefresh) { + try { + // check and init before do refresh + preProcessRefresh(); + refreshWithPrefixes(getPrefixes(), getConfigMode()); + } catch (Exception e) { + logger.error(COMMON_FAILED_OVERRIDE_FIELD, "", "", "Failed to override field value of config bean: " + this, e); + throw new IllegalStateException("Failed to override field value of config bean: " + this, e); + } - postProcessRefresh(); + postProcessRefresh(); + } refreshed.set(true); } @@ -949,6 +956,17 @@ public void setDefault(Boolean isDefault) { this.isDefault = isDefault; } + @Transient + @Parameter(excluded = true, attribute = false) + public boolean isNeedRefresh() { + return needRefresh; + } + + @Transient + public void setNeedRefresh(boolean needRefresh) { + this.needRefresh = needRefresh; + } + @Override public String toString() { try {