You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/06/21 02:18:43 UTC
[dubbo] branch 3.0 updated: [3.0] Optimize MigrationRuleListener
(#8071)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new f004643 [3.0] Optimize MigrationRuleListener (#8071)
f004643 is described below
commit f00464324398a401afa4f1cc9628224d970a1983
Author: Wu Zhiguo <ch...@startdt.com>
AuthorDate: Mon Jun 21 10:18:33 2021 +0800
[3.0] Optimize MigrationRuleListener (#8071)
* optimize MigrationRuleListener
* remove unnecessary rwlock
---
.../client/migration/MigrationRuleListener.java | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java
index 321d88e..a1b9364 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationRuleListener.java
@@ -65,12 +65,12 @@ public class MigrationRuleListener implements RegistryProtocolListener, Configur
if (StringUtils.isEmpty(rawRule)) {
rawRule = INIT;
}
- this.rawRule = rawRule;
+ setRawRule(rawRule);
} else {
if (logger.isWarnEnabled()) {
logger.warn("Using default configuration rule because config center is not configured!");
}
- rawRule = INIT;
+ setRawRule(INIT);
}
String localRawRule = ApplicationModel.getEnvironment().getLocalMigrationRule();
@@ -101,7 +101,7 @@ public class MigrationRuleListener implements RegistryProtocolListener, Configur
@Override
public synchronized void process(ConfigChangedEvent event) {
- rawRule = event.getContent();
+ String rawRule = event.getContent();
if (StringUtils.isEmpty(rawRule)) {
logger.warn("Received empty migration rule, will ignore.");
return;
@@ -110,13 +110,18 @@ public class MigrationRuleListener implements RegistryProtocolListener, Configur
logger.info("Using the following migration rule to migrate:");
logger.info(rawRule);
- rule = parseRule(rawRule);
+ setRawRule(rawRule);
if (CollectionUtils.isNotEmptyMap(handlers)) {
handlers.forEach((_key, handler) -> handler.doMigrate(rule));
}
}
+ public void setRawRule(String rawRule) {
+ this.rawRule = rawRule;
+ this.rule = parseRule(this.rawRule);
+ }
+
private MigrationRule parseRule(String rawRule) {
MigrationRule tmpRule = rule;
if (INIT.equals(rawRule)) {
@@ -132,19 +137,17 @@ public class MigrationRuleListener implements RegistryProtocolListener, Configur
}
@Override
- public synchronized void onExport(RegistryProtocol registryProtocol, Exporter<?> exporter) {
+ public void onExport(RegistryProtocol registryProtocol, Exporter<?> exporter) {
}
@Override
- public synchronized void onRefer(RegistryProtocol registryProtocol, ClusterInvoker<?> invoker, URL consumerUrl, URL registryURL) {
+ public void onRefer(RegistryProtocol registryProtocol, ClusterInvoker<?> invoker, URL consumerUrl, URL registryURL) {
MigrationRuleHandler<?> migrationRuleHandler = handlers.computeIfAbsent((MigrationInvoker<?>) invoker, _key -> {
((MigrationInvoker<?>) invoker).setMigrationRuleListener(this);
return new MigrationRuleHandler<>((MigrationInvoker<?>) invoker, consumerUrl);
});
- rule = parseRule(rawRule);
-
migrationRuleHandler.doMigrate(rule);
}