You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by il...@apache.org on 2019/09/05 08:31:22 UTC
[dubbo] branch master updated: nacos-registry:serviceName split
error (#4974)
This is an automated email from the ASF dual-hosted git repository.
iluo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new a032767 nacos-registry:serviceName split error (#4974)
a032767 is described below
commit a0327674c610dac69d65467f8810ccfc65997b8f
Author: charish00 <ch...@163.com>
AuthorDate: Thu Sep 5 16:30:53 2019 +0800
nacos-registry:serviceName split error (#4974)
* nacos-registry:serviceName split error
* nacos-registry::remove depency org.apache.commons.lang3
---
.../apache/dubbo/registry/nacos/NacosRegistry.java | 89 ++++++++++------------
.../dubbo/registry/nacos/NacosServiceName.java | 44 ++++-------
2 files changed, 57 insertions(+), 76 deletions(-)
diff --git a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
index b364df4..5c90780 100644
--- a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
+++ b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
@@ -16,24 +16,23 @@
*/
package org.apache.dubbo.registry.nacos;
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.logger.Logger;
-import org.apache.dubbo.common.logger.LoggerFactory;
-import org.apache.dubbo.common.utils.UrlUtils;
-import org.apache.dubbo.registry.NotifyListener;
-import org.apache.dubbo.registry.Registry;
-import org.apache.dubbo.registry.support.FailbackRegistry;
-
-import com.alibaba.nacos.api.exception.NacosException;
-import com.alibaba.nacos.api.naming.NamingService;
-import com.alibaba.nacos.api.naming.listener.EventListener;
-import com.alibaba.nacos.api.naming.listener.NamingEvent;
-import com.alibaba.nacos.api.naming.pojo.Instance;
-import com.alibaba.nacos.api.naming.pojo.ListView;
-import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.lang3.StringUtils;
+import static java.util.Collections.singleton;
+import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
+import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
+import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_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.PROVIDERS_CATEGORY;
+import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY;
+import static org.apache.dubbo.registry.Constants.ADMIN_PROTOCOL;
+import static org.apache.dubbo.registry.nacos.NacosServiceName.valueOf;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -49,20 +48,20 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
-import static java.util.Collections.singleton;
-import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
-import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
-import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_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.PROVIDERS_CATEGORY;
-import static org.apache.dubbo.common.constants.RegistryConstants.ROUTERS_CATEGORY;
-import static org.apache.dubbo.registry.Constants.ADMIN_PROTOCOL;
-import static org.apache.dubbo.registry.nacos.NacosServiceName.valueOf;
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.LoggerFactory;
+import org.apache.dubbo.common.utils.UrlUtils;
+import org.apache.dubbo.registry.NotifyListener;
+import org.apache.dubbo.registry.Registry;
+import org.apache.dubbo.registry.support.FailbackRegistry;
+
+import com.alibaba.nacos.api.exception.NacosException;
+import com.alibaba.nacos.api.naming.NamingService;
+import com.alibaba.nacos.api.naming.listener.EventListener;
+import com.alibaba.nacos.api.naming.listener.NamingEvent;
+import com.alibaba.nacos.api.naming.pojo.Instance;
+import com.alibaba.nacos.api.naming.pojo.ListView;
/**
* Nacos {@link Registry}
@@ -77,7 +76,7 @@ public class NacosRegistry extends FailbackRegistry {
/**
* All supported categories
*/
- private static final String[] ALL_SUPPORTED_CATEGORIES = of(
+ private static final List<String> ALL_SUPPORTED_CATEGORIES = Arrays.asList(
PROVIDERS_CATEGORY,
CONSUMERS_CATEGORY,
ROUTERS_CATEGORY,
@@ -252,7 +251,7 @@ public class NacosRegistry extends FailbackRegistry {
boolean accepted = false;
for (String category : ALL_SUPPORTED_CATEGORIES) {
String prefix = category + SERVICE_NAME_SEPARATOR;
- if (StringUtils.startsWith(serviceName, prefix)) {
+ if (serviceName != null && serviceName.startsWith(prefix)) {
accepted = true;
break;
}
@@ -310,7 +309,7 @@ public class NacosRegistry extends FailbackRegistry {
private void filterServiceNames(Set<String> serviceNames, URL url) {
- final String[] categories = getCategories(url);
+ final List<String> categories = getCategories(url);
final String targetServiceInterface = url.getServiceInterface();
@@ -324,32 +323,32 @@ public class NacosRegistry extends FailbackRegistry {
// (required) segments[1] = serviceInterface
// (optional) segments[2] = version
// (optional) segments[3] = group
- String[] segments = StringUtils.split(serviceName, SERVICE_NAME_SEPARATOR);
+ String[] segments = serviceName.split(SERVICE_NAME_SEPARATOR, -1);
int length = segments.length;
if (length != 4) { // must present 4 segments
return false;
}
String category = segments[CATEGORY_INDEX];
- if (!ArrayUtils.contains(categories, category)) { // no match category
+ if (!categories.contains(category)) { // no match category
return false;
}
String serviceInterface = segments[SERVICE_INTERFACE_INDEX];
if (!WILDCARD.equals(targetServiceInterface) &&
- !StringUtils.equals(targetServiceInterface, serviceInterface)) { // no match service interface
+ !targetServiceInterface.equals(serviceInterface)) { // no match service interface
return false;
}
String version = segments[SERVICE_VERSION_INDEX];
if (!WILDCARD.equals(targetVersion) &&
- !StringUtils.equals(targetVersion, version)) { // no match service version
+ !targetVersion.equals(version)) { // no match service version
return false;
}
String group = segments[SERVICE_GROUP_INDEX];
return group == null || WILDCARD.equals(targetGroup)
- || StringUtils.equals(targetGroup, group);
+ || targetGroup.equals(group);
});
}
@@ -360,8 +359,8 @@ public class NacosRegistry extends FailbackRegistry {
@Deprecated
private List<String> doGetServiceNames(URL url) {
- String[] categories = getCategories(url);
- List<String> serviceNames = new ArrayList<>(categories.length);
+ List<String> categories = getCategories(url);
+ List<String> serviceNames = new ArrayList<>(categories.size());
for (String category : categories) {
final String serviceName = getServiceName(url, category);
serviceNames.add(serviceName);
@@ -418,9 +417,9 @@ public class NacosRegistry extends FailbackRegistry {
* @param url {@link URL}
* @return non-null array
*/
- private String[] getCategories(URL url) {
+ private List<String> getCategories(URL url) {
return ANY_VALUE.equals(url.getServiceInterface()) ?
- ALL_SUPPORTED_CATEGORIES : of(DEFAULT_CATEGORY);
+ ALL_SUPPORTED_CATEGORIES : Arrays.asList(DEFAULT_CATEGORY);
}
private URL buildURL(Instance instance) {
@@ -475,12 +474,6 @@ public class NacosRegistry extends FailbackRegistry {
filterData(instances, Instance::isEnabled);
}
- @SafeVarargs
- private static <T> T[] of(T... values) {
- return values;
- }
-
-
/**
* A filter for Nacos data
*
diff --git a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceName.java b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceName.java
index 9a85bed..bb609ca 100644
--- a/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceName.java
+++ b/dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceName.java
@@ -16,23 +16,17 @@
*/
package org.apache.dubbo.registry.nacos;
-import org.apache.dubbo.common.URL;
-
-import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.lang3.StringUtils;
-
-import java.util.Objects;
-
-import static org.apache.commons.lang3.ArrayUtils.getLength;
-import static org.apache.commons.lang3.StringUtils.contains;
-import static org.apache.commons.lang3.StringUtils.isBlank;
-import static org.apache.commons.lang3.StringUtils.split;
-import static org.apache.commons.lang3.StringUtils.splitPreserveAllTokens;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.DEFAULT_CATEGORY;
+import static org.apache.dubbo.common.utils.StringUtils.isBlank;
+
+import java.util.Arrays;
+import java.util.Objects;
+
+import org.apache.dubbo.common.URL;
/**
* The service name of Nacos
@@ -80,7 +74,7 @@ public class NacosServiceName {
public NacosServiceName(String value) {
this.value = value;
- String[] segments = splitPreserveAllTokens(value, NAME_SEPARATOR);
+ String[] segments = value.split(NAME_SEPARATOR, -1);
this.category = segments[CATEGORY_INDEX];
this.serviceInterface = segments[SERVICE_INTERFACE_INDEX];
this.version = segments[SERVICE_VERSION_INDEX];
@@ -113,12 +107,12 @@ public class NacosServiceName {
}
// Not match comparison
- if (!StringUtils.equals(this.category, concreteServiceName.category) &&
- !ArrayUtils.contains(splitPreserveAllTokens(this.category, VALUE_SEPARATOR), concreteServiceName.category)) {
+ if (!this.category.equals(concreteServiceName.category)
+ && !matchRange(this.category, concreteServiceName.category)) {
return false;
}
- if (!StringUtils.equals(this.serviceInterface, concreteServiceName.serviceInterface)) {
+ if (!this.serviceInterface.equals(concreteServiceName.serviceInterface)) {
return false;
}
@@ -132,13 +126,12 @@ public class NacosServiceName {
}
// range condition
- if (!StringUtils.equals(this.version, concreteServiceName.version) &&
- !matchRange(this.version, concreteServiceName.version)) {
+ if (!this.version.equals(concreteServiceName.version)
+ && !matchRange(this.version, concreteServiceName.version)) {
return false;
}
- if (!StringUtils.equals(this.group, concreteServiceName.group) &&
- !matchRange(this.group, concreteServiceName.group)) {
+ if (!this.group.equals(concreteServiceName.group) && !matchRange(this.group, concreteServiceName.group)) {
return false;
}
@@ -152,8 +145,8 @@ public class NacosServiceName {
if (!isRange(range)) {
return false;
}
- String[] values = split(range, VALUE_SEPARATOR);
- return ArrayUtils.contains(values, value);
+ String[] values = range.split(VALUE_SEPARATOR);
+ return Arrays.asList(values).contains(value);
}
private boolean isConcrete(String value) {
@@ -165,11 +158,7 @@ public class NacosServiceName {
}
private boolean isRange(String value) {
- if (contains(value, VALUE_SEPARATOR)) {
- String[] values = split(value, VALUE_SEPARATOR);
- return getLength(values) > 1;
- }
- return false;
+ return value != null && value.indexOf(VALUE_SEPARATOR) > -1 && value.split(VALUE_SEPARATOR).length > 1;
}
public String getCategory() {
@@ -219,7 +208,6 @@ public class NacosServiceName {
.toString();
}
-
@Override
public boolean equals(Object o) {
if (this == o) {