Skip to content

Commit b9632fc

Browse files
authored
refactor:let the configuration SDK context stand alone. (#1344)
1 parent 67f0386 commit b9632fc

File tree

35 files changed

+255
-187
lines changed

35 files changed

+255
-187
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ closes #
2626

2727
## Checklist (Optional)
2828

29-
- [ ] Will pull request to branch of 2023.
30-
- [ ] Will pull request to branch of 2022.
31-
- [ ] Will pull request to branch of 2021.
32-
- [ ] Will pull request to branch of 2020.
29+
- [ ] Will pull request to branch of 2023.0.
30+
- [ ] Will pull request to branch of 2022.0.
31+
- [ ] Will pull request to branch of 2021.0.
32+
- [ ] Will pull request to branch of 2020.0.
3333
- [ ] Will pull request to branch of hoxton.

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
- [feat: add lane router examples](https://github.com/Tencent/spring-cloud-tencent/pull/1340)
1111
- [fix: fix the lossless provider override in multiple registries scenario](https://github.com/Tencent/spring-cloud-tencent/pull/1341)
1212
- [fix:fix nearby router properties loading bug.](https://github.com/Tencent/spring-cloud-tencent/pull/1342)
13-
- [fix: fix grammar issues for lane router example & optimize the gateway dependency](https://github.com/Tencent/spring-cloud-tencent/pull/1343)
13+
- [fix: fix grammar issues for lane router example & optimize the gateway dependency](https://github.com/Tencent/spring-cloud-tencent/pull/1343)
14+
- [refactor:let the configuration SDK context stand alone.](https://github.com/Tencent/spring-cloud-tencent/pull/1344)

spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/ConfigurationModifier.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
1414
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
1515
* specific language governing permissions and limitations under the License.
16-
*
1716
*/
1817

1918
package com.tencent.cloud.polaris.config;
@@ -26,7 +25,7 @@
2625
import com.tencent.cloud.common.util.AddressUtils;
2726
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
2827
import com.tencent.cloud.polaris.config.config.PolarisCryptoConfigProperties;
29-
import com.tencent.cloud.polaris.context.PolarisConfigModifier;
28+
import com.tencent.cloud.polaris.context.PolarisConfigurationConfigModifier;
3029
import com.tencent.cloud.polaris.context.config.PolarisContextProperties;
3130
import com.tencent.polaris.factory.config.ConfigurationImpl;
3231
import com.tencent.polaris.factory.config.configuration.ConfigFilterConfigImpl;
@@ -42,7 +41,7 @@
4241
*
4342
* @author lepdou 2022-03-10
4443
*/
45-
public class ConfigurationModifier implements PolarisConfigModifier {
44+
public class ConfigurationModifier implements PolarisConfigurationConfigModifier {
4645
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationModifier.class);
4746

4847
private static final String DATA_SOURCE_POLARIS = "polaris";

spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigAutoConfiguration.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.tencent.cloud.polaris.config.adapter.AffectedConfigurationPropertiesRebinder;
2222
import com.tencent.cloud.polaris.config.adapter.PolarisConfigPropertyRefresher;
2323
import com.tencent.cloud.polaris.config.adapter.PolarisConfigRefreshScopeAnnotationDetector;
24-
import com.tencent.cloud.polaris.config.adapter.PolarisPropertySourceManager;
2524
import com.tencent.cloud.polaris.config.adapter.PolarisRefreshAffectedContextRefresher;
2625
import com.tencent.cloud.polaris.config.adapter.PolarisRefreshEntireContextRefresher;
2726
import com.tencent.cloud.polaris.config.annotation.PolarisConfigAnnotationProcessor;
@@ -78,9 +77,9 @@ public ConfigurationPropertiesRebinder affectedConfigurationPropertiesRebinder(
7877

7978
@Bean
8079
@ConditionalOnMissingBean(search = SearchStrategy.CURRENT)
81-
public PolarisConfigPropertyRefresher polarisRefreshContextPropertySourceAutoRefresher(PolarisConfigProperties polarisConfigProperties,
82-
PolarisPropertySourceManager polarisPropertySourceManager, ContextRefresher contextRefresher) {
83-
return new PolarisRefreshEntireContextRefresher(polarisConfigProperties, polarisPropertySourceManager, contextRefresher);
80+
public PolarisConfigPropertyRefresher polarisRefreshContextPropertySourceAutoRefresher(
81+
PolarisConfigProperties polarisConfigProperties, ContextRefresher contextRefresher) {
82+
return new PolarisRefreshEntireContextRefresher(polarisConfigProperties, contextRefresher);
8483
}
8584

8685
@Configuration(proxyBeanMethods = false)
@@ -104,10 +103,10 @@ public SpringValueProcessor springValueProcessor(PlaceholderHelper placeholderHe
104103
}
105104

106105
@Bean
107-
public PolarisConfigPropertyRefresher polarisReflectPropertySourceAutoRefresher(PolarisConfigProperties polarisConfigProperties,
108-
PolarisPropertySourceManager polarisPropertySourceManager, SpringValueRegistry springValueRegistry,
106+
public PolarisConfigPropertyRefresher polarisReflectPropertySourceAutoRefresher(
107+
PolarisConfigProperties polarisConfigProperties, SpringValueRegistry springValueRegistry,
109108
PlaceholderHelper placeholderHelper) {
110-
return new PolarisRefreshAffectedContextRefresher(polarisConfigProperties, polarisPropertySourceManager,
109+
return new PolarisRefreshAffectedContextRefresher(polarisConfigProperties,
111110
springValueRegistry, placeholderHelper);
112111
}
113112

spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/PolarisConfigBootstrapAutoConfiguration.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import com.tencent.cloud.polaris.config.adapter.AffectedConfigurationPropertiesRebinder;
2222
import com.tencent.cloud.polaris.config.adapter.PolarisConfigFileLocator;
23-
import com.tencent.cloud.polaris.config.adapter.PolarisPropertySourceManager;
2423
import com.tencent.cloud.polaris.config.condition.ConditionalOnReflectRefreshType;
2524
import com.tencent.cloud.polaris.config.config.PolarisConfigProperties;
2625
import com.tencent.cloud.polaris.config.config.PolarisCryptoConfigProperties;
@@ -59,16 +58,10 @@ public PolarisCryptoConfigProperties polarisCryptoConfigProperties() {
5958
return new PolarisCryptoConfigProperties();
6059
}
6160

62-
@Bean
63-
@ConditionalOnMissingBean
64-
public PolarisPropertySourceManager polarisPropertySourceManager() {
65-
return new PolarisPropertySourceManager();
66-
}
67-
6861
@Bean
6962
@ConditionalOnConnectRemoteServerEnabled
7063
public ConfigFileService configFileService(PolarisSDKContextManager polarisSDKContextManager) {
71-
return ConfigFileServiceFactory.createConfigFileService(polarisSDKContextManager.getSDKContext());
64+
return ConfigFileServiceFactory.createConfigFileService(polarisSDKContextManager.getConfigSDKContext());
7265
}
7366

7467
@Bean
@@ -77,11 +70,9 @@ public PolarisConfigFileLocator polarisConfigFileLocator(
7770
PolarisConfigProperties polarisConfigProperties,
7871
PolarisContextProperties polarisContextProperties,
7972
ConfigFileService configFileService,
80-
PolarisPropertySourceManager polarisPropertySourceManager,
8173
Environment environment) {
8274
return new PolarisConfigFileLocator(polarisConfigProperties,
83-
polarisContextProperties, configFileService,
84-
polarisPropertySourceManager, environment);
75+
polarisContextProperties, configFileService, environment);
8576
}
8677

8778
@Bean

spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/adapter/PolarisConfigCustomExtensionLayer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
public interface PolarisConfigCustomExtensionLayer {
3232
void initRegisterConfig(PolarisConfigPropertyAutoRefresher polarisConfigPropertyAutoRefresher);
3333

34-
void initConfigFiles(Environment environment, CompositePropertySource compositePropertySource, PolarisPropertySourceManager polarisPropertySourceManager, ConfigFileService configFileService);
34+
void initConfigFiles(Environment environment, CompositePropertySource compositePropertySource, ConfigFileService configFileService);
3535

3636
void executeAfterLocateConfigReturning(CompositePropertySource compositePropertySource);
37+
3738
boolean executeRegisterPublishChangeListener(PolarisPropertySource polarisPropertySource);
3839
}

spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/adapter/PolarisConfigFileLocator.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,15 @@ public class PolarisConfigFileLocator implements PropertySourceLocator {
6464

6565
private final ConfigFileService configFileService;
6666

67-
private final PolarisPropertySourceManager polarisPropertySourceManager;
68-
6967
private final Environment environment;
7068
// this class provides customized logic for some customers to configure special business group files
7169
private final PolarisConfigCustomExtensionLayer polarisConfigCustomExtensionLayer = PolarisServiceLoaderUtil.getPolarisConfigCustomExtensionLayer();
7270

73-
public PolarisConfigFileLocator(PolarisConfigProperties polarisConfigProperties, PolarisContextProperties polarisContextProperties, ConfigFileService configFileService, PolarisPropertySourceManager polarisPropertySourceManager, Environment environment) {
71+
public PolarisConfigFileLocator(PolarisConfigProperties polarisConfigProperties,
72+
PolarisContextProperties polarisContextProperties, ConfigFileService configFileService, Environment environment) {
7473
this.polarisConfigProperties = polarisConfigProperties;
7574
this.polarisContextProperties = polarisContextProperties;
7675
this.configFileService = configFileService;
77-
this.polarisPropertySourceManager = polarisPropertySourceManager;
7876
this.environment = environment;
7977
}
8078

@@ -104,7 +102,7 @@ private void initCustomPolarisConfigExtensionFiles(CompositePropertySource compo
104102
LOGGER.debug("[SCT Config] PolarisConfigCustomExtensionLayer is not init, ignore the following execution steps");
105103
return;
106104
}
107-
polarisConfigCustomExtensionLayer.initConfigFiles(environment, compositePropertySource, polarisPropertySourceManager, configFileService);
105+
polarisConfigCustomExtensionLayer.initConfigFiles(environment, compositePropertySource, configFileService);
108106
}
109107

110108
private void afterLocatePolarisConfigExtension(CompositePropertySource compositePropertySource) {
@@ -123,7 +121,7 @@ private void initInternalConfigFiles(CompositePropertySource compositePropertySo
123121

124122
compositePropertySource.addPropertySource(polarisPropertySource);
125123

126-
polarisPropertySourceManager.addPropertySource(polarisPropertySource);
124+
PolarisPropertySourceManager.addPropertySource(polarisPropertySource);
127125

128126
LOGGER.info("[SCT Config] Load and inject polaris config file. file = {}", configFile);
129127
}
@@ -206,7 +204,7 @@ private void initCustomPolarisConfigFiles(CompositePropertySource compositePrope
206204

207205
compositePropertySource.addPropertySource(polarisPropertySource);
208206

209-
polarisPropertySourceManager.addPropertySource(polarisPropertySource);
207+
PolarisPropertySourceManager.addPropertySource(polarisPropertySource);
210208

211209
LOGGER.info("[SCT Config] Load and inject polaris config file success. namespace = {}, group = {}, fileName = {}", namespace, group, fileName);
212210
}

spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/adapter/PolarisConfigFilePuller.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ public final class PolarisConfigFilePuller {
5353

5454
private ConfigFileService configFileService;
5555

56-
private PolarisPropertySourceManager polarisPropertySourceManager;
57-
5856
private PolarisConfigFilePuller() {
5957
}
6058

@@ -64,15 +62,12 @@ private PolarisConfigFilePuller() {
6462
*
6563
* @param polarisContextProperties polarisContextProperties
6664
* @param configFileService configFileService
67-
* @param polarisPropertySourceManager polarisPropertySourceManager
6865
* @return PolarisConfigFilePuller instance
6966
*/
70-
public static PolarisConfigFilePuller get(PolarisContextProperties polarisContextProperties, ConfigFileService configFileService,
71-
PolarisPropertySourceManager polarisPropertySourceManager) {
67+
public static PolarisConfigFilePuller get(PolarisContextProperties polarisContextProperties, ConfigFileService configFileService) {
7268
PolarisConfigFilePuller puller = new PolarisConfigFilePuller();
7369
puller.polarisContextProperties = polarisContextProperties;
7470
puller.configFileService = configFileService;
75-
puller.polarisPropertySourceManager = polarisPropertySourceManager;
7671
return puller;
7772
}
7873

@@ -91,7 +86,7 @@ public void initInternalConfigFiles(CompositePropertySource compositePropertySou
9186
PolarisPropertySource polarisPropertySource = loadPolarisPropertySource(
9287
configFile.getNamespace(), configFile.getFileGroup(), configFile.getFileName());
9388
compositePropertySource.addPropertySource(polarisPropertySource);
94-
polarisPropertySourceManager.addPropertySource(polarisPropertySource);
89+
PolarisPropertySourceManager.addPropertySource(polarisPropertySource);
9590
LOGGER.info("[SCT Config] Load and inject polaris config file. file = {}", configFile);
9691
}
9792
}
@@ -129,7 +124,7 @@ public void initCustomPolarisConfigFile(CompositePropertySource compositePropert
129124
for (String fileName : files) {
130125
PolarisPropertySource polarisPropertySource = loadPolarisPropertySource(namespace, group, fileName);
131126
compositePropertySource.addPropertySource(polarisPropertySource);
132-
polarisPropertySourceManager.addPropertySource(polarisPropertySource);
127+
PolarisPropertySourceManager.addPropertySource(polarisPropertySource);
133128
LOGGER.info(
134129
"[SCT Config] Load and inject polaris config file success. namespace = {}, group = {}, fileName = {}",
135130
namespace, group, fileName);

spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/adapter/PolarisConfigPropertyAutoRefresher.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,13 @@ public abstract class PolarisConfigPropertyAutoRefresher implements ApplicationL
4646

4747
private final PolarisConfigProperties polarisConfigProperties;
4848

49-
private final PolarisPropertySourceManager polarisPropertySourceManager;
50-
5149
private final AtomicBoolean registered = new AtomicBoolean(false);
5250

5351
// this class provides customized logic for some customers to configure special business group files
5452
private final PolarisConfigCustomExtensionLayer polarisConfigCustomExtensionLayer = PolarisServiceLoaderUtil.getPolarisConfigCustomExtensionLayer();
5553

56-
public PolarisConfigPropertyAutoRefresher(PolarisConfigProperties polarisConfigProperties, PolarisPropertySourceManager polarisPropertySourceManager) {
54+
public PolarisConfigPropertyAutoRefresher(PolarisConfigProperties polarisConfigProperties) {
5755
this.polarisConfigProperties = polarisConfigProperties;
58-
this.polarisPropertySourceManager = polarisPropertySourceManager;
5956
}
6057

6158
@Override
@@ -68,7 +65,7 @@ private void registerPolarisConfigPublishEvent() {
6865
return;
6966
}
7067

71-
List<PolarisPropertySource> polarisPropertySources = polarisPropertySourceManager.getAllPropertySources();
68+
List<PolarisPropertySource> polarisPropertySources = PolarisPropertySourceManager.getAllPropertySources();
7269
if (CollectionUtils.isEmpty(polarisPropertySources)) {
7370
return;
7471
}
@@ -144,4 +141,11 @@ private void customRegisterPolarisConfigPublishChangeListener(PolarisPropertySou
144141
}
145142
polarisConfigCustomExtensionLayer.executeRegisterPublishChangeListener(polarisPropertySource);
146143
}
144+
145+
/**
146+
* Just for junit test.
147+
*/
148+
public void setRegistered(boolean registered) {
149+
this.registered.set(registered);
150+
}
147151
}

spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/adapter/PolarisPropertySourceManager.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,25 @@
2828
*
2929
* @author lepdou 2022-03-28
3030
*/
31-
public class PolarisPropertySourceManager {
31+
public final class PolarisPropertySourceManager {
3232

33-
private final Map<String, PolarisPropertySource> polarisPropertySources = new ConcurrentHashMap<>();
33+
private static final Map<String, PolarisPropertySource> polarisPropertySources = new ConcurrentHashMap<>();
3434

35-
public void addPropertySource(PolarisPropertySource polarisPropertySource) {
36-
polarisPropertySources.putIfAbsent(polarisPropertySource.getPropertySourceName(), polarisPropertySource);
35+
private PolarisPropertySourceManager() {
3736
}
3837

39-
public List<PolarisPropertySource> getAllPropertySources() {
38+
public static void addPropertySource(PolarisPropertySource polarisPropertySource) {
39+
polarisPropertySources.put(polarisPropertySource.getPropertySourceName(), polarisPropertySource);
40+
}
41+
42+
public static List<PolarisPropertySource> getAllPropertySources() {
4043
return new ArrayList<>(polarisPropertySources.values());
4144
}
45+
46+
/**
47+
* Just for test.
48+
*/
49+
public static void clearPropertySources() {
50+
polarisPropertySources.clear();
51+
}
4252
}

0 commit comments

Comments
 (0)