From bcc3e741b3524be9a369e605d32bedd45f690220 Mon Sep 17 00:00:00 2001 From: Jexy <839447797@qq.com> Date: Mon, 17 Sep 2018 15:50:17 +0800 Subject: [PATCH] code promote: move constant field to Constants class (#2509) --- .../src/main/java/org/apache/dubbo/common/Constants.java | 2 ++ .../apache/dubbo/registry/zookeeper/ZookeeperRegistry.java | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java index 95069306907..4d6e7585cf2 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Constants.java @@ -362,6 +362,8 @@ public class Constants { public final static String PATH_SEPARATOR = "/"; + public final static String PROTOCOL_SEPARATOR = "://"; + public static final String REGISTRY_SEPARATOR = "|"; public static final Pattern REGISTRY_SPLIT_PATTERN = Pattern diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index 86465b6f4b5..43426c7b9f6 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -278,7 +278,7 @@ private List toUrlsWithoutEmpty(URL consumer, List providers) { if (providers != null && !providers.isEmpty()) { for (String provider : providers) { provider = URL.decode(provider); - if (provider.contains("://")) { + if (provider.contains(Constants.PROTOCOL_SEPARATOR)) { URL url = URL.valueOf(provider); if (UrlUtils.isMatch(consumer, url)) { urls.add(url); @@ -292,7 +292,7 @@ private List toUrlsWithoutEmpty(URL consumer, List providers) { private List toUrlsWithEmpty(URL consumer, String path, List providers) { List urls = toUrlsWithoutEmpty(consumer, providers); if (urls == null || urls.isEmpty()) { - int i = path.lastIndexOf('/'); + int i = path.lastIndexOf(Constants.PATH_SEPARATOR); String category = i < 0 ? path : path.substring(i + 1); URL empty = consumer.setProtocol(Constants.EMPTY_PROTOCOL).addParameter(Constants.CATEGORY_KEY, category); urls.add(empty);