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 dce2f19 Fix the problem that MigrationRuleListener calls
removeListener method without group (#9488)
dce2f19 is described below
commit dce2f199dd8195c7b9cf53b897eaf529205ef578
Author: 灼华 <[email protected]>
AuthorDate: Thu Jan 20 14:56:43 2022 +0800
Fix the problem that MigrationRuleListener calls removeListener method
without group (#9488)
* Fix the problem that MigrationRuleListener calls removeListener without
group
* FIX
---
.../dubbo/rpc/cluster/router/state/BitList.java | 6 ++--
.../src/main/java/org/apache/dubbo/common/URL.java | 6 ++--
.../DefaultMigrationAddressComparator.java | 6 ++--
.../client/migration/MigrationRuleListener.java | 2 +-
.../registry/integration/DynamicDirectory.java | 12 ++++---
.../registry/integration/RegistryDirectory.java | 41 ++--------------------
6 files changed, 19 insertions(+), 54 deletions(-)
diff --git
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/BitList.java
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/BitList.java
index 055fd4c..ce0027e 100644
---
a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/BitList.java
+++
b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/state/BitList.java
@@ -132,7 +132,7 @@ public class BitList<E> extends AbstractList<E> {
}
public boolean hasMoreElementInTailList() {
- return CollectionUtils.isNotEmpty(tailList) && tailList.size() > 0;
+ return CollectionUtils.isNotEmpty(tailList);
}
public List<E> getTailList() {
@@ -342,7 +342,7 @@ public class BitList<E> extends AbstractList<E> {
@Override
public boolean isEmpty() {
- return this.rootSet.isEmpty() && (tailList == null ||
tailList.isEmpty());
+ return this.rootSet.isEmpty() && CollectionUtils.isEmpty(tailList);
}
@Override
@@ -538,7 +538,7 @@ public class BitList<E> extends AbstractList<E> {
}
public ArrayList<E> cloneToArrayList() {
- if (rootSet.cardinality() == originList.size() && (tailList == null ||
tailList.isEmpty())) {
+ if (rootSet.cardinality() == originList.size() &&
(CollectionUtils.isEmpty(tailList))) {
return new ArrayList<>(originList);
}
ArrayList<E> arrayList = new ArrayList<>(size());
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
index 08b0f1d..98218de 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/URL.java
@@ -270,12 +270,12 @@ class URL implements Serializable {
return result.clearParameters().addParameters(newMap);
}
- public static URL valueOf(URL url, String[] reserveParams, String[]
reserveParamPrefixs) {
+ public static URL valueOf(URL url, String[] reserveParams, String[]
reserveParamPrefixes) {
Map<String, String> newMap = new HashMap<>();
Map<String, String> oldMap = url.getParameters();
- if (reserveParamPrefixs != null && reserveParamPrefixs.length != 0) {
+ if (reserveParamPrefixes != null && reserveParamPrefixes.length != 0) {
for (Map.Entry<String, String> entry : oldMap.entrySet()) {
- for (String reserveParamPrefix : reserveParamPrefixs) {
+ for (String reserveParamPrefix : reserveParamPrefixes) {
if (entry.getKey().startsWith(reserveParamPrefix) &&
StringUtils.isNotEmpty(entry.getValue())) {
newMap.put(entry.getKey(), entry.getValue());
}
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/DefaultMigrationAddressComparator.java
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/DefaultMigrationAddressComparator.java
index 40a5d78..0ec1e88 100644
---
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/DefaultMigrationAddressComparator.java
+++
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/DefaultMigrationAddressComparator.java
@@ -64,9 +64,9 @@ public class DefaultMigrationAddressComparator implements
MigrationAddressCompar
migrationData.put(NEW_ADDRESS_SIZE, newAddressSize);
String rawThreshold = null;
- Float configedThreshold = rule == null ? null :
rule.getThreshold(oldInvoker.getUrl());
- if (configedThreshold != null && configedThreshold >= 0) {
- rawThreshold = String.valueOf(configedThreshold);
+ Float configuredThreshold = rule == null ? null :
rule.getThreshold(oldInvoker.getUrl());
+ if (configuredThreshold != null && configuredThreshold >= 0) {
+ rawThreshold = String.valueOf(configuredThreshold);
}
rawThreshold = StringUtils.isNotEmpty(rawThreshold) ? rawThreshold :
ConfigurationUtils.getCachedDynamicProperty(MIGRATION_THRESHOLD,
DEFAULT_THRESHOLD_STRING);
float threshold;
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 ca1f3dd..4623000 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
@@ -244,7 +244,7 @@ public class MigrationRuleListener implements
RegistryProtocolListener, Configur
@Override
public void onDestroy() {
if (configuration != null) {
- configuration.removeListener(ruleKey, this);
+ configuration.removeListener(ruleKey,
DUBBO_SERVICEDISCOVERY_MIGRATION, this);
}
if (ruleMigrationFuture != null) {
ruleMigrationFuture.cancel(true);
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/DynamicDirectory.java
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/DynamicDirectory.java
index 65b71a7..f8b20fc 100644
---
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/DynamicDirectory.java
+++
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/DynamicDirectory.java
@@ -24,6 +24,7 @@ import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.NetUtils;
+import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.registry.AddressListener;
import org.apache.dubbo.registry.NotifyListener;
import org.apache.dubbo.registry.Registry;
@@ -54,7 +55,7 @@ import static org.apache.dubbo.remoting.Constants.CHECK_KEY;
/**
- * RegistryDirectory
+ * DynamicDirectory
*/
public abstract class DynamicDirectory<T> extends AbstractDirectory<T>
implements NotifyListener {
@@ -115,6 +116,10 @@ public abstract class DynamicDirectory<T> extends
AbstractDirectory<T> implement
*/
private final boolean shouldFailFast;
+ private volatile InvokersChangedListener invokersChangedListener;
+ private volatile boolean invokersChanged;
+
+
public DynamicDirectory(Class<T> serviceType, URL url) {
super(url, true);
@@ -127,7 +132,7 @@ public abstract class DynamicDirectory<T> extends
AbstractDirectory<T> implement
throw new IllegalArgumentException("service type is null.");
}
- if (url.getServiceKey() == null || url.getServiceKey().length() == 0) {
+ if (StringUtils.isEmpty(url.getServiceKey())) {
throw new IllegalArgumentException("registry serviceKey is null.");
}
@@ -327,9 +332,6 @@ public abstract class DynamicDirectory<T> extends
AbstractDirectory<T> implement
}
}
- private volatile InvokersChangedListener invokersChangedListener;
- private volatile boolean invokersChanged;
-
public synchronized void
setInvokersChangedListener(InvokersChangedListener listener) {
this.invokersChangedListener = listener;
if (invokersChangedListener != null && invokersChanged) {
diff --git
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java
index aa4fd38..57c36cf 100644
---
a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java
+++
b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java
@@ -63,10 +63,8 @@ import static
org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TAG_KEY;
import static
org.apache.dubbo.common.constants.RegistryConstants.APP_DYNAMIC_CONFIGURATORS_CATEGORY;
-import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY;
import static
org.apache.dubbo.common.constants.RegistryConstants.COMPATIBLE_CONFIG_KEY;
import static
org.apache.dubbo.common.constants.RegistryConstants.CONFIGURATORS_CATEGORY;
-import static
org.apache.dubbo.common.constants.RegistryConstants.CONSUMERS_CATEGORY;
import static
org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_CATEGORY;
import static
org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_HASHMAP_LOAD_FACTOR;
import static
org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_CONFIGURATORS_CATEGORY;
@@ -75,8 +73,6 @@ import static
org.apache.dubbo.common.constants.RegistryConstants.PROVIDERS_CATE
import static
org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY;
import static
org.apache.dubbo.common.constants.RegistryConstants.ROUTE_PROTOCOL;
import static org.apache.dubbo.registry.Constants.CONFIGURATORS_SUFFIX;
-import static
org.apache.dubbo.registry.integration.InterfaceCompatibleRegistryProtocol.DEFAULT_REGISTER_CONSUMER_KEYS;
-import static org.apache.dubbo.remoting.Constants.CHECK_KEY;
import static org.apache.dubbo.rpc.Constants.MOCK_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.ROUTER_KEY;
import static org.apache.dubbo.rpc.model.ScopeModelUtil.getApplicationModel;
@@ -111,10 +107,9 @@ public class RegistryDirectory<T> extends
DynamicDirectory<T> {
@Override
public void subscribe(URL url) {
- setSubscribeUrl(url);
+ super.subscribe(url);
consumerConfigurationListener.addNotifyListener(this);
referenceConfigurationListener = new
ReferenceConfigurationListener(url.getOrDefaultModuleModel(), this, url);
- registry.subscribe(url, this);
}
private ConsumerConfigurationListener
getConsumerConfigurationListener(ModuleModel moduleModel) {
@@ -124,10 +119,9 @@ public class RegistryDirectory<T> extends
DynamicDirectory<T> {
@Override
public void unSubscribe(URL url) {
- setSubscribeUrl(null);
+ super.unSubscribe(url);
consumerConfigurationListener.removeNotifyListener(this);
referenceConfigurationListener.stop();
- registry.unsubscribe(url, this);
}
@Override
@@ -522,37 +516,6 @@ public class RegistryDirectory<T> extends
DynamicDirectory<T> {
logger.info("New url total size, " + newUrlInvokerMap.size() + ",
destroyed total size " + oldUrlInvokerMap.size());
}
- @Override
- public Class<T> getInterface() {
- return serviceType;
- }
-
- @Override
- public List<Invoker<T>> getAllInvokers() {
- return this.getInvokers();
- }
-
- @Override
- public URL getConsumerUrl() {
- return this.consumerUrl;
- }
-
- @Override
- public URL getRegisteredConsumerUrl() {
- return registeredConsumerUrl;
- }
-
- @Override
- public void setRegisteredConsumerUrl(URL url) {
- if (!shouldSimplified) {
- this.registeredConsumerUrl = url.addParameters(CATEGORY_KEY,
CONSUMERS_CATEGORY, CHECK_KEY,
- String.valueOf(false));
- } else {
- this.registeredConsumerUrl = URL.valueOf(url,
DEFAULT_REGISTER_CONSUMER_KEYS, null).addParameters(
- CATEGORY_KEY, CONSUMERS_CATEGORY, CHECK_KEY,
String.valueOf(false));
- }
- }
-
/**
* Haomin: added for test purpose
*/