This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.3
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.3 by this push:
new e2887e114d Bugfix: An instance of the subclass of RegistryConfig
should be added to configsCache as the RegistryConfig class type(#15016)
(#15017)
e2887e114d is described below
commit e2887e114def108783bccb77fcfb66b73f40a250
Author: youjie23 <[email protected]>
AuthorDate: Sun Jan 26 20:36:22 2025 +0800
Bugfix: An instance of the subclass of RegistryConfig should be added to
configsCache as the RegistryConfig class type(#15016) (#15017)
Co-authored-by: youjie_li <[email protected]>
---
.../dubbo/config/context/AbstractConfigManager.java | 20 ++++++++++++++------
.../dubbo/config/context/ConfigManagerTest.java | 15 +++++++++++++++
2 files changed, 29 insertions(+), 6 deletions(-)
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java
b/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java
index 95c1ea6c39..cab26b6829 100644
---
a/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java
+++
b/dubbo-common/src/main/java/org/apache/dubbo/config/context/AbstractConfigManager.java
@@ -161,8 +161,10 @@ public abstract class AbstractConfigManager extends
LifecycleAdapter {
config.setScopeModel(scopeModel);
}
+ Class<? extends AbstractConfig> targetConfigType =
getTargetConfigType(config.getClass());
+
Map<String, AbstractConfig> configsMap =
- configsCache.computeIfAbsent(getTagName(config.getClass()),
type -> new ConcurrentHashMap<>());
+ configsCache.computeIfAbsent(getTagName(targetConfigType),
type -> new ConcurrentHashMap<>());
// fast check duplicated equivalent config before write lock
if (!(config instanceof ReferenceConfigBase || config instanceof
ServiceConfigBase)) {
@@ -175,17 +177,21 @@ public abstract class AbstractConfigManager extends
LifecycleAdapter {
// lock by config type
synchronized (configsMap) {
- return (T) addIfAbsent(config, configsMap);
+ return (T) addIfAbsent(config, configsMap, targetConfigType);
}
}
protected boolean isSupportConfigType(Class<? extends AbstractConfig>
type) {
+ return getTargetConfigType(type) != null;
+ }
+
+ protected Class<? extends AbstractConfig> getTargetConfigType(Class<?
extends AbstractConfig> type) {
for (Class<? extends AbstractConfig> supportedConfigType :
supportedConfigTypes) {
if (supportedConfigType.isAssignableFrom(type)) {
- return true;
+ return supportedConfigType;
}
}
- return false;
+ return null;
}
/**
@@ -196,7 +202,9 @@ public abstract class AbstractConfigManager extends
LifecycleAdapter {
* @return the existing equivalent config or the new adding config
* @throws IllegalStateException
*/
- private <C extends AbstractConfig> C addIfAbsent(C config, Map<String, C>
configsMap) throws IllegalStateException {
+ private <C extends AbstractConfig> C addIfAbsent(
+ C config, Map<String, C> configsMap, Class<? extends
AbstractConfig> targetConfigType)
+ throws IllegalStateException {
if (config == null || configsMap == null) {
return config;
@@ -218,7 +226,7 @@ public abstract class AbstractConfigManager extends
LifecycleAdapter {
C existedConfig = configsMap.get(key);
if (existedConfig != null && !isEquals(existedConfig, config)) {
- String type = config.getClass().getSimpleName();
+ String type = targetConfigType.getSimpleName();
logger.warn(
COMMON_UNEXPECTED_EXCEPTION,
"",
diff --git
a/dubbo-common/src/test/java/org/apache/dubbo/config/context/ConfigManagerTest.java
b/dubbo-common/src/test/java/org/apache/dubbo/config/context/ConfigManagerTest.java
index 9b2966a05b..d51d43a1e9 100644
---
a/dubbo-common/src/test/java/org/apache/dubbo/config/context/ConfigManagerTest.java
+++
b/dubbo-common/src/test/java/org/apache/dubbo/config/context/ConfigManagerTest.java
@@ -251,6 +251,21 @@ class ConfigManagerTest {
assertFalse(moduleConfigManager.getProviders().isEmpty());
}
+ @Test
+ void testAddCustomConfig() {
+ configManager.addConfig(new
CustomRegistryConfig("CustomConfigManagerTest"));
+
+
assertTrue(configManager.getRegistry("CustomConfigManagerTest").isPresent());
+ }
+
+ static class CustomRegistryConfig extends RegistryConfig {
+
+ CustomRegistryConfig(String id) {
+ super();
+ this.setId(id);
+ }
+ }
+
@Test
void testRefreshAll() {
configManager.refreshAll();