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 321d88effdc..a1b9364426a 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 MigrationRuleListener() { 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 @@ private int getDelay() { @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 synchronized void process(ConfigChangedEvent event) { 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 @@ private MigrationRule parseRule(String rawRule) { } @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); }