You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2021/02/04 06:54:39 UTC
[dubbo-spi-extensions] 04/47: adjust modules
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch 2.7.x
in repository https://gitbox.apache.org/repos/asf/dubbo-spi-extensions.git
commit c340ddf942ade45eef3b230168b9e6f46e5b4b15
Author: ken.lj <ke...@gmail.com>
AuthorDate: Mon May 18 14:40:16 2020 +0800
adjust modules
---
.../dubbo-configcenter-apollo/pom.xml | 52 --
.../support/apollo/ApolloDynamicConfiguration.java | 258 ---------
.../apollo/ApolloDynamicConfigurationFactory.java | 31 -
...config.configcenter.DynamicConfigurationFactory | 1 -
.../apollo/ApolloDynamicConfigurationTest.java | 191 -------
.../src/test/resources/META-INF/app.properties | 1 -
.../src/test/resources/mockdata-dubbo.properties | 2 -
.../dubbo-configcenter-nacos/pom.xml | 45 --
.../support/nacos/NacosDynamicConfiguration.java | 381 -------------
.../nacos/NacosDynamicConfigurationFactory.java | 41 --
...config.configcenter.DynamicConfigurationFactory | 1 -
.../nacos/NacosDynamicConfigurationTest.java | 188 ------
dubbo-spi-configcenter/pom.xml | 2 -
.../dubbo-metadata-report-redis/pom.xml | 57 --
.../metadata/store/redis/RedisMetadataReport.java | 201 -------
.../store/redis/RedisMetadataReportFactory.java | 34 --
...che.dubbo.metadata.report.MetadataReportFactory | 1 -
.../store/redis/RedisMetadata4TstService.java | 28 -
.../store/redis/RedisMetadataReportTest.java | 220 -------
dubbo-spi-metadata/pom.xml | 1 -
dubbo-spi-registry/dubbo-registry-multiple/pom.xml | 65 ---
.../dubbo/registry/multiple/MultipleRegistry.java | 337 -----------
.../registry/multiple/MultipleRegistryFactory.java | 33 --
.../org.apache.dubbo.registry.RegistryFactory | 1 -
.../multiple/MultipleRegistry2S2RTest.java | 213 -------
.../multiple/MultipleRegistryTestUtil.java | 145 -----
dubbo-spi-registry/dubbo-registry-nacos/pom.xml | 83 ---
.../apache/dubbo/registry/nacos/NacosRegistry.java | 629 ---------------------
.../dubbo/registry/nacos/NacosRegistryFactory.java | 42 --
.../registry/nacos/NacosServiceDiscovery.java | 130 -----
.../dubbo/registry/nacos/NacosServiceName.java | 234 --------
.../nacos/util/NacosInstanceManageUtil.java | 67 ---
.../nacos/util/NacosNamingServiceUtils.java | 192 -------
.../org.apache.dubbo.registry.RegistryFactory | 1 -
...g.apache.dubbo.registry.client.ServiceDiscovery | 1 -
dubbo-spi-registry/pom.xml | 2 -
.../dubbo-remoting-zookeeper/pom.xml | 56 --
.../dubbo/remoting/zookeeper/ChildListener.java | 25 -
.../dubbo/remoting/zookeeper/DataListener.java | 25 -
.../apache/dubbo/remoting/zookeeper/EventType.java | 65 ---
.../dubbo/remoting/zookeeper/StateListener.java | 33 --
.../dubbo/remoting/zookeeper/ZookeeperClient.java | 65 ---
.../remoting/zookeeper/ZookeeperTransporter.java | 30 -
.../zookeeper/curator/CuratorZookeeperClient.java | 398 -------------
.../curator/CuratorZookeeperTransporter.java | 30 -
.../zookeeper/support/AbstractZookeeperClient.java | 226 --------
.../support/AbstractZookeeperTransporter.java | 182 ------
...e.dubbo.remoting.zookeeper.ZookeeperTransporter | 1 -
.../curator/CuratorZookeeperClientTest.java | 195 -------
.../curator/CuratorZookeeperTransporterTest.java | 57 --
.../support/AbstractZookeeperTransporterTest.java | 225 --------
dubbo-spi-remoting/pom.xml | 1 -
.../dubbo-serialization-jdk/pom.xml | 43 --
.../serialize/java/CompactedJavaSerialization.java | 59 --
.../serialize/java/CompactedObjectInputStream.java | 64 ---
.../java/CompactedObjectOutputStream.java | 43 --
.../common/serialize/java/JavaObjectInput.java | 91 ---
.../common/serialize/java/JavaObjectOutput.java | 61 --
.../common/serialize/java/JavaSerialization.java | 59 --
.../nativejava/NativeJavaObjectInput.java | 118 ----
.../nativejava/NativeJavaObjectOutput.java | 115 ----
.../nativejava/NativeJavaSerialization.java | 60 --
...org.apache.dubbo.common.serialize.Serialization | 3 -
dubbo-spi-serialization/pom.xml | 1 -
64 files changed, 6242 deletions(-)
diff --git a/dubbo-spi-configcenter/dubbo-configcenter-apollo/pom.xml b/dubbo-spi-configcenter/dubbo-configcenter-apollo/pom.xml
deleted file mode 100644
index 8d3dc0e..0000000
--- a/dubbo-spi-configcenter/dubbo-configcenter-apollo/pom.xml
+++ /dev/null
@@ -1,52 +0,0 @@
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-configcenter</artifactId>
- <version>2.7.7-SNAPSHOT</version>
- </parent>
-
- <artifactId>dubbo-configcenter-apollo</artifactId>
- <packaging>jar</packaging>
- <name>${project.artifactId}</name>
- <description>The Apollo implementation of the configcenter api</description>
- <properties>
- <skip_maven_deploy>false</skip_maven_deploy>
- <apollo_mock_server_version>1.1.1</apollo_mock_server_version>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-common</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>com.ctrip.framework.apollo</groupId>
- <artifactId>apollo-client</artifactId>
- </dependency>
- <dependency>
- <groupId>com.ctrip.framework.apollo</groupId>
- <artifactId>apollo-mockserver</artifactId>
- <version>${apollo_mock_server_version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
\ No newline at end of file
diff --git a/dubbo-spi-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java b/dubbo-spi-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java
deleted file mode 100644
index f191178..0000000
--- a/dubbo-spi-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java
+++ /dev/null
@@ -1,258 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.configcenter.support.apollo;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.config.configcenter.ConfigChangeType;
-import org.apache.dubbo.common.config.configcenter.ConfigChangedEvent;
-import org.apache.dubbo.common.config.configcenter.ConfigurationListener;
-import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
-import org.apache.dubbo.common.logger.Logger;
-import org.apache.dubbo.common.logger.LoggerFactory;
-import org.apache.dubbo.common.utils.StringUtils;
-
-import com.ctrip.framework.apollo.Config;
-import com.ctrip.framework.apollo.ConfigChangeListener;
-import com.ctrip.framework.apollo.ConfigFile;
-import com.ctrip.framework.apollo.ConfigService;
-import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
-import com.ctrip.framework.apollo.enums.ConfigSourceType;
-import com.ctrip.framework.apollo.enums.PropertyChangeType;
-import com.ctrip.framework.apollo.model.ConfigChange;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.stream.Collectors;
-
-import static org.apache.dubbo.common.config.configcenter.Constants.CONFIG_NAMESPACE_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE;
-import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.CHECK_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
-import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
-
-/**
- * Apollo implementation, https://github.com/ctripcorp/apollo
- *
- * Apollo will be used for management of both governance rules and .properties files, by default, these two different
- * kinds of data share the same namespace 'dubbo'. To gain better performance, we recommend separate them by giving
- * namespace and group different values, for example:
- *
- * <dubbo:config-center namespace="governance" group="dubbo" />, 'dubbo=governance' is for governance rules while
- * 'group=dubbo' is for properties files.
- *
- * Please see http://dubbo.apache.org/zh-cn/docs/user/configuration/config-center.html for details.
- */
-public class ApolloDynamicConfiguration implements DynamicConfiguration {
- private static final Logger logger = LoggerFactory.getLogger(ApolloDynamicConfiguration.class);
- private static final String APOLLO_ENV_KEY = "env";
- private static final String APOLLO_ADDR_KEY = "apollo.meta";
- private static final String APOLLO_CLUSTER_KEY = "apollo.cluster";
- private static final String APOLLO_PROTOCOL_PREFIX = "http://";
- private static final String APOLLO_APPLICATION_KEY = "application";
- private static final String APOLLO_APPID_KEY = "app.id";
-
- private URL url;
- private Config dubboConfig;
- private ConfigFile dubboConfigFile;
- private ConcurrentMap<String, ApolloListener> listeners = new ConcurrentHashMap<>();
-
- ApolloDynamicConfiguration(URL url) {
- this.url = url;
- // Instead of using Dubbo's configuration, I would suggest use the original configuration method Apollo provides.
- String configEnv = url.getParameter(APOLLO_ENV_KEY);
- String configAddr = getAddressWithProtocolPrefix(url);
- String configCluster = url.getParameter(CLUSTER_KEY);
- String configAppId = url.getParameter(APOLLO_APPID_KEY);
- if (StringUtils.isEmpty(System.getProperty(APOLLO_ENV_KEY)) && configEnv != null) {
- System.setProperty(APOLLO_ENV_KEY, configEnv);
- }
- if (StringUtils.isEmpty(System.getProperty(APOLLO_ADDR_KEY)) && !ANYHOST_VALUE.equals(url.getHost())) {
- System.setProperty(APOLLO_ADDR_KEY, configAddr);
- }
- if (StringUtils.isEmpty(System.getProperty(APOLLO_CLUSTER_KEY)) && configCluster != null) {
- System.setProperty(APOLLO_CLUSTER_KEY, configCluster);
- }
- if (StringUtils.isEmpty(System.getProperty(APOLLO_APPID_KEY)) && configAppId != null) {
- System.setProperty(APOLLO_APPID_KEY, configAppId);
- }
-
- String namespace = url.getParameter(CONFIG_NAMESPACE_KEY, DEFAULT_GROUP);
- String apolloNamespace = StringUtils.isEmpty(namespace) ? url.getParameter(GROUP_KEY, DEFAULT_GROUP) : namespace;
- dubboConfig = ConfigService.getConfig(apolloNamespace);
- dubboConfigFile = ConfigService.getConfigFile(apolloNamespace, ConfigFileFormat.Properties);
-
- // Decide to fail or to continue when failed to connect to remote server.
- boolean check = url.getParameter(CHECK_KEY, true);
- if (dubboConfig.getSourceType() != ConfigSourceType.REMOTE) {
- if (check) {
- throw new IllegalStateException("Failed to connect to config center, the config center is Apollo, " +
- "the address is: " + (StringUtils.isNotEmpty(configAddr) ? configAddr : configEnv));
- } else {
- logger.warn("Failed to connect to config center, the config center is Apollo, " +
- "the address is: " + (StringUtils.isNotEmpty(configAddr) ? configAddr : configEnv) +
- ", will use the local cache value instead before eventually the connection is established.");
- }
- }
- }
-
- private String getAddressWithProtocolPrefix(URL url) {
- String address = url.getBackupAddress();
- if (StringUtils.isNotEmpty(address)) {
- address = Arrays.stream(COMMA_SPLIT_PATTERN.split(address))
- .map(addr -> {
- if (addr.startsWith(APOLLO_PROTOCOL_PREFIX)) {
- return addr;
- }
- return APOLLO_PROTOCOL_PREFIX + addr;
- })
- .collect(Collectors.joining(","));
- }
- return address;
- }
-
- /**
- * Since all governance rules will lay under dubbo group, this method now always uses the default dubboConfig and
- * ignores the group parameter.
- */
- @Override
- public void addListener(String key, String group, ConfigurationListener listener) {
- ApolloListener apolloListener = listeners.computeIfAbsent(group + key, k -> createTargetListener(key, group));
- apolloListener.addListener(listener);
- dubboConfig.addChangeListener(apolloListener, Collections.singleton(key));
- }
-
- @Override
- public void removeListener(String key, String group, ConfigurationListener listener) {
- ApolloListener apolloListener = listeners.get(group + key);
- if (apolloListener != null) {
- apolloListener.removeListener(listener);
- if (!apolloListener.hasInternalListener()) {
- dubboConfig.removeChangeListener(apolloListener);
- }
- }
- }
-
- @Override
- public String getConfig(String key, String group, long timeout) throws IllegalStateException {
- if (StringUtils.isNotEmpty(group)) {
- if (group.equals(url.getParameter(APPLICATION_KEY))) {
- return ConfigService.getAppConfig().getProperty(key, null);
- } else {
- return ConfigService.getConfig(group).getProperty(key, null);
- }
- }
- return dubboConfig.getProperty(key, null);
- }
-
- /**
- * Recommend specify namespace and group when using Apollo.
- * <p>
- * <dubbo:config-center namespace="governance" group="dubbo" />, 'dubbo=governance' is for governance rules while
- * 'group=dubbo' is for properties files.
- *
- * @param key default value is 'dubbo.properties', currently useless for Apollo.
- * @param group
- * @param timeout
- * @return
- * @throws IllegalStateException
- */
- @Override
- public String getProperties(String key, String group, long timeout) throws IllegalStateException {
- if (StringUtils.isEmpty(group)) {
- return dubboConfigFile.getContent();
- }
- if (group.equals(url.getParameter(APPLICATION_KEY))) {
- return ConfigService.getConfigFile(APOLLO_APPLICATION_KEY, ConfigFileFormat.Properties).getContent();
- }
-
- ConfigFile configFile = ConfigService.getConfigFile(group, ConfigFileFormat.Properties);
- if (configFile == null) {
- throw new IllegalStateException("There is no namespace named " + group + " in Apollo.");
- }
- return configFile.getContent();
- }
-
- /**
- * This method will be used by Configuration to get valid value at runtime.
- * The group is expected to be 'app level', which can be fetched from the 'config.appnamespace' in url if necessary.
- * But I think Apollo's inheritance feature of namespace can solve the problem .
- */
- @Override
- public String getInternalProperty(String key) {
- return dubboConfig.getProperty(key, null);
- }
-
- /**
- * Ignores the group parameter.
- *
- * @param key property key the native listener will listen on
- * @param group to distinguish different set of properties
- * @return
- */
- private ApolloListener createTargetListener(String key, String group) {
- return new ApolloListener();
- }
-
- public class ApolloListener implements ConfigChangeListener {
-
- private Set<ConfigurationListener> listeners = new CopyOnWriteArraySet<>();
-
- ApolloListener() {
- }
-
- @Override
- public void onChange(com.ctrip.framework.apollo.model.ConfigChangeEvent changeEvent) {
- for (String key : changeEvent.changedKeys()) {
- ConfigChange change = changeEvent.getChange(key);
- if ("".equals(change.getNewValue())) {
- logger.warn("an empty rule is received for " + key + ", the current working rule is " +
- change.getOldValue() + ", the empty rule will not take effect.");
- return;
- }
-
- ConfigChangedEvent event = new ConfigChangedEvent(key, change.getNamespace(), change.getNewValue(), getChangeType(change));
- listeners.forEach(listener -> listener.process(event));
- }
- }
-
- private ConfigChangeType getChangeType(ConfigChange change) {
- if (change.getChangeType() == PropertyChangeType.DELETED) {
- return ConfigChangeType.DELETED;
- }
- return ConfigChangeType.MODIFIED;
- }
-
- void addListener(ConfigurationListener configurationListener) {
- this.listeners.add(configurationListener);
- }
-
- void removeListener(ConfigurationListener configurationListener) {
- this.listeners.remove(configurationListener);
- }
-
- boolean hasInternalListener() {
- return listeners != null && listeners.size() > 0;
- }
- }
-
-}
diff --git a/dubbo-spi-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfigurationFactory.java b/dubbo-spi-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfigurationFactory.java
deleted file mode 100644
index 6a8ce30..0000000
--- a/dubbo-spi-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfigurationFactory.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.configcenter.support.apollo;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.config.configcenter.AbstractDynamicConfigurationFactory;
-import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
-
-/**
- *
- */
-public class ApolloDynamicConfigurationFactory extends AbstractDynamicConfigurationFactory {
- @Override
- protected DynamicConfiguration createDynamicConfiguration(URL url) {
- return new ApolloDynamicConfiguration(url);
- }
-}
diff --git a/dubbo-spi-configcenter/dubbo-configcenter-apollo/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory b/dubbo-spi-configcenter/dubbo-configcenter-apollo/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory
deleted file mode 100644
index 0ea08c5..0000000
--- a/dubbo-spi-configcenter/dubbo-configcenter-apollo/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory
+++ /dev/null
@@ -1 +0,0 @@
-apollo=org.apache.dubbo.configcenter.support.apollo.ApolloDynamicConfigurationFactory
\ No newline at end of file
diff --git a/dubbo-spi-configcenter/dubbo-configcenter-apollo/src/test/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfigurationTest.java b/dubbo-spi-configcenter/dubbo-configcenter-apollo/src/test/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfigurationTest.java
deleted file mode 100644
index ca48bd6..0000000
--- a/dubbo-spi-configcenter/dubbo-configcenter-apollo/src/test/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfigurationTest.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.configcenter.support.apollo;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.config.configcenter.ConfigChangeType;
-import org.apache.dubbo.common.config.configcenter.ConfigurationListener;
-
-import com.ctrip.framework.apollo.mockserver.EmbeddedApollo;
-import com.google.common.util.concurrent.SettableFuture;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.Properties;
-import java.util.Random;
-import java.util.concurrent.TimeUnit;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.fail;
-
-/**
- * Apollo dynamic configuration mock test.
- * Notice: EmbeddedApollo(apollo mock server) only support < junit5, please not upgrade the junit version in this UT,
- * the junit version in this UT is junit4, and the dependency comes from apollo-mockserver.
- */
-public class ApolloDynamicConfigurationTest {
- private static final String SESSION_TIMEOUT_KEY = "session";
- private static final String DEFAULT_NAMESPACE = "dubbo";
- private static ApolloDynamicConfiguration apolloDynamicConfiguration;
- private static URL url;
-
- /**
- * The constant embeddedApollo.
- */
- @ClassRule
- public static EmbeddedApollo embeddedApollo = new EmbeddedApollo();
-
- /**
- * Sets up.
- */
- @Before
- public void setUp() {
- String apolloUrl = System.getProperty("apollo.configService");
- String urlForDubbo = "apollo://" + apolloUrl.substring(apolloUrl.lastIndexOf("/") + 1) + "/org.apache.dubbo.apollo.testService?namespace=dubbo&check=true";
- url = URL.valueOf(urlForDubbo).addParameter(SESSION_TIMEOUT_KEY, 15000);
- }
-
-// /**
-// * Embedded Apollo does not work as expected.
-// */
-// @Test
-// public void testProperties() {
-// URL url = this.url.addParameter(GROUP_KEY, "dubbo")
-// .addParameter("namespace", "governance");
-//
-// apolloDynamicConfiguration = new ApolloDynamicConfiguration(url);
-// putData("dubbo", "dubbo.registry.address", "zookeeper://127.0.0.1:2181");
-// assertEquals("zookeeper://127.0.0.1:2181", apolloDynamicConfiguration.getProperties(null, "dubbo"));
-//
-// putData("governance", "router.tag", "router tag rule");
-// assertEquals("router tag rule", apolloDynamicConfiguration.getConfig("router.tag", "governance"));
-//
-// }
-
- /**
- * Test get rule.
- */
- @Test
- public void testGetRule() {
- String mockKey = "mockKey1";
- String mockValue = String.valueOf(new Random().nextInt());
- putMockRuleData(mockKey, mockValue, DEFAULT_NAMESPACE);
- apolloDynamicConfiguration = new ApolloDynamicConfiguration(url);
- assertEquals(mockValue, apolloDynamicConfiguration.getConfig(mockKey, DEFAULT_NAMESPACE, 3000L));
-
- mockKey = "notExistKey";
- assertNull(apolloDynamicConfiguration.getConfig(mockKey, DEFAULT_NAMESPACE, 3000L));
- }
-
- /**
- * Test get internal property.
- *
- * @throws InterruptedException the interrupted exception
- */
- @Test
- public void testGetInternalProperty() throws InterruptedException {
- String mockKey = "mockKey2";
- String mockValue = String.valueOf(new Random().nextInt());
- putMockRuleData(mockKey, mockValue, DEFAULT_NAMESPACE);
- TimeUnit.MILLISECONDS.sleep(1000);
- apolloDynamicConfiguration = new ApolloDynamicConfiguration(url);
- assertEquals(mockValue, apolloDynamicConfiguration.getInternalProperty(mockKey));
-
- mockValue = "mockValue2";
- System.setProperty(mockKey, mockValue);
- assertEquals(mockValue, apolloDynamicConfiguration.getInternalProperty(mockKey));
-
- mockKey = "notExistKey";
- assertNull(apolloDynamicConfiguration.getInternalProperty(mockKey));
- }
-
- /**
- * Test add listener.
- *
- * @throws Exception the exception
- */
- @Test
- public void testAddListener() throws Exception {
- String mockKey = "mockKey3";
- String mockValue = String.valueOf(new Random().nextInt());
-
- final SettableFuture<org.apache.dubbo.common.config.configcenter.ConfigChangedEvent> future = SettableFuture.create();
-
- apolloDynamicConfiguration = new ApolloDynamicConfiguration(url);
-
- apolloDynamicConfiguration.addListener(mockKey, DEFAULT_NAMESPACE, new ConfigurationListener() {
- @Override
- public void process(org.apache.dubbo.common.config.configcenter.ConfigChangedEvent event) {
- future.set(event);
- }
- });
-
- putData(mockKey, mockValue);
- org.apache.dubbo.common.config.configcenter.ConfigChangedEvent result = future.get(3000, TimeUnit.MILLISECONDS);
- assertEquals(mockValue, result.getContent());
- assertEquals(mockKey, result.getKey());
- assertEquals(ConfigChangeType.MODIFIED, result.getChangeType());
- }
-
- private static void putData(String namespace, String key, String value) {
- embeddedApollo.addOrModifyProperty(namespace, key, value);
- }
-
- private static void putData(String key, String value) {
- embeddedApollo.addOrModifyProperty(DEFAULT_NAMESPACE, key, value);
- }
-
- private static void putMockRuleData(String key, String value, String group) {
- String fileName = ApolloDynamicConfigurationTest.class.getResource("/").getPath() + "mockdata-" + group + ".properties";
- putMockData(key, value, fileName);
- }
-
- private static void putMockData(String key, String value, String fileName) {
- Properties pro = new Properties();
- FileOutputStream oFile = null;
- try {
- oFile = new FileOutputStream(fileName);
- pro.setProperty(key, value);
- pro.store(oFile, "put mock data");
- } catch (IOException exx) {
- fail(exx.getMessage());
-
- } finally {
- if (null != oFile) {
- try {
- oFile.close();
- } catch (IOException e) {
- fail(e.getMessage());
- }
- }
- }
- }
-
- /**
- * Tear down.
- */
- @After
- public void tearDown() {
-
- }
-
-}
\ No newline at end of file
diff --git a/dubbo-spi-configcenter/dubbo-configcenter-apollo/src/test/resources/META-INF/app.properties b/dubbo-spi-configcenter/dubbo-configcenter-apollo/src/test/resources/META-INF/app.properties
deleted file mode 100644
index 4d963e2..0000000
--- a/dubbo-spi-configcenter/dubbo-configcenter-apollo/src/test/resources/META-INF/app.properties
+++ /dev/null
@@ -1 +0,0 @@
-app.id=someAppId
\ No newline at end of file
diff --git a/dubbo-spi-configcenter/dubbo-configcenter-apollo/src/test/resources/mockdata-dubbo.properties b/dubbo-spi-configcenter/dubbo-configcenter-apollo/src/test/resources/mockdata-dubbo.properties
deleted file mode 100644
index f995a3b..0000000
--- a/dubbo-spi-configcenter/dubbo-configcenter-apollo/src/test/resources/mockdata-dubbo.properties
+++ /dev/null
@@ -1,2 +0,0 @@
-key1=value1
-key2=value2
\ No newline at end of file
diff --git a/dubbo-spi-configcenter/dubbo-configcenter-nacos/pom.xml b/dubbo-spi-configcenter/dubbo-configcenter-nacos/pom.xml
deleted file mode 100644
index 42dcc69..0000000
--- a/dubbo-spi-configcenter/dubbo-configcenter-nacos/pom.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-configcenter</artifactId>
- <version>2.7.7-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>dubbo-configcenter-nacos</artifactId>
- <packaging>jar</packaging>
- <name>${project.artifactId}</name>
- <description>The nacos implementation of the config-center api</description>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-common</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>com.alibaba.nacos</groupId>
- <artifactId>nacos-client</artifactId>
- </dependency>
- </dependencies>
-</project>
diff --git a/dubbo-spi-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java b/dubbo-spi-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java
deleted file mode 100644
index 2227015..0000000
--- a/dubbo-spi-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java
+++ /dev/null
@@ -1,381 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.dubbo.configcenter.support.nacos;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.config.configcenter.ConfigChangeType;
-import org.apache.dubbo.common.config.configcenter.ConfigChangedEvent;
-import org.apache.dubbo.common.config.configcenter.ConfigurationListener;
-import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
-import org.apache.dubbo.common.logger.Logger;
-import org.apache.dubbo.common.logger.LoggerFactory;
-import org.apache.dubbo.common.utils.StringUtils;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.alibaba.nacos.api.NacosFactory;
-import com.alibaba.nacos.api.config.ConfigService;
-import com.alibaba.nacos.api.config.listener.AbstractSharedListener;
-import com.alibaba.nacos.api.exception.NacosException;
-import com.alibaba.nacos.client.config.http.HttpAgent;
-import com.alibaba.nacos.client.config.impl.HttpSimpleClient;
-
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.concurrent.Executor;
-import java.util.stream.Stream;
-
-import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY;
-import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME;
-import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT;
-import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_RETRY_TIME;
-import static com.alibaba.nacos.api.PropertyKeyConst.CONTEXT_PATH;
-import static com.alibaba.nacos.api.PropertyKeyConst.ENABLE_REMOTE_SYNC_CONFIG;
-import static com.alibaba.nacos.api.PropertyKeyConst.ENCODE;
-import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT;
-import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT_PORT;
-import static com.alibaba.nacos.api.PropertyKeyConst.IS_USE_CLOUD_NAMESPACE_PARSING;
-import static com.alibaba.nacos.api.PropertyKeyConst.IS_USE_ENDPOINT_PARSING_RULE;
-import static com.alibaba.nacos.api.PropertyKeyConst.MAX_RETRY;
-import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
-import static com.alibaba.nacos.api.PropertyKeyConst.NAMING_CLIENT_BEAT_THREAD_COUNT;
-import static com.alibaba.nacos.api.PropertyKeyConst.NAMING_LOAD_CACHE_AT_START;
-import static com.alibaba.nacos.api.PropertyKeyConst.NAMING_POLLING_THREAD_COUNT;
-import static com.alibaba.nacos.api.PropertyKeyConst.RAM_ROLE_NAME;
-import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY;
-import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
-import static com.alibaba.nacos.client.naming.utils.UtilAndComs.NACOS_NAMING_LOG_NAME;
-import static java.util.Arrays.asList;
-import static java.util.Collections.emptyList;
-import static org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY;
-import static org.apache.dubbo.common.utils.StringUtils.HYPHEN_CHAR;
-import static org.apache.dubbo.common.utils.StringUtils.SLASH_CHAR;
-
-/**
- * The nacos implementation of {@link DynamicConfiguration}
- */
-public class NacosDynamicConfiguration implements DynamicConfiguration {
-
- private static final String GET_CONFIG_KEYS_PATH = "/v1/cs/configs";
-
- private final Logger logger = LoggerFactory.getLogger(getClass());
- /**
- * the default timeout in millis to get config from nacos
- */
- private static final long DEFAULT_TIMEOUT = 5000L;
-
- private Properties nacosProperties;
-
- /**
- * The nacos configService
- */
- private final ConfigService configService;
-
- private HttpAgent httpAgent;
-
- /**
- * The map store the key to {@link NacosConfigListener} mapping
- */
- private final ConcurrentMap<String, NacosConfigListener> watchListenerMap;
-
- NacosDynamicConfiguration(URL url) {
- this.nacosProperties = buildNacosProperties(url);
- this.configService = buildConfigService(url);
- this.httpAgent = getHttpAgent(configService);
- watchListenerMap = new ConcurrentHashMap<>();
- }
-
- private ConfigService buildConfigService(URL url) {
- ConfigService configService = null;
- try {
- configService = NacosFactory.createConfigService(nacosProperties);
- } catch (NacosException e) {
- if (logger.isErrorEnabled()) {
- logger.error(e.getErrMsg(), e);
- }
- throw new IllegalStateException(e);
- }
- return configService;
- }
-
- private HttpAgent getHttpAgent(ConfigService configService) {
- HttpAgent agent = null;
- try {
- Field field = configService.getClass().getDeclaredField("agent");
- field.setAccessible(true);
- agent = (HttpAgent) field.get(configService);
- } catch (Exception e) {
- throw new IllegalStateException(e);
- }
- return agent;
- }
-
- private Properties buildNacosProperties(URL url) {
- Properties properties = new Properties();
- setServerAddr(url, properties);
- setProperties(url, properties);
- return properties;
- }
-
- private void setServerAddr(URL url, Properties properties) {
- StringBuilder serverAddrBuilder =
- new StringBuilder(url.getHost()) // Host
- .append(":")
- .append(url.getPort()); // Port
-
- // Append backup parameter as other servers
- String backup = url.getParameter(BACKUP_KEY);
- if (backup != null) {
- serverAddrBuilder.append(",").append(backup);
- }
- String serverAddr = serverAddrBuilder.toString();
- properties.put(SERVER_ADDR, serverAddr);
- }
-
- private static void setProperties(URL url, Properties properties) {
- putPropertyIfAbsent(url, properties, NACOS_NAMING_LOG_NAME);
- putPropertyIfAbsent(url, properties, IS_USE_CLOUD_NAMESPACE_PARSING);
- putPropertyIfAbsent(url, properties, IS_USE_ENDPOINT_PARSING_RULE);
- putPropertyIfAbsent(url, properties, ENDPOINT);
- putPropertyIfAbsent(url, properties, ENDPOINT_PORT);
- putPropertyIfAbsent(url, properties, NAMESPACE);
- putPropertyIfAbsent(url, properties, ACCESS_KEY);
- putPropertyIfAbsent(url, properties, SECRET_KEY);
- putPropertyIfAbsent(url, properties, RAM_ROLE_NAME);
- putPropertyIfAbsent(url, properties, CONTEXT_PATH);
- putPropertyIfAbsent(url, properties, CLUSTER_NAME);
- putPropertyIfAbsent(url, properties, ENCODE);
- putPropertyIfAbsent(url, properties, CONFIG_LONG_POLL_TIMEOUT);
- putPropertyIfAbsent(url, properties, CONFIG_RETRY_TIME);
- putPropertyIfAbsent(url, properties, MAX_RETRY);
- putPropertyIfAbsent(url, properties, ENABLE_REMOTE_SYNC_CONFIG);
- putPropertyIfAbsent(url, properties, NAMING_LOAD_CACHE_AT_START, "true");
- putPropertyIfAbsent(url, properties, NAMING_CLIENT_BEAT_THREAD_COUNT);
- putPropertyIfAbsent(url, properties, NAMING_POLLING_THREAD_COUNT);
- }
-
- private static void putPropertyIfAbsent(URL url, Properties properties, String propertyName) {
- String propertyValue = url.getParameter(propertyName);
- if (StringUtils.isNotEmpty(propertyValue)) {
- properties.setProperty(propertyName, propertyValue);
- }
- }
-
- private static void putPropertyIfAbsent(URL url, Properties properties, String propertyName, String defaultValue) {
- String propertyValue = url.getParameter(propertyName);
- if (StringUtils.isNotEmpty(propertyValue)) {
- properties.setProperty(propertyName, propertyValue);
- } else {
- properties.setProperty(propertyName, defaultValue);
- }
- }
-
- /**
- * Ignores the group parameter.
- *
- * @param key property key the native listener will listen on
- * @param group to distinguish different set of properties
- * @return
- */
- private NacosConfigListener createTargetListener(String key, String group) {
- NacosConfigListener configListener = new NacosConfigListener();
- configListener.fillContext(key, group);
- return configListener;
- }
-
- @Override
- public void addListener(String key, String group, ConfigurationListener listener) {
- String resolvedGroup = resolveGroup(group);
- String listenerKey = buildListenerKey(key, group);
- NacosConfigListener nacosConfigListener = watchListenerMap.computeIfAbsent(listenerKey, k -> createTargetListener(key, resolvedGroup));
- nacosConfigListener.addListener(listener);
- try {
- configService.addListener(key, resolvedGroup, nacosConfigListener);
- } catch (NacosException e) {
- logger.error(e.getMessage());
- }
- }
-
- @Override
- public void removeListener(String key, String group, ConfigurationListener listener) {
- String listenerKey = buildListenerKey(key, group);
- NacosConfigListener eventListener = watchListenerMap.get(listenerKey);
- if (eventListener != null) {
- eventListener.removeListener(listener);
- }
- }
-
- @Override
- public String getConfig(String key, String group, long timeout) throws IllegalStateException {
- String resolvedGroup = resolveGroup(group);
- try {
- long nacosTimeout = timeout < 0 ? getDefaultTimeout() : timeout;
- if (StringUtils.isEmpty(resolvedGroup)) {
- resolvedGroup = DEFAULT_GROUP;
- }
- return configService.getConfig(key, resolvedGroup, nacosTimeout);
- } catch (NacosException e) {
- logger.error(e.getMessage());
- }
- return null;
- }
-
- @Override
- public Object getInternalProperty(String key) {
- try {
- return configService.getConfig(key, DEFAULT_GROUP, getDefaultTimeout());
- } catch (NacosException e) {
- logger.error(e.getMessage());
- }
- return null;
- }
-
- @Override
- public boolean publishConfig(String key, String group, String content) {
- boolean published = false;
- String resolvedGroup = resolveGroup(group);
- try {
- String value = configService.getConfig(key, resolvedGroup, getDefaultTimeout());
- if (StringUtils.isNotEmpty(value)) {
- content = value + "," + content;
- }
- published = configService.publishConfig(key, resolvedGroup, content);
- } catch (NacosException e) {
- logger.error(e.getErrMsg());
- }
- return published;
- }
-
- @Override
- public long getDefaultTimeout() {
- return DEFAULT_TIMEOUT;
- }
-
- /**
- * TODO Nacos does not support atomic update of the value mapped to a key.
- *
- * @param key
- * @param group the specified group
- * @return
- */
- @Override
- public SortedSet<String> getConfigKeys(String group) {
- // TODO use Nacos Client API to replace HTTP Open API
- SortedSet<String> keys = new TreeSet<>();
- try {
- List<String> paramsValues = asList(
- "search", "accurate",
- "dataId", "",
- "group", resolveGroup(group),
- "pageNo", "1",
- "pageSize", String.valueOf(Integer.MAX_VALUE)
- );
- String encoding = getProperty(ENCODE, "UTF-8");
- HttpSimpleClient.HttpResult result = httpAgent.httpGet(GET_CONFIG_KEYS_PATH, emptyList(), paramsValues, encoding, 5 * 1000);
- Stream<String> keysStream = toKeysStream(result.content);
- keysStream.forEach(keys::add);
- } catch (IOException e) {
- if (logger.isErrorEnabled()) {
- logger.error(e.getMessage(), e);
- }
- }
- return keys;
- }
-
- private Stream<String> toKeysStream(String content) {
- JSONObject jsonObject = JSON.parseObject(content);
- JSONArray pageItems = jsonObject.getJSONArray("pageItems");
- return pageItems.stream()
- .map(object -> (JSONObject) object)
- .map(json -> json.getString("dataId"));
- }
-
- private String getProperty(String name, String defaultValue) {
- return nacosProperties.getProperty(name, defaultValue);
- }
-
- public class NacosConfigListener extends AbstractSharedListener {
-
- private Set<ConfigurationListener> listeners = new CopyOnWriteArraySet<>();
- /**
- * cache data to store old value
- */
- private Map<String, String> cacheData = new ConcurrentHashMap<>();
-
- @Override
- public Executor getExecutor() {
- return null;
- }
-
- /**
- * receive
- *
- * @param dataId data ID
- * @param group group
- * @param configInfo content
- */
- @Override
- public void innerReceive(String dataId, String group, String configInfo) {
- String oldValue = cacheData.get(dataId);
- ConfigChangedEvent event = new ConfigChangedEvent(dataId, group, configInfo, getChangeType(configInfo, oldValue));
- if (configInfo == null) {
- cacheData.remove(dataId);
- } else {
- cacheData.put(dataId, configInfo);
- }
- listeners.forEach(listener -> listener.process(event));
- }
-
- void addListener(ConfigurationListener configurationListener) {
-
- this.listeners.add(configurationListener);
- }
-
- void removeListener(ConfigurationListener configurationListener) {
- this.listeners.remove(configurationListener);
- }
-
- private ConfigChangeType getChangeType(String configInfo, String oldValue) {
- if (StringUtils.isBlank(configInfo)) {
- return ConfigChangeType.DELETED;
- }
- if (StringUtils.isBlank(oldValue)) {
- return ConfigChangeType.ADDED;
- }
- return ConfigChangeType.MODIFIED;
- }
- }
-
- protected String buildListenerKey(String key, String group) {
- return key + HYPHEN_CHAR + resolveGroup(group);
- }
-
- protected String resolveGroup(String group) {
- return group.replace(SLASH_CHAR, HYPHEN_CHAR);
- }
-}
diff --git a/dubbo-spi-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationFactory.java b/dubbo-spi-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationFactory.java
deleted file mode 100644
index 61c02b4..0000000
--- a/dubbo-spi-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationFactory.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.dubbo.configcenter.support.nacos;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.config.configcenter.AbstractDynamicConfigurationFactory;
-import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
-import org.apache.dubbo.common.constants.CommonConstants;
-
-import com.alibaba.nacos.api.PropertyKeyConst;
-
-/**
- * The nacos implementation of {@link AbstractDynamicConfigurationFactory}
- */
-public class NacosDynamicConfigurationFactory extends AbstractDynamicConfigurationFactory {
-
- @Override
- protected DynamicConfiguration createDynamicConfiguration(URL url) {
- URL nacosURL = url;
- if (CommonConstants.DUBBO.equals(url.getParameter(PropertyKeyConst.NAMESPACE))) {
- // Nacos use empty string as default name space, replace default namespace "dubbo" to ""
- nacosURL = url.removeParameter(PropertyKeyConst.NAMESPACE);
- }
- return new NacosDynamicConfiguration(nacosURL);
- }
-}
diff --git a/dubbo-spi-configcenter/dubbo-configcenter-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory b/dubbo-spi-configcenter/dubbo-configcenter-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory
deleted file mode 100644
index b9c75a4..0000000
--- a/dubbo-spi-configcenter/dubbo-configcenter-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory
+++ /dev/null
@@ -1 +0,0 @@
-nacos=org.apache.dubbo.configcenter.support.nacos.NacosDynamicConfigurationFactory
\ No newline at end of file
diff --git a/dubbo-spi-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java b/dubbo-spi-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java
deleted file mode 100644
index afafc1c..0000000
--- a/dubbo-spi-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.dubbo.configcenter.support.nacos;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.config.configcenter.ConfigChangedEvent;
-import org.apache.dubbo.common.config.configcenter.ConfigurationListener;
-import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
-
-import com.alibaba.nacos.api.NacosFactory;
-import com.alibaba.nacos.api.config.ConfigService;
-import com.alibaba.nacos.api.exception.NacosException;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Disabled;
-import org.junit.jupiter.api.Test;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.SortedSet;
-import java.util.concurrent.CountDownLatch;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-
-/**
- * Unit test for nacos config center support
- */
-//FIXME: waiting for embedded Nacos suport, then we can open the switch.
-@Disabled("https://github.com/alibaba/nacos/issues/1188")
-public class NacosDynamicConfigurationTest {
- private static final String SESSION_TIMEOUT_KEY = "session";
-
- private static NacosDynamicConfiguration config;
-
- /**
- * A test client to put data to Nacos server for testing purpose
- */
- private static ConfigService nacosClient;
-
- @Test
- public void testGetConfig() throws Exception {
- put("org.apache.dubbo.nacos.testService.configurators", "hello");
- Thread.sleep(200);
- put("dubbo.properties", "test", "aaa=bbb");
- Thread.sleep(200);
- put("org.apache.dubbo.demo.DemoService:1.0.0.test:xxxx.configurators", "helloworld");
- Thread.sleep(200);
- Assertions.assertEquals("hello", config.getConfig("org.apache.dubbo.nacos.testService.configurators", DynamicConfiguration.DEFAULT_GROUP));
- Assertions.assertEquals("aaa=bbb", config.getConfig("dubbo.properties", "test"));
- Assertions.assertEquals("helloworld", config.getConfig("org.apache.dubbo.demo.DemoService:1.0.0.test:xxxx.configurators", DynamicConfiguration.DEFAULT_GROUP));
- }
-
- @Test
- public void testAddListener() throws Exception {
- CountDownLatch latch = new CountDownLatch(4);
- TestListener listener1 = new TestListener(latch);
- TestListener listener2 = new TestListener(latch);
- TestListener listener3 = new TestListener(latch);
- TestListener listener4 = new TestListener(latch);
-
-
- config.addListener("AService.configurators", listener1);
- config.addListener("AService.configurators", listener2);
- config.addListener("testapp.tag-router", listener3);
- config.addListener("testapp.tag-router", listener4);
-
- put("AService.configurators", "new value1");
- Thread.sleep(200);
- put("testapp.tag-router", "new value2");
- Thread.sleep(200);
- put("testapp", "new value3");
- Thread.sleep(5000);
-
- latch.await();
-
- Assertions.assertEquals(1, listener1.getCount("AService.configurators"));
- Assertions.assertEquals(1, listener2.getCount("AService.configurators"));
- Assertions.assertEquals(1, listener3.getCount("testapp.tag-router"));
- Assertions.assertEquals(1, listener4.getCount("testapp.tag-router"));
-
- Assertions.assertEquals("new value1", listener1.getValue());
- Assertions.assertEquals("new value1", listener2.getValue());
- Assertions.assertEquals("new value2", listener3.getValue());
- Assertions.assertEquals("new value2", listener4.getValue());
-
- }
-
- @Test
- public void testGetConfigKeys() {
-
- put("key1", "a");
- put("key2", "b");
-
- SortedSet<String> keys = config.getConfigKeys(DynamicConfiguration.DEFAULT_GROUP);
-
- Assertions.assertFalse(keys.isEmpty());
-
- }
-
- private void put(String key, String value) {
- put(key, DynamicConfiguration.DEFAULT_GROUP, value);
- }
-
- private void put(String key, String group, String value) {
- try {
- nacosClient.publishConfig(key, group, value);
- } catch (Exception e) {
- System.out.println("Error put value to nacos.");
- }
- }
-
- @BeforeAll
- public static void setUp() {
- String urlForDubbo = "nacos://" + "127.0.0.1:8848" + "/org.apache.dubbo.nacos.testService";
- // timeout in 15 seconds.
- URL url = URL.valueOf(urlForDubbo)
- .addParameter(SESSION_TIMEOUT_KEY, 15000);
- config = new NacosDynamicConfiguration(url);
-
-
- try {
- nacosClient = NacosFactory.createConfigService("127.0.0.1:8848");
- } catch (NacosException e) {
- e.printStackTrace();
- }
- }
-
- @Test
- public void testPublishConfig() {
- String key = "user-service";
- String group = "org.apache.dubbo.service.UserService";
- String content = "test";
-
- assertTrue(config.publishConfig(key, group, content));
- assertEquals("test", config.getProperties(key, group));
- }
-
- @AfterAll
- public static void tearDown() {
-
- }
-
- private class TestListener implements ConfigurationListener {
- private CountDownLatch latch;
- private String value;
- private Map<String, Integer> countMap = new HashMap<>();
-
- public TestListener(CountDownLatch latch) {
- this.latch = latch;
- }
-
- @Override
- public void process(ConfigChangedEvent event) {
- System.out.println(this + ": " + event);
- Integer count = countMap.computeIfAbsent(event.getKey(), k -> 0);
- countMap.put(event.getKey(), ++count);
- value = event.getContent();
- latch.countDown();
- }
-
- public int getCount(String key) {
- return countMap.get(key);
- }
-
- public String getValue() {
- return value;
- }
- }
-
-}
diff --git a/dubbo-spi-configcenter/pom.xml b/dubbo-spi-configcenter/pom.xml
index 0e3813a..458b80b 100644
--- a/dubbo-spi-configcenter/pom.xml
+++ b/dubbo-spi-configcenter/pom.xml
@@ -30,9 +30,7 @@
</properties>
<modules>
- <module>dubbo-configcenter-apollo</module>
<module>dubbo-configcenter-consul</module>
<module>dubbo-configcenter-etcd</module>
- <module>dubbo-configcenter-nacos</module>
</modules>
</project>
diff --git a/dubbo-spi-metadata/dubbo-metadata-report-redis/pom.xml b/dubbo-spi-metadata/dubbo-metadata-report-redis/pom.xml
deleted file mode 100644
index 70bd32d..0000000
--- a/dubbo-spi-metadata/dubbo-metadata-report-redis/pom.xml
+++ /dev/null
@@ -1,57 +0,0 @@
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-metadata</artifactId>
- <version>2.7.7-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>dubbo-metadata-report-redis</artifactId>
- <properties>
- <jedis.version>2.9.0</jedis.version>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-metadata-api</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>redis.clients</groupId>
- <artifactId>jedis</artifactId>
- <version>${jedis.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.github.kstyrc</groupId>
- <artifactId>embedded-redis</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
diff --git a/dubbo-spi-metadata/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java b/dubbo-spi-metadata/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java
deleted file mode 100644
index c00be04..0000000
--- a/dubbo-spi-metadata/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.metadata.store.redis;
-
-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.StringUtils;
-import org.apache.dubbo.metadata.report.identifier.BaseMetadataIdentifier;
-import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
-import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
-import org.apache.dubbo.metadata.report.identifier.ServiceMetadataIdentifier;
-import org.apache.dubbo.metadata.report.identifier.SubscriberMetadataIdentifier;
-import org.apache.dubbo.metadata.report.support.AbstractMetadataReport;
-import org.apache.dubbo.rpc.RpcException;
-
-import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
-import redis.clients.jedis.HostAndPort;
-import redis.clients.jedis.Jedis;
-import redis.clients.jedis.JedisCluster;
-import redis.clients.jedis.JedisPool;
-import redis.clients.jedis.JedisPoolConfig;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY;
-import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
-import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
-import static org.apache.dubbo.metadata.MetadataConstants.META_DATA_STORE_TAG;
-
-/**
- * RedisMetadataReport
- */
-public class RedisMetadataReport extends AbstractMetadataReport {
-
- private final static String REDIS_DATABASE_KEY = "database";
- private final static Logger logger = LoggerFactory.getLogger(RedisMetadataReport.class);
-
- JedisPool pool;
- Set<HostAndPort> jedisClusterNodes;
- private int timeout;
- private String password;
-
-
- public RedisMetadataReport(URL url) {
- super(url);
- timeout = url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT);
- if (url.getParameter(CLUSTER_KEY, false)) {
- jedisClusterNodes = new HashSet<HostAndPort>();
- List<URL> urls = url.getBackupUrls();
- for (URL tmpUrl : urls) {
- jedisClusterNodes.add(new HostAndPort(tmpUrl.getHost(), tmpUrl.getPort()));
- }
- } else {
- int database = url.getParameter(REDIS_DATABASE_KEY, 0);
- pool = new JedisPool(new JedisPoolConfig(), url.getHost(), url.getPort(), timeout, url.getPassword(), database);
- }
- }
-
- @Override
- protected void doStoreProviderMetadata(MetadataIdentifier providerMetadataIdentifier, String serviceDefinitions) {
- this.storeMetadata(providerMetadataIdentifier, serviceDefinitions);
- }
-
- @Override
- protected void doStoreConsumerMetadata(MetadataIdentifier consumerMetadataIdentifier, String value) {
- this.storeMetadata(consumerMetadataIdentifier, value);
- }
-
- @Override
- protected void doSaveMetadata(ServiceMetadataIdentifier serviceMetadataIdentifier, URL url) {
- this.storeMetadata(serviceMetadataIdentifier, URL.encode(url.toFullString()));
- }
-
- @Override
- protected void doRemoveMetadata(ServiceMetadataIdentifier serviceMetadataIdentifier) {
- this.deleteMetadata(serviceMetadataIdentifier);
- }
-
- @Override
- protected List<String> doGetExportedURLs(ServiceMetadataIdentifier metadataIdentifier) {
- String content = getMetadata(metadataIdentifier);
- if (StringUtils.isEmpty(content)) {
- return Collections.emptyList();
- }
- return new ArrayList<String>(Arrays.asList(URL.decode(content)));
- }
-
- @Override
- protected void doSaveSubscriberData(SubscriberMetadataIdentifier subscriberMetadataIdentifier, String urlListStr) {
- this.storeMetadata(subscriberMetadataIdentifier, urlListStr);
- }
-
- @Override
- protected String doGetSubscribedURLs(SubscriberMetadataIdentifier subscriberMetadataIdentifier) {
- return this.getMetadata(subscriberMetadataIdentifier);
- }
-
- @Override
- public String getServiceDefinition(MetadataIdentifier metadataIdentifier) {
- return this.getMetadata(metadataIdentifier);
- }
-
- private void storeMetadata(BaseMetadataIdentifier metadataIdentifier, String v) {
- if (pool != null) {
- storeMetadataStandalone(metadataIdentifier, v);
- } else {
- storeMetadataInCluster(metadataIdentifier, v);
- }
- }
-
- private void storeMetadataInCluster(BaseMetadataIdentifier metadataIdentifier, String v) {
- try (JedisCluster jedisCluster = new JedisCluster(jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig())) {
- jedisCluster.set(metadataIdentifier.getIdentifierKey() + META_DATA_STORE_TAG, v);
- } catch (Throwable e) {
- logger.error("Failed to put " + metadataIdentifier + " to redis cluster " + v + ", cause: " + e.getMessage(), e);
- throw new RpcException("Failed to put " + metadataIdentifier + " to redis cluster " + v + ", cause: " + e.getMessage(), e);
- }
- }
-
- private void storeMetadataStandalone(BaseMetadataIdentifier metadataIdentifier, String v) {
- try (Jedis jedis = pool.getResource()) {
- jedis.set(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY), v);
- } catch (Throwable e) {
- logger.error("Failed to put " + metadataIdentifier + " to redis " + v + ", cause: " + e.getMessage(), e);
- throw new RpcException("Failed to put " + metadataIdentifier + " to redis " + v + ", cause: " + e.getMessage(), e);
- }
- }
-
- private void deleteMetadata(BaseMetadataIdentifier metadataIdentifier) {
- if (pool != null) {
- deleteMetadataStandalone(metadataIdentifier);
- } else {
- deleteMetadataInCluster(metadataIdentifier);
- }
- }
-
- private void deleteMetadataInCluster(BaseMetadataIdentifier metadataIdentifier) {
- try (JedisCluster jedisCluster = new JedisCluster(jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig())) {
- jedisCluster.del(metadataIdentifier.getIdentifierKey() + META_DATA_STORE_TAG);
- } catch (Throwable e) {
- logger.error("Failed to delete " + metadataIdentifier + " from redis cluster , cause: " + e.getMessage(), e);
- throw new RpcException("Failed to delete " + metadataIdentifier + " from redis cluster , cause: " + e.getMessage(), e);
- }
- }
-
- private void deleteMetadataStandalone(BaseMetadataIdentifier metadataIdentifier) {
- try (Jedis jedis = pool.getResource()) {
- jedis.del(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
- } catch (Throwable e) {
- logger.error("Failed to delete " + metadataIdentifier + " from redis , cause: " + e.getMessage(), e);
- throw new RpcException("Failed to delete " + metadataIdentifier + " from redis , cause: " + e.getMessage(), e);
- }
- }
-
- private String getMetadata(BaseMetadataIdentifier metadataIdentifier) {
- if (pool != null) {
- return getMetadataStandalone(metadataIdentifier);
- } else {
- return getMetadataInCluster(metadataIdentifier);
- }
- }
-
- private String getMetadataInCluster(BaseMetadataIdentifier metadataIdentifier) {
- try (JedisCluster jedisCluster = new JedisCluster(jedisClusterNodes, timeout, timeout, 2, password, new GenericObjectPoolConfig())) {
- return jedisCluster.get(metadataIdentifier.getIdentifierKey() + META_DATA_STORE_TAG);
- } catch (Throwable e) {
- logger.error("Failed to get " + metadataIdentifier + " from redis cluster , cause: " + e.getMessage(), e);
- throw new RpcException("Failed to get " + metadataIdentifier + " from redis cluster , cause: " + e.getMessage(), e);
- }
- }
-
- private String getMetadataStandalone(BaseMetadataIdentifier metadataIdentifier) {
- try (Jedis jedis = pool.getResource()) {
- return jedis.get(metadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
- } catch (Throwable e) {
- logger.error("Failed to get " + metadataIdentifier + " from redis , cause: " + e.getMessage(), e);
- throw new RpcException("Failed to get " + metadataIdentifier + " from redis , cause: " + e.getMessage(), e);
- }
- }
-
-}
diff --git a/dubbo-spi-metadata/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportFactory.java b/dubbo-spi-metadata/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportFactory.java
deleted file mode 100644
index bd08877..0000000
--- a/dubbo-spi-metadata/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportFactory.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.metadata.store.redis;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.metadata.report.MetadataReport;
-import org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory;
-
-/**
- * RedisMetadataReportFactory.
- */
-public class RedisMetadataReportFactory extends AbstractMetadataReportFactory {
-
-
- @Override
- public MetadataReport createMetadataReport(URL url) {
- return new RedisMetadataReport(url);
- }
-
-}
diff --git a/dubbo-spi-metadata/dubbo-metadata-report-redis/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory b/dubbo-spi-metadata/dubbo-metadata-report-redis/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory
deleted file mode 100644
index 2e6effa..0000000
--- a/dubbo-spi-metadata/dubbo-metadata-report-redis/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.metadata.report.MetadataReportFactory
+++ /dev/null
@@ -1 +0,0 @@
-redis=org.apache.dubbo.metadata.store.redis.RedisMetadataReportFactory
diff --git a/dubbo-spi-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadata4TstService.java b/dubbo-spi-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadata4TstService.java
deleted file mode 100644
index 0a8d51b..0000000
--- a/dubbo-spi-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadata4TstService.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.metadata.store.redis;
-
-/**
- * 2018/10/26
- */
-public interface RedisMetadata4TstService {
-
-
- int getCounter();
-
- void printResult(String var);
-}
diff --git a/dubbo-spi-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java b/dubbo-spi-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java
deleted file mode 100644
index 900bf37..0000000
--- a/dubbo-spi-metadata/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.metadata.store.redis;
-
-import org.apache.commons.lang3.SystemUtils;
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.utils.NetUtils;
-import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder;
-import org.apache.dubbo.metadata.definition.model.FullServiceDefinition;
-import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
-import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
-import org.apache.dubbo.rpc.RpcException;
-
-import com.google.gson.Gson;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestInfo;
-import redis.clients.jedis.Jedis;
-import redis.clients.jedis.exceptions.JedisConnectionException;
-import redis.clients.jedis.exceptions.JedisDataException;
-import redis.embedded.RedisServer;
-import redis.embedded.RedisServerBuilder;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER_SIDE;
-import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
-import static org.apache.dubbo.metadata.report.support.Constants.SYNC_REPORT_KEY;
-
-/**
- * 2018/10/9
- */
-public class RedisMetadataReportTest {
- RedisMetadataReport redisMetadataReport;
- RedisMetadataReport syncRedisMetadataReport;
- RedisServer redisServer;
- URL registryUrl;
-
- @BeforeEach
- public void constructor(TestInfo testInfo) throws IOException {
- int redisPort = NetUtils.getAvailablePort();
- String methodName = testInfo.getTestMethod().get().getName();
- if ("testAuthRedisMetadata".equals(methodName) || ("testWrongAuthRedisMetadata".equals(methodName))) {
- String password = "チェリー";
- RedisServerBuilder builder = RedisServer.builder().port(redisPort).setting("requirepass " + password);
- if (SystemUtils.IS_OS_WINDOWS) {
- // set maxheap to fix Windows error 0x70 while starting redis
- builder.setting("maxheap 128mb");
- }
- redisServer = builder.build();
- registryUrl = URL.valueOf("redis://username:" + password + "@localhost:" + redisPort);
- } else {
- RedisServerBuilder builder = RedisServer.builder().port(redisPort);
- if (SystemUtils.IS_OS_WINDOWS) {
- // set maxheap to fix Windows error 0x70 while starting redis
- builder.setting("maxheap 128mb");
- }
- redisServer = builder.build();
- registryUrl = URL.valueOf("redis://localhost:" + redisPort);
- }
-
- this.redisServer.start();
- redisMetadataReport = (RedisMetadataReport) new RedisMetadataReportFactory().createMetadataReport(registryUrl);
- URL asyncRegistryUrl = URL.valueOf("redis://localhost:" + redisPort + "?" + SYNC_REPORT_KEY + "=true");
- syncRedisMetadataReport = (RedisMetadataReport) new RedisMetadataReportFactory().createMetadataReport(registryUrl);
- }
-
- @AfterEach
- public void tearDown() throws Exception {
- this.redisServer.stop();
- }
-
- @Test
- public void testAsyncStoreProvider() throws ClassNotFoundException {
- testStoreProvider(redisMetadataReport, "1.0.0.redis.md.p1", 3000);
- }
-
- @Test
- public void testSyncStoreProvider() throws ClassNotFoundException {
- testStoreProvider(syncRedisMetadataReport, "1.0.0.redis.md.p2", 3);
- }
-
- private void testStoreProvider(RedisMetadataReport redisMetadataReport, String version, long moreTime) throws ClassNotFoundException {
- String interfaceName = "org.apache.dubbo.metadata.store.redis.RedisMetadata4TstService";
- String group = null;
- String application = "vic.redis.md";
- MetadataIdentifier providerMetadataIdentifier = storePrivider(redisMetadataReport, interfaceName, version, group, application);
- Jedis jedis = null;
- try {
- jedis = redisMetadataReport.pool.getResource();
- String keyTmp = providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY);
- String value = jedis.get(keyTmp);
- if (value == null) {
- Thread.sleep(moreTime);
- value = jedis.get(keyTmp);
- }
-
- Assertions.assertNotNull(value);
-
- Gson gson = new Gson();
- FullServiceDefinition fullServiceDefinition = gson.fromJson(value, FullServiceDefinition.class);
- Assertions.assertEquals(fullServiceDefinition.getParameters().get("paramTest"), "redisTest");
- } catch (Throwable e) {
- throw new RpcException("Failed to put to redis . cause: " + e.getMessage(), e);
- } finally {
- if (jedis != null) {
- jedis.del(providerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
- }
- redisMetadataReport.pool.close();
- }
- }
-
- @Test
- public void testAsyncStoreConsumer() throws ClassNotFoundException {
- testStoreConsumer(redisMetadataReport, "1.0.0.redis.md.c1", 3000);
- }
-
- @Test
- public void testSyncStoreConsumer() throws ClassNotFoundException {
- testStoreConsumer(syncRedisMetadataReport, "1.0.0.redis.md.c2", 3);
- }
-
- private void testStoreConsumer(RedisMetadataReport redisMetadataReport, String version, long moreTime) throws ClassNotFoundException {
- String interfaceName = "org.apache.dubbo.metadata.store.redis.RedisMetadata4TstService";
- String group = null;
- String application = "vic.redis.md";
- MetadataIdentifier consumerMetadataIdentifier = storeConsumer(redisMetadataReport, interfaceName, version, group, application);
- Jedis jedis = null;
- try {
- jedis = redisMetadataReport.pool.getResource();
- String keyTmp = consumerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY);
- String value = jedis.get(keyTmp);
- if (value == null) {
- Thread.sleep(moreTime);
- value = jedis.get(keyTmp);
- }
- Assertions.assertEquals(value, "{\"paramConsumerTest\":\"redisCm\"}");
- } catch (Throwable e) {
- throw new RpcException("Failed to put to redis . cause: " + e.getMessage(), e);
- } finally {
- if (jedis != null) {
- jedis.del(consumerMetadataIdentifier.getUniqueKey(KeyTypeEnum.UNIQUE_KEY));
- }
- redisMetadataReport.pool.close();
- }
- }
-
- private MetadataIdentifier storePrivider(RedisMetadataReport redisMetadataReport, String interfaceName, String version, String group, String application) throws ClassNotFoundException {
- URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName + "?paramTest=redisTest&version=" + version + "&application="
- + application + (group == null ? "" : "&group=" + group));
-
- MetadataIdentifier providerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, PROVIDER_SIDE, application);
- Class interfaceClass = Class.forName(interfaceName);
- FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, url.getParameters());
-
- redisMetadataReport.storeProviderMetadata(providerMetadataIdentifier, fullServiceDefinition);
- try {
- Thread.sleep(300);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- return providerMetadataIdentifier;
- }
-
- private MetadataIdentifier storeConsumer(RedisMetadataReport redisMetadataReport, String interfaceName, String version, String group, String application) throws ClassNotFoundException {
- URL url = URL.valueOf("xxx://" + NetUtils.getLocalAddress().getHostName() + ":4444/" + interfaceName + "?version=" + version + "&application="
- + application + (group == null ? "" : "&group=" + group));
-
- MetadataIdentifier consumerMetadataIdentifier = new MetadataIdentifier(interfaceName, version, group, CONSUMER_SIDE, application);
- Class interfaceClass = Class.forName(interfaceName);
-
- Map<String, String> tmp = new HashMap<>();
- tmp.put("paramConsumerTest", "redisCm");
- redisMetadataReport.storeConsumerMetadata(consumerMetadataIdentifier, tmp);
- try {
- Thread.sleep(300);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- return consumerMetadataIdentifier;
- }
-
- @Test
- public void testAuthRedisMetadata() throws ClassNotFoundException {
- testStoreProvider(redisMetadataReport, "1.0.0.redis.md.p1", 3000);
- }
-
- @Test
- public void testWrongAuthRedisMetadata() throws ClassNotFoundException {
- registryUrl = registryUrl.setPassword("123456");
- redisMetadataReport = (RedisMetadataReport) new RedisMetadataReportFactory().createMetadataReport(registryUrl);
- try {
- testStoreProvider(redisMetadataReport, "1.0.0.redis.md.p1", 3000);
- } catch (RpcException e) {
- if (e.getCause() instanceof JedisConnectionException && e.getCause().getCause() instanceof JedisDataException) {
- Assertions.assertEquals("ERR invalid password", e.getCause().getCause().getMessage());
- } else {
- Assertions.fail("no invalid password exception!");
- }
- }
- }
-}
diff --git a/dubbo-spi-metadata/pom.xml b/dubbo-spi-metadata/pom.xml
index ffd446a..72fef74 100644
--- a/dubbo-spi-metadata/pom.xml
+++ b/dubbo-spi-metadata/pom.xml
@@ -32,7 +32,6 @@
</properties>
<modules>
- <module>dubbo-metadata-report-redis</module>
<module>dubbo-metadata-report-consul</module>
<module>dubbo-metadata-report-etcd</module>
<module>dubbo-metadata-report-nacos</module>
diff --git a/dubbo-spi-registry/dubbo-registry-multiple/pom.xml b/dubbo-spi-registry/dubbo-registry-multiple/pom.xml
deleted file mode 100644
index 375ed2e..0000000
--- a/dubbo-spi-registry/dubbo-registry-multiple/pom.xml
+++ /dev/null
@@ -1,65 +0,0 @@
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-registry</artifactId>
- <version>2.7.7-SNAPSHOT</version>
- </parent>
- <artifactId>dubbo-registry-multiple</artifactId>
- <packaging>jar</packaging>
- <name>${project.artifactId}</name>
- <description>The multiple registry module of dubbo project</description>
- <properties>
- <skip_maven_deploy>false</skip_maven_deploy>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-registry-api</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-registry-zookeeper</artifactId>
- <version>${project.parent.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-registry-redis</artifactId>
- <version>${project.parent.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>com.github.kstyrc</groupId>
- <artifactId>embedded-redis</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
diff --git a/dubbo-spi-registry/dubbo-registry-multiple/src/main/java/org/apache/dubbo/registry/multiple/MultipleRegistry.java b/dubbo-spi-registry/dubbo-registry-multiple/src/main/java/org/apache/dubbo/registry/multiple/MultipleRegistry.java
deleted file mode 100644
index 8ad2c10..0000000
--- a/dubbo-spi-registry/dubbo-registry-multiple/src/main/java/org/apache/dubbo/registry/multiple/MultipleRegistry.java
+++ /dev/null
@@ -1,337 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.registry.multiple;
-
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.constants.CommonConstants;
-import org.apache.dubbo.common.extension.ExtensionLoader;
-import org.apache.dubbo.common.utils.CollectionUtils;
-import org.apache.dubbo.registry.NotifyListener;
-import org.apache.dubbo.registry.Registry;
-import org.apache.dubbo.registry.RegistryFactory;
-import org.apache.dubbo.registry.support.AbstractRegistry;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import static org.apache.dubbo.common.constants.RegistryConstants.EMPTY_PROTOCOL;
-
-/**
- * MultipleRegistry
- */
-public class MultipleRegistry extends AbstractRegistry {
-
- public static final String REGISTRY_FOR_SERVICE = "service-registry";
- public static final String REGISTRY_FOR_REFERENCE = "reference-registry";
-
- protected RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension();
- private final Map<String, Registry> serviceRegistries = new ConcurrentHashMap<>(4);
- private final Map<String, Registry> referenceRegistries = new ConcurrentHashMap<String, Registry>(4);
- private final Map<NotifyListener, MultipleNotifyListenerWrapper> multipleNotifyListenerMap = new ConcurrentHashMap<NotifyListener, MultipleNotifyListenerWrapper>(32);
- protected List<String> origServiceRegistryURLs;
- protected List<String> origReferenceRegistryURLs;
- protected List<String> effectServiceRegistryURLs;
- protected List<String> effectReferenceRegistryURLs;
- private URL registryUrl;
- private String applicationName;
-
- public MultipleRegistry(URL url) {
- this(url, true, true);
-
- boolean defaultRegistry = url.getParameter(CommonConstants.DEFAULT_KEY, true);
- if (defaultRegistry && effectServiceRegistryURLs.isEmpty() && effectReferenceRegistryURLs.isEmpty()) {
- throw new IllegalArgumentException("Illegal registry url. You need to configure parameter " +
- REGISTRY_FOR_SERVICE + " or " + REGISTRY_FOR_REFERENCE);
- }
- }
-
- public MultipleRegistry(URL url, boolean initServiceRegistry, boolean initReferenceRegistry) {
- super(url);
- this.registryUrl = url;
- this.applicationName = url.getParameter(CommonConstants.APPLICATION_KEY);
- init();
- checkApplicationName(this.applicationName);
- // This urls contain parameter and it donot inherit from the parameter of url in MultipleRegistry
-
- Map<String, Registry> registryMap = new HashMap<>();
- if (initServiceRegistry) {
- initServiceRegistry(url, registryMap);
- }
- if (initReferenceRegistry) {
- initReferenceRegistry(url, registryMap);
- }
- }
-
- protected void initServiceRegistry(URL url, Map<String, Registry> registryMap) {
- origServiceRegistryURLs = url.getParameter(REGISTRY_FOR_SERVICE, new ArrayList<String>());
- effectServiceRegistryURLs = this.filterServiceRegistry(origServiceRegistryURLs);
- for (String tmpUrl : effectServiceRegistryURLs) {
- if (registryMap.get(tmpUrl) != null) {
- serviceRegistries.put(tmpUrl, registryMap.get(tmpUrl));
- continue;
- }
- Registry registry = registryFactory.getRegistry(URL.valueOf(tmpUrl));
- registryMap.put(tmpUrl, registry);
- serviceRegistries.put(tmpUrl, registry);
- }
- }
-
- protected void initReferenceRegistry(URL url, Map<String, Registry> registryMap) {
- origReferenceRegistryURLs = url.getParameter(REGISTRY_FOR_REFERENCE, new ArrayList<String>());
- effectReferenceRegistryURLs = this.filterReferenceRegistry(origReferenceRegistryURLs);
- for (String tmpUrl : effectReferenceRegistryURLs) {
- if (registryMap.get(tmpUrl) != null) {
- referenceRegistries.put(tmpUrl, registryMap.get(tmpUrl));
- continue;
- }
- Registry registry = registryFactory.getRegistry(URL.valueOf(tmpUrl));
- registryMap.put(tmpUrl, registry);
- referenceRegistries.put(tmpUrl, registry);
- }
- }
-
-
- @Override
- public URL getUrl() {
- return registryUrl;
- }
-
- @Override
- public boolean isAvailable() {
- boolean available = serviceRegistries.isEmpty() ? true : false;
- for (Registry serviceRegistry : serviceRegistries.values()) {
- if (serviceRegistry.isAvailable()) {
- available = true;
- }
- }
- if (!available) {
- return false;
- }
-
- available = referenceRegistries.isEmpty() ? true : false;
- for (Registry referenceRegistry : referenceRegistries.values()) {
- if (referenceRegistry.isAvailable()) {
- available = true;
- }
- }
- if (!available) {
- return false;
- }
- return true;
- }
-
- @Override
- public void destroy() {
- Set<Registry> registries = new HashSet<Registry>(serviceRegistries.values());
- registries.addAll(referenceRegistries.values());
- for (Registry registry : registries) {
- registry.destroy();
- }
- }
-
- @Override
- public void register(URL url) {
- super.register(url);
- for (Registry registry : serviceRegistries.values()) {
- registry.register(url);
- }
- }
-
- @Override
- public void unregister(URL url) {
- super.unregister(url);
- for (Registry registry : serviceRegistries.values()) {
- registry.unregister(url);
- }
- }
-
- @Override
- public void subscribe(URL url, NotifyListener listener) {
- MultipleNotifyListenerWrapper multipleNotifyListenerWrapper = new MultipleNotifyListenerWrapper(listener);
- multipleNotifyListenerMap.put(listener, multipleNotifyListenerWrapper);
- for (Registry registry : referenceRegistries.values()) {
- SingleNotifyListener singleNotifyListener = new SingleNotifyListener(multipleNotifyListenerWrapper, registry);
- multipleNotifyListenerWrapper.putRegistryMap(registry.getUrl(), singleNotifyListener);
- registry.subscribe(url, singleNotifyListener);
- }
- super.subscribe(url, multipleNotifyListenerWrapper);
- }
-
- @Override
- public void unsubscribe(URL url, NotifyListener listener) {
- MultipleNotifyListenerWrapper notifyListener = multipleNotifyListenerMap.remove(listener);
- for (Registry registry : referenceRegistries.values()) {
- SingleNotifyListener singleNotifyListener = notifyListener.registryMap.get(registry.getUrl());
- registry.unsubscribe(url, singleNotifyListener);
- }
-
- if (notifyListener != null) {
- super.unsubscribe(url, notifyListener);
- notifyListener.destroy();
- }
- }
-
- @Override
- public List<URL> lookup(URL url) {
- List<URL> urls = new ArrayList<URL>();
- for (Registry registry : referenceRegistries.values()) {
- List<URL> tmpUrls = registry.lookup(url);
- if (!CollectionUtils.isEmpty(tmpUrls)) {
- urls.addAll(tmpUrls);
- }
- }
- return urls;
- }
-
- protected void init() {
- }
-
- protected List<String> filterServiceRegistry(List<String> serviceRegistryURLs) {
- return serviceRegistryURLs;
- }
-
- protected List<String> filterReferenceRegistry(List<String> referenceRegistryURLs) {
- return referenceRegistryURLs;
- }
-
-
- protected void checkApplicationName(String applicationName) {
- }
-
- protected String getApplicationName() {
- return applicationName;
- }
-
- public Map<String, Registry> getServiceRegistries() {
- return serviceRegistries;
- }
-
- public Map<String, Registry> getReferenceRegistries() {
- return referenceRegistries;
- }
-
- public List<String> getOrigServiceRegistryURLs() {
- return origServiceRegistryURLs;
- }
-
- public List<String> getOrigReferenceRegistryURLs() {
- return origReferenceRegistryURLs;
- }
-
- public List<String> getEffectServiceRegistryURLs() {
- return effectServiceRegistryURLs;
- }
-
- public List<String> getEffectReferenceRegistryURLs() {
- return effectReferenceRegistryURLs;
- }
-
- static protected class MultipleNotifyListenerWrapper implements NotifyListener {
-
- Map<URL, SingleNotifyListener> registryMap = new ConcurrentHashMap<URL, SingleNotifyListener>(4);
- NotifyListener sourceNotifyListener;
-
- public MultipleNotifyListenerWrapper(NotifyListener sourceNotifyListener) {
- this.sourceNotifyListener = sourceNotifyListener;
- }
-
- public void putRegistryMap(URL registryURL, SingleNotifyListener singleNotifyListener) {
- this.registryMap.put(registryURL, singleNotifyListener);
- }
-
- public void destroy() {
- for (SingleNotifyListener singleNotifyListener : registryMap.values()) {
- if (singleNotifyListener != null) {
- singleNotifyListener.destroy();
- }
- }
- registryMap.clear();
- sourceNotifyListener = null;
- }
-
- public synchronized void notifySourceListener() {
- List<URL> notifyURLs = new ArrayList<URL>();
- URL emptyURL = null;
- for (SingleNotifyListener singleNotifyListener : registryMap.values()) {
- List<URL> tmpUrls = singleNotifyListener.getUrlList();
- if (CollectionUtils.isEmpty(tmpUrls)) {
- continue;
- }
- // empty protocol
- if (tmpUrls.size() == 1
- && tmpUrls.get(0) != null
- && EMPTY_PROTOCOL.equals(tmpUrls.get(0).getProtocol())) {
- // if only one empty
- if (emptyURL == null) {
- emptyURL = tmpUrls.get(0);
- }
- continue;
- }
- notifyURLs.addAll(tmpUrls);
- }
- // if no notify URL, add empty protocol URL
- if (emptyURL != null && notifyURLs.isEmpty()) {
- notifyURLs.add(emptyURL);
- }
- this.notify(notifyURLs);
- }
-
- @Override
- public void notify(List<URL> urls) {
- sourceNotifyListener.notify(urls);
- }
-
- public Map<URL, SingleNotifyListener> getRegistryMap() {
- return registryMap;
- }
- }
-
- static protected class SingleNotifyListener implements NotifyListener {
-
- MultipleNotifyListenerWrapper multipleNotifyListenerWrapper;
- Registry registry;
- volatile List<URL> urlList;
-
- public SingleNotifyListener(MultipleNotifyListenerWrapper multipleNotifyListenerWrapper, Registry registry) {
- this.registry = registry;
- this.multipleNotifyListenerWrapper = multipleNotifyListenerWrapper;
- }
-
- @Override
- public synchronized void notify(List<URL> urls) {
- this.urlList = urls;
- if (multipleNotifyListenerWrapper != null) {
- this.multipleNotifyListenerWrapper.notifySourceListener();
- }
- }
-
- public void destroy() {
- this.multipleNotifyListenerWrapper = null;
- this.registry = null;
- }
-
- public List<URL> getUrlList() {
- return urlList;
- }
- }
-}
diff --git a/dubbo-spi-registry/dubbo-registry-multiple/src/main/java/org/apache/dubbo/registry/multiple/MultipleRegistryFactory.java b/dubbo-spi-registry/dubbo-registry-multiple/src/main/java/org/apache/dubbo/registry/multiple/MultipleRegistryFactory.java
deleted file mode 100644
index 69d695b..0000000
--- a/dubbo-spi-registry/dubbo-registry-multiple/src/main/java/org/apache/dubbo/registry/multiple/MultipleRegistryFactory.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.registry.multiple;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.registry.Registry;
-import org.apache.dubbo.registry.support.AbstractRegistryFactory;
-
-/**
- * MultipleRegistryFactory
- */
-public class MultipleRegistryFactory extends AbstractRegistryFactory {
-
- @Override
- protected Registry createRegistry(URL url) {
- return new MultipleRegistry(url);
- }
-
-}
diff --git a/dubbo-spi-registry/dubbo-registry-multiple/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory b/dubbo-spi-registry/dubbo-registry-multiple/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory
deleted file mode 100644
index defb7a2..0000000
--- a/dubbo-spi-registry/dubbo-registry-multiple/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory
+++ /dev/null
@@ -1 +0,0 @@
-multiple=org.apache.dubbo.registry.multiple.MultipleRegistryFactory
diff --git a/dubbo-spi-registry/dubbo-registry-multiple/src/test/java/org/apache/dubbo/registry/multiple/MultipleRegistry2S2RTest.java b/dubbo-spi-registry/dubbo-registry-multiple/src/test/java/org/apache/dubbo/registry/multiple/MultipleRegistry2S2RTest.java
deleted file mode 100644
index 9243730..0000000
--- a/dubbo-spi-registry/dubbo-registry-multiple/src/test/java/org/apache/dubbo/registry/multiple/MultipleRegistry2S2RTest.java
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.registry.multiple;
-
-import org.apache.commons.lang3.SystemUtils;
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.utils.NetUtils;
-import org.apache.dubbo.registry.NotifyListener;
-import org.apache.dubbo.registry.Registry;
-import org.apache.dubbo.registry.redis.RedisRegistry;
-import org.apache.dubbo.registry.zookeeper.ZookeeperRegistry;
-import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
-import org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient;
-
-import org.apache.curator.test.TestingServer;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import redis.embedded.RedisServer;
-import redis.embedded.RedisServerBuilder;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * 2019-04-30
- */
-public class MultipleRegistry2S2RTest {
-
- private static final String SERVICE_NAME = "org.apache.dubbo.registry.MultipleService2S2R";
- private static final String SERVICE2_NAME = "org.apache.dubbo.registry.MultipleService2S2R2";
-
- private static TestingServer zkServer;
- private static RedisServer redisServer;
- static int zkServerPort;
- static int redisServerPort;
-
- private static String zookeeperRegistryURLStr;
- private static String redisRegistryURLStr;
-
- private static MultipleRegistry multipleRegistry;
- // for test content
- private static ZookeeperClient zookeeperClient;
-
- private static ZookeeperRegistry zookeeperRegistry;
- private static RedisRegistry redisRegistry;
-
-
- @BeforeAll
- public static void setUp() throws Exception {
- zkServerPort = NetUtils.getAvailablePort();
- zkServer = new TestingServer(zkServerPort, true);
- zookeeperRegistryURLStr = "zookeeper://127.0.0.1:" + zkServerPort;
-
- redisServerPort = NetUtils.getAvailablePort();
- RedisServerBuilder builder = RedisServer.builder().port(redisServerPort);
- if (SystemUtils.IS_OS_WINDOWS) {
- // set maxheap to fix Windows error 0x70 while starting redis
- builder.setting("maxheap 128mb");
- }
- redisServer = builder.build();
- redisServer.start();
- redisRegistryURLStr = "redis://127.0.0.1:" + redisServerPort;
-
-
- URL url = URL.valueOf("multiple://127.0.0.1?application=vic&" +
- MultipleRegistry.REGISTRY_FOR_SERVICE + "=" + zookeeperRegistryURLStr + "," + redisRegistryURLStr + "&"
- + MultipleRegistry.REGISTRY_FOR_REFERENCE + "=" + zookeeperRegistryURLStr + "," + redisRegistryURLStr);
- multipleRegistry = (MultipleRegistry) new MultipleRegistryFactory().createRegistry(url);
-
- // for test validation
- zookeeperClient = new CuratorZookeeperClient(URL.valueOf(zookeeperRegistryURLStr));
- zookeeperRegistry = MultipleRegistryTestUtil.getZookeeperRegistry(multipleRegistry.getServiceRegistries().values());
- redisRegistry = MultipleRegistryTestUtil.getRedisRegistry(multipleRegistry.getServiceRegistries().values());
- }
-
- @AfterAll
- public static void tearDown() throws Exception {
- zkServer.stop();
- redisServer.stop();
- }
-
- @Test
- public void testParamConfig() {
-
- Assertions.assertEquals(2, multipleRegistry.origReferenceRegistryURLs.size());
- Assertions.assertTrue(multipleRegistry.origReferenceRegistryURLs.contains(zookeeperRegistryURLStr));
- Assertions.assertTrue(multipleRegistry.origReferenceRegistryURLs.contains(redisRegistryURLStr));
-
- Assertions.assertEquals(2, multipleRegistry.origServiceRegistryURLs.size());
- Assertions.assertTrue(multipleRegistry.origServiceRegistryURLs.contains(zookeeperRegistryURLStr));
- Assertions.assertTrue(multipleRegistry.origServiceRegistryURLs.contains(redisRegistryURLStr));
-
- Assertions.assertEquals(2, multipleRegistry.effectReferenceRegistryURLs.size());
- Assertions.assertTrue(multipleRegistry.effectReferenceRegistryURLs.contains(zookeeperRegistryURLStr));
- Assertions.assertTrue(multipleRegistry.effectReferenceRegistryURLs.contains(redisRegistryURLStr));
-
- Assertions.assertEquals(2, multipleRegistry.effectServiceRegistryURLs.size());
- Assertions.assertTrue(multipleRegistry.effectServiceRegistryURLs.contains(zookeeperRegistryURLStr));
- Assertions.assertTrue(multipleRegistry.effectServiceRegistryURLs.contains(redisRegistryURLStr));
-
- Assertions.assertTrue(multipleRegistry.getServiceRegistries().containsKey(zookeeperRegistryURLStr));
- Assertions.assertTrue(multipleRegistry.getServiceRegistries().containsKey(redisRegistryURLStr));
- Assertions.assertEquals(2, multipleRegistry.getServiceRegistries().values().size());
-// java.util.Iterator<Registry> registryIterable = multipleRegistry.getServiceRegistries().values().iterator();
-// Registry firstRegistry = registryIterable.next();
-// Registry secondRegistry = registryIterable.next();
- Assertions.assertNotNull(MultipleRegistryTestUtil.getZookeeperRegistry(multipleRegistry.getServiceRegistries().values()));
- Assertions.assertNotNull(MultipleRegistryTestUtil.getRedisRegistry(multipleRegistry.getServiceRegistries().values()));
- Assertions.assertNotNull(MultipleRegistryTestUtil.getZookeeperRegistry(multipleRegistry.getReferenceRegistries().values()));
- Assertions.assertNotNull(MultipleRegistryTestUtil.getRedisRegistry(multipleRegistry.getReferenceRegistries().values()));
-
- Assertions.assertEquals(MultipleRegistryTestUtil.getZookeeperRegistry(multipleRegistry.getServiceRegistries().values()),
- MultipleRegistryTestUtil.getZookeeperRegistry(multipleRegistry.getReferenceRegistries().values()));
-
- Assertions.assertEquals(MultipleRegistryTestUtil.getRedisRegistry(multipleRegistry.getServiceRegistries().values()),
- MultipleRegistryTestUtil.getRedisRegistry(multipleRegistry.getReferenceRegistries().values()));
-
- Assertions.assertEquals(multipleRegistry.getApplicationName(), "vic");
-
- Assertions.assertTrue(multipleRegistry.isAvailable());
- }
-
- @Test
- public void testRegistryAndUnRegistry() throws InterruptedException {
- URL serviceUrl = URL.valueOf("http2://multiple/" + SERVICE_NAME + "?notify=false&methods=test1,test2&category=providers");
-// URL serviceUrl2 = URL.valueOf("http2://multiple2/" + SERVICE_NAME + "?notify=false&methods=test1,test2&category=providers");
- multipleRegistry.register(serviceUrl);
-
- String path = "/dubbo/" + SERVICE_NAME + "/providers";
- List<String> providerList = zookeeperClient.getChildren(path);
- Assertions.assertTrue(!providerList.isEmpty());
- System.out.println(providerList.get(0));
-
- Assertions.assertNotNull(MultipleRegistryTestUtil.getRedisHashContent(redisServerPort, path, serviceUrl.toFullString()));
-
- final List<URL> list = new ArrayList<URL>();
- multipleRegistry.subscribe(serviceUrl, new NotifyListener() {
- @Override
- public void notify(List<URL> urls) {
- System.out.println("invoke notify: " + urls);
- list.clear();
- list.addAll(urls);
- }
- });
- Thread.sleep(1500);
- Assertions.assertEquals(2, list.size());
-
- multipleRegistry.unregister(serviceUrl);
- Thread.sleep(1500);
- Assertions.assertEquals(1, list.size());
- List<URL> urls = MultipleRegistryTestUtil.getProviderURLsFromNotifyURLS(list);
- Assertions.assertEquals(1, list.size());
- Assertions.assertEquals("empty", list.get(0).getProtocol());
- }
-
- @Test
- public void testSubscription() throws InterruptedException {
- URL serviceUrl = URL.valueOf("http2://multiple/" + SERVICE2_NAME + "?notify=false&methods=test1,test2&category=providers");
-// URL serviceUrl2 = URL.valueOf("http2://multiple2/" + SERVICE_NAME + "?notify=false&methods=test1,test2&category=providers");
- multipleRegistry.register(serviceUrl);
-
- String path = "/dubbo/" + SERVICE2_NAME + "/providers";
- List<String> providerList = zookeeperClient.getChildren(path);
- Assertions.assertTrue(!providerList.isEmpty());
- System.out.println(providerList.get(0));
-
- Assertions.assertNotNull(MultipleRegistryTestUtil.getRedisHashContent(redisServerPort, path, serviceUrl.toFullString()));
-
- final List<URL> list = new ArrayList<URL>();
- multipleRegistry.subscribe(serviceUrl, new NotifyListener() {
- @Override
- public void notify(List<URL> urls) {
- System.out.println("invoke notify: " + urls);
- list.clear();
- list.addAll(urls);
- }
- });
- Thread.sleep(1500);
- Assertions.assertEquals(2, list.size());
-
- List<Registry> serviceRegistries = new ArrayList<Registry>(multipleRegistry.getServiceRegistries().values());
- serviceRegistries.get(0).unregister(serviceUrl);
- Thread.sleep(1500);
- Assertions.assertEquals(1, list.size());
- List<URL> urls = MultipleRegistryTestUtil.getProviderURLsFromNotifyURLS(list);
- Assertions.assertEquals(1, list.size());
- Assertions.assertTrue(!"empty".equals(list.get(0).getProtocol()));
-
- serviceRegistries.get(1).unregister(serviceUrl);
- Thread.sleep(1500);
- Assertions.assertEquals(1, list.size());
- urls = MultipleRegistryTestUtil.getProviderURLsFromNotifyURLS(list);
- Assertions.assertEquals(1, list.size());
- Assertions.assertEquals("empty", list.get(0).getProtocol());
- }
-
-}
diff --git a/dubbo-spi-registry/dubbo-registry-multiple/src/test/java/org/apache/dubbo/registry/multiple/MultipleRegistryTestUtil.java b/dubbo-spi-registry/dubbo-registry-multiple/src/test/java/org/apache/dubbo/registry/multiple/MultipleRegistryTestUtil.java
deleted file mode 100644
index 9544ef8..0000000
--- a/dubbo-spi-registry/dubbo-registry-multiple/src/test/java/org/apache/dubbo/registry/multiple/MultipleRegistryTestUtil.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.registry.multiple;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.utils.StringUtils;
-import org.apache.dubbo.common.utils.UrlUtils;
-import org.apache.dubbo.registry.ListenerRegistryWrapper;
-import org.apache.dubbo.registry.Registry;
-import org.apache.dubbo.registry.redis.RedisRegistry;
-import org.apache.dubbo.registry.zookeeper.ZookeeperRegistry;
-import org.apache.dubbo.rpc.RpcException;
-
-import redis.clients.jedis.Jedis;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.stream.Collectors;
-
-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.DEFAULT_CATEGORY;
-import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_CONFIGURATORS_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.common.constants.RegistryConstants.ROUTE_PROTOCOL;
-
-/**
- * 2019-05-13
- */
-public class MultipleRegistryTestUtil {
- public static ZookeeperRegistry getZookeeperRegistry(Collection<Registry> registryCollection) {
- for (Registry registry : registryCollection) {
- if (registry instanceof ListenerRegistryWrapper) {
- registry = ((ListenerRegistryWrapper) registry).getRegistry();
- }
- if (registry instanceof ZookeeperRegistry) {
- return (ZookeeperRegistry) registry;
- }
- }
- return null;
- }
-
- public static RedisRegistry getRedisRegistry(Collection<Registry> registryCollection) {
- for (Registry registry : registryCollection) {
- if (registry instanceof ListenerRegistryWrapper) {
- registry = ((ListenerRegistryWrapper) registry).getRegistry();
- }
- if (registry instanceof RedisRegistry) {
- return (RedisRegistry) registry;
- }
- }
- return null;
- }
-
- public static String getRedisContent(int port, String key) {
- Jedis jedis = null;
- try {
- jedis = new Jedis("127.0.0.1", port);
- return jedis.get(key);
- } catch (Throwable e) {
- throw new RpcException("Failed to put to redis . cause: " + e.getMessage(), e);
- } finally {
- if (jedis != null) {
- jedis.close();
- }
- }
- }
-
- public static String getRedisHashContent(int port, String key, String field) {
- Jedis jedis = null;
- try {
- jedis = new Jedis("127.0.0.1", port);
- return jedis.hget(key, field);
- } catch (Throwable e) {
- throw new RpcException("Failed to put to redis . cause: " + e.getMessage(), e);
- } finally {
- if (jedis != null) {
- jedis.close();
- }
- }
- }
-
- /**
- * copy from @org.apache.dubbo.registry.integration.RegistryDirectory#notify(java.util.List)
- *
- * @param urls
- * @return
- */
- public static List<URL> getProviderURLsFromNotifyURLS(List<URL> urls) {
- Map<String, List<URL>> categoryUrls = urls.stream()
- .filter(Objects::nonNull)
- .filter(MultipleRegistryTestUtil::isValidCategory)
- .filter(MultipleRegistryTestUtil::isNotCompatibleFor26x)
- .collect(Collectors.groupingBy(url -> {
- if (UrlUtils.isConfigurator(url)) {
- return CONFIGURATORS_CATEGORY;
- } else if (UrlUtils.isRoute(url)) {
- return ROUTERS_CATEGORY;
- } else if (UrlUtils.isProvider(url)) {
- return PROVIDERS_CATEGORY;
- }
- return "";
- }));
-
- // providers
- List<URL> providerURLs = categoryUrls.getOrDefault(PROVIDERS_CATEGORY, Collections.emptyList());
- return providerURLs;
-
- }
-
- private static boolean isValidCategory(URL url) {
- String category = url.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY);
- if ((ROUTERS_CATEGORY.equals(category) || ROUTE_PROTOCOL.equals(url.getProtocol())) ||
- PROVIDERS_CATEGORY.equals(category) ||
- CONFIGURATORS_CATEGORY.equals(category) || DYNAMIC_CONFIGURATORS_CATEGORY.equals(category) ||
- APP_DYNAMIC_CONFIGURATORS_CATEGORY.equals(category)) {
- return true;
- }
- return false;
- }
-
- private static boolean isNotCompatibleFor26x(URL url) {
- return StringUtils.isEmpty(url.getParameter(COMPATIBLE_CONFIG_KEY));
- }
-}
diff --git a/dubbo-spi-registry/dubbo-registry-nacos/pom.xml b/dubbo-spi-registry/dubbo-registry-nacos/pom.xml
deleted file mode 100644
index f381bba..0000000
--- a/dubbo-spi-registry/dubbo-registry-nacos/pom.xml
+++ /dev/null
@@ -1,83 +0,0 @@
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-registry</artifactId>
- <version>2.7.7-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>dubbo-registry-nacos</artifactId>
- <name>${project.artifactId}</name>
- <description>The Nacos registry module of Dubbo project</description>
-
- <dependencies>
-
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-registry-api</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-common</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.alibaba.nacos</groupId>
- <artifactId>nacos-client</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-serialization-hessian2</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-rpc-dubbo</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-remoting-netty4</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <scope>test</scope>
- </dependency>
-
- <!-- REST support dependencies -->
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- <scope>test</scope>
- </dependency>
-
- </dependencies>
-</project>
diff --git a/dubbo-spi-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java b/dubbo-spi-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
deleted file mode 100644
index 187da71..0000000
--- a/dubbo-spi-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
+++ /dev/null
@@ -1,629 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.registry.nacos;
-
-
-import com.alibaba.nacos.api.common.Constants;
-import com.google.common.collect.Lists;
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.URLBuilder;
-import org.apache.dubbo.common.logger.Logger;
-import org.apache.dubbo.common.logger.LoggerFactory;
-import org.apache.dubbo.common.utils.StringUtils;
-import org.apache.dubbo.common.utils.UrlUtils;
-import org.apache.dubbo.registry.NotifyListener;
-import org.apache.dubbo.registry.Registry;
-import org.apache.dubbo.registry.nacos.util.NacosInstanceManageUtil;
-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 java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
-
-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.INTERFACE_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.EMPTY_PROTOCOL;
-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;
-
-/**
- * Nacos {@link Registry}
- *
- * @see #SERVICE_NAME_SEPARATOR
- * @see #PAGINATION_SIZE
- * @see #LOOKUP_INTERVAL
- * @since 2.6.5
- */
-public class NacosRegistry extends FailbackRegistry {
-
- /**
- * All supported categories
- */
- private static final List<String> ALL_SUPPORTED_CATEGORIES = Arrays.asList(
- PROVIDERS_CATEGORY,
- CONSUMERS_CATEGORY,
- ROUTERS_CATEGORY,
- CONFIGURATORS_CATEGORY
- );
-
- private static final int CATEGORY_INDEX = 0;
-
- private static final int SERVICE_INTERFACE_INDEX = 1;
-
- private static final int SERVICE_VERSION_INDEX = 2;
-
- private static final int SERVICE_GROUP_INDEX = 3;
-
- private static final String WILDCARD = "*";
-
- /**
- * The separator for service name
- * Change a constant to be configurable, it's designed for Windows file name that is compatible with old
- * Nacos binary release(< 0.6.1)
- */
- private static final String SERVICE_NAME_SEPARATOR = System.getProperty("nacos.service.name.separator", ":");
-
- /**
- * The pagination size of query for Nacos service names(only for Dubbo-OPS)
- */
- private static final int PAGINATION_SIZE = Integer.getInteger("nacos.service.names.pagination.size", 100);
-
- /**
- * The interval in second of lookup Nacos service names(only for Dubbo-OPS)
- */
- private static final long LOOKUP_INTERVAL = Long.getLong("nacos.service.names.lookup.interval", 30);
-
- /**
- * {@link ScheduledExecutorService} lookup Nacos service names(only for Dubbo-OPS)
- */
- private volatile ScheduledExecutorService scheduledExecutorService;
-
- private final Logger logger = LoggerFactory.getLogger(getClass());
-
- private final NamingService namingService;
-
- public NacosRegistry(URL url, NamingService namingService) {
- super(url);
- this.namingService = namingService;
- }
-
- @Override
- public boolean isAvailable() {
- return "UP".equals(namingService.getServerStatus());
- }
-
- @Override
- public List<URL> lookup(final URL url) {
- final List<URL> urls = new LinkedList<>();
- execute(namingService -> {
- Set<String> serviceNames = getServiceNames(url, null);
- for (String serviceName : serviceNames) {
- List<Instance> instances = namingService.getAllInstances(serviceName,
- getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP));
- urls.addAll(buildURLs(url, instances));
- }
- });
- return urls;
- }
-
- @Override
- public void doRegister(URL url) {
- final String serviceName = getServiceName(url);
- final Instance instance = createInstance(url);
- /**
- * namingService.registerInstance with {@link org.apache.dubbo.registry.support.AbstractRegistry#registryUrl}
- * default {@link DEFAULT_GROUP}
- *
- * in https://github.com/apache/dubbo/issues/5978
- */
- execute(namingService -> namingService.registerInstance(serviceName,
- getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP), instance));
- }
-
- @Override
- public void doUnregister(final URL url) {
- execute(namingService -> {
- String serviceName = getServiceName(url);
- Instance instance = createInstance(url);
- namingService.deregisterInstance(serviceName,
- getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP),
- instance.getIp()
- , instance.getPort());
- });
- }
-
- @Override
- public void doSubscribe(final URL url, final NotifyListener listener) {
- Set<String> serviceNames = getServiceNames(url, listener);
-
- //Set corresponding serviceNames for easy search later
- if (isServiceNamesWithCompatibleMode(url)) {
- for (String serviceName : serviceNames) {
- NacosInstanceManageUtil.setCorrespondingServiceNames(serviceName, serviceNames);
- }
- }
-
- doSubscribe(url, listener, serviceNames);
- }
-
- private void doSubscribe(final URL url, final NotifyListener listener, final Set<String> serviceNames) {
- execute(namingService -> {
- if (isServiceNamesWithCompatibleMode(url)) {
- List<Instance> allCorrespondingInstanceList = Lists.newArrayList();
-
- /**
- * Get all instances with serviceNames to avoid instance overwrite and but with empty instance mentioned
- * in https://github.com/apache/dubbo/issues/5885 and https://github.com/apache/dubbo/issues/5899
- *
- * namingService.getAllInstances with {@link org.apache.dubbo.registry.support.AbstractRegistry#registryUrl}
- * default {@link DEFAULT_GROUP}
- *
- * in https://github.com/apache/dubbo/issues/5978
- */
- for (String serviceName : serviceNames) {
- List<Instance> instances = namingService.getAllInstances(serviceName,
- getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP));
- NacosInstanceManageUtil.initOrRefreshServiceInstanceList(serviceName, instances);
- allCorrespondingInstanceList.addAll(instances);
- }
- notifySubscriber(url, listener, allCorrespondingInstanceList);
- for (String serviceName : serviceNames) {
- subscribeEventListener(serviceName, url, listener);
- }
- } else {
- List<Instance> instances = new LinkedList<>();
- for (String serviceName : serviceNames) {
- instances.addAll(namingService.getAllInstances(serviceName
- , getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP)));
- notifySubscriber(url, listener, instances);
- subscribeEventListener(serviceName, url, listener);
- }
- }
-
- });
- }
-
- /**
- * Since 2.7.6 the legacy service name will be added to serviceNames
- * to fix bug with https://github.com/apache/dubbo/issues/5442
- *
- * @param url
- * @return
- */
- private boolean isServiceNamesWithCompatibleMode(final URL url) {
- if (!isAdminProtocol(url) && createServiceName(url).isConcrete()) {
- return true;
- } else {
- return false;
- }
- }
-
- @Override
- public void doUnsubscribe(URL url, NotifyListener listener) {
- if (isAdminProtocol(url)) {
- shutdownServiceNamesLookup();
- }
- }
-
- private void shutdownServiceNamesLookup() {
- if (scheduledExecutorService != null) {
- scheduledExecutorService.shutdown();
- }
- }
-
- /**
- * Get the service names from the specified {@link URL url}
- *
- * @param url {@link URL}
- * @param listener {@link NotifyListener}
- * @return non-null
- */
- private Set<String> getServiceNames(URL url, NotifyListener listener) {
- if (isAdminProtocol(url)) {
- scheduleServiceNamesLookup(url, listener);
- return getServiceNamesForOps(url);
- } else {
- return getServiceNames0(url);
- }
- }
-
- private Set<String> getServiceNames0(URL url) {
- NacosServiceName serviceName = createServiceName(url);
-
- final Set<String> serviceNames;
-
- if (serviceName.isConcrete()) { // is the concrete service name
- serviceNames = new LinkedHashSet<>();
- serviceNames.add(serviceName.toString());
- // Add the legacy service name since 2.7.6
- String legacySubscribedServiceName = getLegacySubscribedServiceName(url);
- if (!serviceName.toString().equals(legacySubscribedServiceName)) {
- //avoid duplicated service names
- serviceNames.add(legacySubscribedServiceName);
- }
- } else {
- serviceNames = filterServiceNames(serviceName);
- }
-
- return serviceNames;
- }
-
- private Set<String> filterServiceNames(NacosServiceName serviceName) {
- Set<String> serviceNames = new LinkedHashSet<>();
-
- execute(namingService -> {
-
- serviceNames.addAll(namingService.getServicesOfServer(1, Integer.MAX_VALUE,
- getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP)).getData()
- .stream()
- .map(NacosServiceName::new)
- .filter(serviceName::isCompatible)
- .map(NacosServiceName::toString)
- .collect(Collectors.toList()));
-
- });
-
- return serviceNames;
- }
-
- /**
- * Get the legacy subscribed service name for compatible with Dubbo 2.7.3 and below
- *
- * @param url {@link URL}
- * @return non-null
- * @since 2.7.6
- */
- private String getLegacySubscribedServiceName(URL url) {
- StringBuilder serviceNameBuilder = new StringBuilder(DEFAULT_CATEGORY);
- appendIfPresent(serviceNameBuilder, url, INTERFACE_KEY);
- appendIfPresent(serviceNameBuilder, url, VERSION_KEY);
- appendIfPresent(serviceNameBuilder, url, GROUP_KEY);
- return serviceNameBuilder.toString();
- }
-
- private void appendIfPresent(StringBuilder target, URL url, String parameterName) {
- String parameterValue = url.getParameter(parameterName);
- if (!org.apache.commons.lang3.StringUtils.isBlank(parameterValue)) {
- target.append(SERVICE_NAME_SEPARATOR).append(parameterValue);
- }
- }
-
-
- private boolean isAdminProtocol(URL url) {
- return ADMIN_PROTOCOL.equals(url.getProtocol());
- }
-
- private void scheduleServiceNamesLookup(final URL url, final NotifyListener listener) {
- if (scheduledExecutorService == null) {
- scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
- scheduledExecutorService.scheduleAtFixedRate(() -> {
- Set<String> serviceNames = getAllServiceNames();
- filterData(serviceNames, serviceName -> {
- boolean accepted = false;
- for (String category : ALL_SUPPORTED_CATEGORIES) {
- String prefix = category + SERVICE_NAME_SEPARATOR;
- if (serviceName != null && serviceName.startsWith(prefix)) {
- accepted = true;
- break;
- }
- }
- return accepted;
- });
- doSubscribe(url, listener, serviceNames);
- }, LOOKUP_INTERVAL, LOOKUP_INTERVAL, TimeUnit.SECONDS);
- }
- }
-
- /**
- * Get the service names for Dubbo OPS
- *
- * @param url {@link URL}
- * @return non-null
- */
- private Set<String> getServiceNamesForOps(URL url) {
- Set<String> serviceNames = getAllServiceNames();
- filterServiceNames(serviceNames, url);
- return serviceNames;
- }
-
- private Set<String> getAllServiceNames() {
-
- final Set<String> serviceNames = new LinkedHashSet<>();
-
- execute(namingService -> {
-
- int pageIndex = 1;
- ListView<String> listView = namingService.getServicesOfServer(pageIndex, PAGINATION_SIZE,
- getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP));
- // First page data
- List<String> firstPageData = listView.getData();
- // Append first page into list
- serviceNames.addAll(firstPageData);
- // the total count
- int count = listView.getCount();
- // the number of pages
- int pageNumbers = count / PAGINATION_SIZE;
- int remainder = count % PAGINATION_SIZE;
- // remain
- if (remainder > 0) {
- pageNumbers += 1;
- }
- // If more than 1 page
- while (pageIndex < pageNumbers) {
- listView = namingService.getServicesOfServer(++pageIndex, PAGINATION_SIZE,
- getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP));
- serviceNames.addAll(listView.getData());
- }
-
- });
-
- return serviceNames;
- }
-
- private void filterServiceNames(Set<String> serviceNames, URL url) {
-
- final List<String> categories = getCategories(url);
-
- final String targetServiceInterface = url.getServiceInterface();
-
- final String targetVersion = url.getParameter(VERSION_KEY, "");
-
- final String targetGroup = url.getParameter(GROUP_KEY, "");
-
- filterData(serviceNames, serviceName -> {
- // split service name to segments
- // (required) segments[0] = category
- // (required) segments[1] = serviceInterface
- // (optional) segments[2] = version
- // (optional) segments[3] = group
- 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 (!categories.contains(category)) { // no match category
- return false;
- }
-
- String serviceInterface = segments[SERVICE_INTERFACE_INDEX];
- // no match service interface
- if (!WILDCARD.equals(targetServiceInterface) &&
- !StringUtils.isEquals(targetServiceInterface, serviceInterface)) {
- return false;
- }
-
- // no match service version
- String version = segments[SERVICE_VERSION_INDEX];
- if (!WILDCARD.equals(targetVersion) && !StringUtils.isEquals(targetVersion, version)) {
- return false;
- }
-
- String group = segments[SERVICE_GROUP_INDEX];
- return group == null || WILDCARD.equals(targetGroup) || StringUtils.isEquals(targetGroup, group);
- });
- }
-
- private <T> void filterData(Collection<T> collection, NacosDataFilter<T> filter) {
- // remove if not accept
- collection.removeIf(data -> !filter.accept(data));
- }
-
- @Deprecated
- private List<String> doGetServiceNames(URL url) {
- 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);
- }
- return serviceNames;
- }
-
- private List<URL> toUrlWithEmpty(URL consumerURL, Collection<Instance> instances) {
- List<URL> urls = buildURLs(consumerURL, instances);
- if (urls.size() == 0) {
- URL empty = URLBuilder.from(consumerURL)
- .setProtocol(EMPTY_PROTOCOL)
- .addParameter(CATEGORY_KEY, DEFAULT_CATEGORY)
- .build();
- urls.add(empty);
- }
- return urls;
- }
-
- private List<URL> buildURLs(URL consumerURL, Collection<Instance> instances) {
- List<URL> urls = new LinkedList<>();
- if (instances != null && !instances.isEmpty()) {
- for (Instance instance : instances) {
- URL url = buildURL(instance);
- if (UrlUtils.isMatch(consumerURL, url)) {
- urls.add(url);
- }
- }
- }
- return urls;
- }
-
- private void subscribeEventListener(String serviceName, final URL url, final NotifyListener listener)
- throws NacosException {
- EventListener eventListener = event -> {
- if (event instanceof NamingEvent) {
- NamingEvent e = (NamingEvent) event;
- List<Instance> instances = e.getInstances();
-
-
- if (isServiceNamesWithCompatibleMode(url)) {
- /**
- * Get all instances with corresponding serviceNames to avoid instance overwrite and but with empty instance mentioned
- * in https://github.com/apache/dubbo/issues/5885 and https://github.com/apache/dubbo/issues/5899
- */
- NacosInstanceManageUtil.initOrRefreshServiceInstanceList(serviceName, instances);
- instances = NacosInstanceManageUtil.getAllCorrespondingServiceInstanceList(serviceName);
- }
-
- notifySubscriber(url, listener, instances);
- }
- };
- namingService.subscribe(serviceName,
- getUrl().getParameter(GROUP_KEY, Constants.DEFAULT_GROUP),
- eventListener);
- }
-
- /**
- * Notify the Healthy {@link Instance instances} to subscriber.
- *
- * @param url {@link URL}
- * @param listener {@link NotifyListener}
- * @param instances all {@link Instance instances}
- */
- private void notifySubscriber(URL url, NotifyListener listener, Collection<Instance> instances) {
- List<Instance> healthyInstances = new LinkedList<>(instances);
- if (healthyInstances.size() > 0) {
- // Healthy Instances
- filterHealthyInstances(healthyInstances);
- }
- List<URL> urls = toUrlWithEmpty(url, healthyInstances);
- NacosRegistry.this.notify(url, listener, urls);
- }
-
- /**
- * Get the categories from {@link URL}
- *
- * @param url {@link URL}
- * @return non-null array
- */
- private List<String> getCategories(URL url) {
- return ANY_VALUE.equals(url.getServiceInterface()) ?
- ALL_SUPPORTED_CATEGORIES : Arrays.asList(DEFAULT_CATEGORY);
- }
-
- private URL buildURL(Instance instance) {
- Map<String, String> metadata = instance.getMetadata();
- String protocol = metadata.get(PROTOCOL_KEY);
- String path = metadata.get(PATH_KEY);
- return new URL(protocol,
- instance.getIp(),
- instance.getPort(),
- path,
- instance.getMetadata());
- }
-
- private Instance createInstance(URL url) {
- // Append default category if absent
- String category = url.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY);
- URL newURL = url.addParameter(CATEGORY_KEY, category);
- newURL = newURL.addParameter(PROTOCOL_KEY, url.getProtocol());
- newURL = newURL.addParameter(PATH_KEY, url.getPath());
- String ip = url.getHost();
- int port = url.getPort();
- Instance instance = new Instance();
- instance.setIp(ip);
- instance.setPort(port);
- instance.setMetadata(new HashMap<>(newURL.getParameters()));
- return instance;
- }
-
- private NacosServiceName createServiceName(URL url) {
- return valueOf(url);
- }
-
- private String getServiceName(URL url) {
- return getServiceName(url, url.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY));
- }
-
- private String getServiceName(URL url, String category) {
- return category + SERVICE_NAME_SEPARATOR + url.getColonSeparatedKey();
- }
-
- private void execute(NamingServiceCallback callback) {
- try {
- callback.callback(namingService);
- } catch (NacosException e) {
- if (logger.isErrorEnabled()) {
- logger.error(e.getErrMsg(), e);
- }
- }
- }
-
- private void filterHealthyInstances(Collection<Instance> instances) {
- filterData(instances, Instance::isEnabled);
- }
-
- /**
- * A filter for Nacos data
- *
- * @since 2.6.5
- */
- private interface NacosDataFilter<T> {
-
- /**
- * Tests whether or not the specified data should be accepted.
- *
- * @param data The data to be tested
- * @return <code>true</code> if and only if <code>data</code>
- * should be accepted
- */
- boolean accept(T data);
-
- }
-
- /**
- * {@link NamingService} Callback
- *
- * @since 2.6.5
- */
- interface NamingServiceCallback {
-
- /**
- * Callback
- *
- * @param namingService {@link NamingService}
- * @throws NacosException
- */
- void callback(NamingService namingService) throws NacosException;
-
- }
-}
\ No newline at end of file
diff --git a/dubbo-spi-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistryFactory.java b/dubbo-spi-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistryFactory.java
deleted file mode 100644
index 380280e..0000000
--- a/dubbo-spi-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistryFactory.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.registry.nacos;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.registry.Registry;
-import org.apache.dubbo.registry.RegistryFactory;
-import org.apache.dubbo.registry.support.AbstractRegistryFactory;
-
-import static org.apache.dubbo.registry.nacos.util.NacosNamingServiceUtils.createNamingService;
-
-/**
- * Nacos {@link RegistryFactory}
- *
- * @since 2.6.5
- */
-public class NacosRegistryFactory extends AbstractRegistryFactory {
-
- @Override
- protected String createRegistryCacheKey(URL url) {
- return url.toFullString();
- }
-
- @Override
- protected Registry createRegistry(URL url) {
- return new NacosRegistry(url, createNamingService(url));
- }
-}
diff --git a/dubbo-spi-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscovery.java b/dubbo-spi-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscovery.java
deleted file mode 100644
index f27a50d..0000000
--- a/dubbo-spi-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscovery.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.registry.nacos;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.function.ThrowableFunction;
-import org.apache.dubbo.common.logger.Logger;
-import org.apache.dubbo.common.logger.LoggerFactory;
-import org.apache.dubbo.registry.client.ServiceDiscovery;
-import org.apache.dubbo.registry.client.ServiceInstance;
-import org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener;
-import org.apache.dubbo.registry.nacos.util.NacosNamingServiceUtils;
-
-import com.alibaba.nacos.api.naming.NamingService;
-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 java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import static org.apache.dubbo.common.function.ThrowableConsumer.execute;
-import static org.apache.dubbo.registry.nacos.util.NacosNamingServiceUtils.createNamingService;
-import static org.apache.dubbo.registry.nacos.util.NacosNamingServiceUtils.getGroup;
-import static org.apache.dubbo.registry.nacos.util.NacosNamingServiceUtils.toInstance;
-
-/**
- * Nacos {@link ServiceDiscovery} implementation
- *
- * @see ServiceDiscovery
- * @since 2.7.5
- */
-public class NacosServiceDiscovery implements ServiceDiscovery {
-
- private final Logger logger = LoggerFactory.getLogger(getClass());
-
- private String group;
-
- private NamingService namingService;
-
- @Override
- public void initialize(URL registryURL) throws Exception {
- this.namingService = createNamingService(registryURL);
- this.group = getGroup(registryURL);
- }
-
- @Override
- public void destroy() {
- this.namingService = null;
- }
-
- @Override
- public void register(ServiceInstance serviceInstance) throws RuntimeException {
- execute(namingService, service -> {
- Instance instance = toInstance(serviceInstance);
- service.registerInstance(instance.getServiceName(), group, instance);
- });
- }
-
- @Override
- public void update(ServiceInstance serviceInstance) throws RuntimeException {
- // TODO: Nacos should support
- unregister(serviceInstance);
- register(serviceInstance);
- }
-
- @Override
- public void unregister(ServiceInstance serviceInstance) throws RuntimeException {
- execute(namingService, service -> {
- Instance instance = toInstance(serviceInstance);
- service.deregisterInstance(instance.getServiceName(), group, instance);
- });
- }
-
- @Override
- public Set<String> getServices() {
- return ThrowableFunction.execute(namingService, service -> {
- ListView<String> view = service.getServicesOfServer(0, Integer.MAX_VALUE, group);
- return new LinkedHashSet<>(view.getData());
- });
- }
-
- @Override
- public List<ServiceInstance> getInstances(String serviceName) throws NullPointerException {
- return ThrowableFunction.execute(namingService, service ->
- service.selectInstances(serviceName, true)
- .stream().map(NacosNamingServiceUtils::toServiceInstance)
- .collect(Collectors.toList())
- );
- }
-
- @Override
- public void addServiceInstancesChangedListener(ServiceInstancesChangedListener listener)
- throws NullPointerException, IllegalArgumentException {
- execute(namingService, service -> {
- service.subscribe(listener.getServiceName(), e -> { // Register Nacos EventListener
- if (e instanceof NamingEvent) {
- NamingEvent event = (NamingEvent) e;
- handleEvent(event, listener);
- }
- });
- });
- }
-
- private void handleEvent(NamingEvent event, ServiceInstancesChangedListener listener) {
- String serviceName = event.getServiceName();
- Collection<ServiceInstance> serviceInstances = event.getInstances()
- .stream()
- .map(NacosNamingServiceUtils::toServiceInstance)
- .collect(Collectors.toList());
- dispatchServiceInstancesChangedEvent(serviceName, serviceInstances);
- }
-}
diff --git a/dubbo-spi-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceName.java b/dubbo-spi-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceName.java
deleted file mode 100644
index 27c45ee..0000000
--- a/dubbo-spi-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceName.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.registry.nacos;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.utils.StringUtils;
-
-import java.util.Arrays;
-import java.util.Objects;
-
-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;
-
-/**
- * The service name of Nacos
- *
- * @since 2.7.3
- */
-public class NacosServiceName {
-
- public static final String NAME_SEPARATOR = ":";
-
- public static final String VALUE_SEPARATOR = ",";
-
- public static final String WILDCARD = "*";
-
- public static final String DEFAULT_PARAM_VALUE = "";
-
- private static final int CATEGORY_INDEX = 0;
-
- private static final int SERVICE_INTERFACE_INDEX = 1;
-
- private static final int SERVICE_VERSION_INDEX = 2;
-
- private static final int SERVICE_GROUP_INDEX = 3;
-
- private String category;
-
- private String serviceInterface;
-
- private String version;
-
- private String group;
-
- private String value;
-
- public NacosServiceName() {
- }
-
- public NacosServiceName(URL url) {
- serviceInterface = url.getParameter(INTERFACE_KEY);
- category = isConcrete(serviceInterface) ? DEFAULT_CATEGORY : url.getParameter(CATEGORY_KEY);
- version = url.getParameter(VERSION_KEY, DEFAULT_PARAM_VALUE);
- group = url.getParameter(GROUP_KEY, DEFAULT_PARAM_VALUE);
- value = toValue();
- }
-
- public NacosServiceName(String value) {
- this.value = value;
- String[] segments = value.split(NAME_SEPARATOR, -1);
- this.category = segments[CATEGORY_INDEX];
- this.serviceInterface = segments[SERVICE_INTERFACE_INDEX];
- this.version = segments[SERVICE_VERSION_INDEX];
- this.group = segments[SERVICE_GROUP_INDEX];
- }
-
- /**
- * Build an instance of {@link NacosServiceName}
- *
- * @param url
- * @return
- */
- public static NacosServiceName valueOf(URL url) {
- return new NacosServiceName(url);
- }
-
- /**
- * Is the concrete service name or not
- *
- * @return if concrete , return <code>true</code>, or <code>false</code>
- */
- public boolean isConcrete() {
- return isConcrete(serviceInterface) && isConcrete(version) && isConcrete(group);
- }
-
- public boolean isCompatible(NacosServiceName concreteServiceName) {
-
- if (!concreteServiceName.isConcrete()) { // The argument must be the concrete NacosServiceName
- return false;
- }
-
- // Not match comparison
- if (!StringUtils.isEquals(this.category, concreteServiceName.category)
- && !matchRange(this.category, concreteServiceName.category)) {
- return false;
- }
-
- if (!StringUtils.isEquals(this.serviceInterface, concreteServiceName.serviceInterface)) {
- return false;
- }
-
- // wildcard condition
- if (isWildcard(this.version)) {
- return true;
- }
-
- if (isWildcard(this.group)) {
- return true;
- }
-
- // range condition
- if (!StringUtils.isEquals(this.version, concreteServiceName.version)
- && !matchRange(this.version, concreteServiceName.version)) {
- return false;
- }
-
- if (!StringUtils.isEquals(this.group, concreteServiceName.group) &&
- !matchRange(this.group, concreteServiceName.group)) {
- return false;
- }
-
- return true;
- }
-
- private boolean matchRange(String range, String value) {
- if (isBlank(range)) {
- return true;
- }
- if (!isRange(range)) {
- return false;
- }
- String[] values = range.split(VALUE_SEPARATOR);
- return Arrays.asList(values).contains(value);
- }
-
- private boolean isConcrete(String value) {
- return !isWildcard(value) && !isRange(value);
- }
-
- private boolean isWildcard(String value) {
- return WILDCARD.equals(value);
- }
-
- private boolean isRange(String value) {
- return value != null && value.indexOf(VALUE_SEPARATOR) > -1 && value.split(VALUE_SEPARATOR).length > 1;
- }
-
- public String getCategory() {
- return category;
- }
-
- public void setCategory(String category) {
- this.category = category;
- }
-
- public String getServiceInterface() {
- return serviceInterface;
- }
-
- public void setServiceInterface(String serviceInterface) {
- this.serviceInterface = serviceInterface;
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-
- public String getGroup() {
- return group;
- }
-
- public void setGroup(String group) {
- this.group = group;
- }
-
- public String getValue() {
- if (value == null) {
- value = toValue();
- }
- return value;
- }
-
- private String toValue() {
- return new StringBuilder(category)
- .append(NAME_SEPARATOR).append(serviceInterface)
- .append(NAME_SEPARATOR).append(version)
- .append(NAME_SEPARATOR).append(group)
- .toString();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof NacosServiceName)) {
- return false;
- }
- NacosServiceName that = (NacosServiceName) o;
- return Objects.equals(getValue(), that.getValue());
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(getValue());
- }
-
- @Override
- public String toString() {
- return getValue();
- }
-}
diff --git a/dubbo-spi-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/util/NacosInstanceManageUtil.java b/dubbo-spi-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/util/NacosInstanceManageUtil.java
deleted file mode 100644
index 190a5aa..0000000
--- a/dubbo-spi-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/util/NacosInstanceManageUtil.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.registry.nacos.util;
-
-import com.alibaba.nacos.api.naming.pojo.Instance;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import org.apache.dubbo.common.utils.CollectionUtils;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Instance manage util for multiple serviceNames
- * To resolve bug with https://github.com/apache/dubbo/issues/5885 and https://github.com/apache/dubbo/issues/5899
- *
- * @since 2.7.6
- */
-public class NacosInstanceManageUtil {
-
- /**
- * serviceName -> refreshed instance list
- */
- private static final Map<String, List<Instance>> SERVICE_INSTANCE_LIST_MAP = Maps.newConcurrentMap();
-
- /**
- * serviceName -> corresponding serviceName list
- */
- private static final Map<String, Set<String>> CORRESPONDING_SERVICE_NAMES_MAP = Maps.newConcurrentMap();
-
- public static void setCorrespondingServiceNames(String serviceName, Set<String> serviceNames) {
- CORRESPONDING_SERVICE_NAMES_MAP.put(serviceName, serviceNames);
- }
-
- public static void initOrRefreshServiceInstanceList(String serviceName, List<Instance> instanceList) {
- SERVICE_INSTANCE_LIST_MAP.put(serviceName, instanceList);
- }
-
- public static List<Instance> getAllCorrespondingServiceInstanceList(String serviceName) {
- if (!CORRESPONDING_SERVICE_NAMES_MAP.containsKey(serviceName)) {
- return Lists.newArrayList();
- }
- List<Instance> allInstances = Lists.newArrayList();
- for (String correspondingServiceName : CORRESPONDING_SERVICE_NAMES_MAP.get(serviceName)) {
- if (SERVICE_INSTANCE_LIST_MAP.containsKey(correspondingServiceName) && CollectionUtils.isNotEmpty(SERVICE_INSTANCE_LIST_MAP.get(correspondingServiceName))) {
- allInstances.addAll(SERVICE_INSTANCE_LIST_MAP.get(correspondingServiceName));
- }
- }
- return allInstances;
- }
-
-}
diff --git a/dubbo-spi-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/util/NacosNamingServiceUtils.java b/dubbo-spi-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/util/NacosNamingServiceUtils.java
deleted file mode 100644
index 5644474..0000000
--- a/dubbo-spi-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/util/NacosNamingServiceUtils.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.registry.nacos.util;
-
-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.StringUtils;
-import org.apache.dubbo.registry.client.DefaultServiceInstance;
-import org.apache.dubbo.registry.client.ServiceInstance;
-
-import com.alibaba.nacos.api.NacosFactory;
-import com.alibaba.nacos.api.exception.NacosException;
-import com.alibaba.nacos.api.naming.NamingService;
-import com.alibaba.nacos.api.naming.pojo.Instance;
-
-import java.util.Properties;
-
-import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY;
-import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME;
-import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_LONG_POLL_TIMEOUT;
-import static com.alibaba.nacos.api.PropertyKeyConst.CONFIG_RETRY_TIME;
-import static com.alibaba.nacos.api.PropertyKeyConst.CONTEXT_PATH;
-import static com.alibaba.nacos.api.PropertyKeyConst.ENABLE_REMOTE_SYNC_CONFIG;
-import static com.alibaba.nacos.api.PropertyKeyConst.ENCODE;
-import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT;
-import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT_PORT;
-import static com.alibaba.nacos.api.PropertyKeyConst.IS_USE_CLOUD_NAMESPACE_PARSING;
-import static com.alibaba.nacos.api.PropertyKeyConst.IS_USE_ENDPOINT_PARSING_RULE;
-import static com.alibaba.nacos.api.PropertyKeyConst.MAX_RETRY;
-import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
-import static com.alibaba.nacos.api.PropertyKeyConst.NAMING_CLIENT_BEAT_THREAD_COUNT;
-import static com.alibaba.nacos.api.PropertyKeyConst.NAMING_LOAD_CACHE_AT_START;
-import static com.alibaba.nacos.api.PropertyKeyConst.NAMING_POLLING_THREAD_COUNT;
-import static com.alibaba.nacos.api.PropertyKeyConst.RAM_ROLE_NAME;
-import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY;
-import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
-import static com.alibaba.nacos.api.common.Constants.DEFAULT_GROUP;
-import static com.alibaba.nacos.client.naming.utils.UtilAndComs.NACOS_NAMING_LOG_NAME;
-import static org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY;
-
-/**
- * The utilities class for {@link NamingService}
- *
- * @since 2.7.5
- */
-public class NacosNamingServiceUtils {
-
- private static final Logger logger = LoggerFactory.getLogger(NacosNamingServiceUtils.class);
-
- /**
- * Convert the {@link ServiceInstance} to {@link Instance}
- *
- * @param serviceInstance {@link ServiceInstance}
- * @return non-null
- * @since 2.7.5
- */
- public static Instance toInstance(ServiceInstance serviceInstance) {
- Instance instance = new Instance();
- instance.setInstanceId(serviceInstance.getId());
- instance.setServiceName(serviceInstance.getServiceName());
- instance.setIp(serviceInstance.getHost());
- instance.setPort(serviceInstance.getPort());
- instance.setMetadata(serviceInstance.getMetadata());
- instance.setEnabled(serviceInstance.isEnabled());
- instance.setHealthy(serviceInstance.isHealthy());
- return instance;
- }
-
- /**
- * Convert the {@link Instance} to {@link ServiceInstance}
- *
- * @param instance {@link Instance}
- * @return non-null
- * @since 2.7.5
- */
- public static ServiceInstance toServiceInstance(Instance instance) {
- DefaultServiceInstance serviceInstance = new DefaultServiceInstance(instance.getInstanceId(),
- instance.getServiceName(), instance.getIp(), instance.getPort());
- serviceInstance.setMetadata(instance.getMetadata());
- serviceInstance.setEnabled(instance.isEnabled());
- serviceInstance.setHealthy(instance.isHealthy());
- return serviceInstance;
- }
-
- /**
- * The group of {@link NamingService} to register
- *
- * @param connectionURL {@link URL connection url}
- * @return non-null, "default" as default
- * @since 2.7.5
- */
- public static String getGroup(URL connectionURL) {
- return connectionURL.getParameter("nacos.group", DEFAULT_GROUP);
- }
-
- /**
- * Create an instance of {@link NamingService} from specified {@link URL connection url}
- *
- * @param connectionURL {@link URL connection url}
- * @return {@link NamingService}
- * @since 2.7.5
- */
- public static NamingService createNamingService(URL connectionURL) {
- Properties nacosProperties = buildNacosProperties(connectionURL);
- NamingService namingService;
- try {
- namingService = NacosFactory.createNamingService(nacosProperties);
- } catch (NacosException e) {
- if (logger.isErrorEnabled()) {
- logger.error(e.getErrMsg(), e);
- }
- throw new IllegalStateException(e);
- }
- return namingService;
- }
-
- private static Properties buildNacosProperties(URL url) {
- Properties properties = new Properties();
- setServerAddr(url, properties);
- setProperties(url, properties);
- return properties;
- }
-
- private static void setServerAddr(URL url, Properties properties) {
- StringBuilder serverAddrBuilder =
- new StringBuilder(url.getHost()) // Host
- .append(":")
- .append(url.getPort()); // Port
-
- // Append backup parameter as other servers
- String backup = url.getParameter(BACKUP_KEY);
- if (backup != null) {
- serverAddrBuilder.append(",").append(backup);
- }
-
- String serverAddr = serverAddrBuilder.toString();
- properties.put(SERVER_ADDR, serverAddr);
- }
-
- private static void setProperties(URL url, Properties properties) {
- putPropertyIfAbsent(url, properties, NACOS_NAMING_LOG_NAME);
- putPropertyIfAbsent(url, properties, IS_USE_CLOUD_NAMESPACE_PARSING);
- putPropertyIfAbsent(url, properties, IS_USE_ENDPOINT_PARSING_RULE);
- putPropertyIfAbsent(url, properties, ENDPOINT);
- putPropertyIfAbsent(url, properties, ENDPOINT_PORT);
- putPropertyIfAbsent(url, properties, NAMESPACE);
- putPropertyIfAbsent(url, properties, ACCESS_KEY);
- putPropertyIfAbsent(url, properties, SECRET_KEY);
- putPropertyIfAbsent(url, properties, RAM_ROLE_NAME);
- putPropertyIfAbsent(url, properties, CONTEXT_PATH);
- putPropertyIfAbsent(url, properties, CLUSTER_NAME);
- putPropertyIfAbsent(url, properties, ENCODE);
- putPropertyIfAbsent(url, properties, CONFIG_LONG_POLL_TIMEOUT);
- putPropertyIfAbsent(url, properties, CONFIG_RETRY_TIME);
- putPropertyIfAbsent(url, properties, MAX_RETRY);
- putPropertyIfAbsent(url, properties, ENABLE_REMOTE_SYNC_CONFIG);
- putPropertyIfAbsent(url, properties, NAMING_LOAD_CACHE_AT_START, "true");
- putPropertyIfAbsent(url, properties, NAMING_CLIENT_BEAT_THREAD_COUNT);
- putPropertyIfAbsent(url, properties, NAMING_POLLING_THREAD_COUNT);
- }
-
- private static void putPropertyIfAbsent(URL url, Properties properties, String propertyName) {
- String propertyValue = url.getParameter(propertyName);
- if (StringUtils.isNotEmpty(propertyValue)) {
- properties.setProperty(propertyName, propertyValue);
- }
- }
-
- private static void putPropertyIfAbsent(URL url, Properties properties, String propertyName, String defaultValue) {
- String propertyValue = url.getParameter(propertyName);
- if (StringUtils.isNotEmpty(propertyValue)) {
- properties.setProperty(propertyName, propertyValue);
- } else {
- properties.setProperty(propertyName, defaultValue);
- }
- }
-}
diff --git a/dubbo-spi-registry/dubbo-registry-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory b/dubbo-spi-registry/dubbo-registry-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory
deleted file mode 100644
index bb75467..0000000
--- a/dubbo-spi-registry/dubbo-registry-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory
+++ /dev/null
@@ -1 +0,0 @@
-nacos=org.apache.dubbo.registry.nacos.NacosRegistryFactory
\ No newline at end of file
diff --git a/dubbo-spi-registry/dubbo-registry-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscovery b/dubbo-spi-registry/dubbo-registry-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscovery
deleted file mode 100644
index e3819e0..0000000
--- a/dubbo-spi-registry/dubbo-registry-nacos/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscovery
+++ /dev/null
@@ -1 +0,0 @@
-nacos=org.apache.dubbo.registry.nacos.NacosServiceDiscovery
\ No newline at end of file
diff --git a/dubbo-spi-registry/pom.xml b/dubbo-spi-registry/pom.xml
index d34c24b..c4e4ca7 100644
--- a/dubbo-spi-registry/pom.xml
+++ b/dubbo-spi-registry/pom.xml
@@ -33,8 +33,6 @@
<module>dubbo-registry-redis</module>
<module>dubbo-registry-consul</module>
<module>dubbo-registry-etcd3</module>
- <module>dubbo-registry-nacos</module>
- <module>dubbo-registry-multiple</module>
<module>dubbo-registry-sofa</module>
<module>dubbo-registry-eureka</module>
</modules>
diff --git a/dubbo-spi-remoting/dubbo-remoting-zookeeper/pom.xml b/dubbo-spi-remoting/dubbo-remoting-zookeeper/pom.xml
deleted file mode 100644
index d17713c..0000000
--- a/dubbo-spi-remoting/dubbo-remoting-zookeeper/pom.xml
+++ /dev/null
@@ -1,56 +0,0 @@
-<!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You under the Apache License, Version 2.0
- (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-remoting</artifactId>
- <version>2.7.7-SNAPSHOT</version>
- </parent>
- <artifactId>dubbo-remoting-zookeeper</artifactId>
- <packaging>jar</packaging>
- <name>${project.artifactId}</name>
- <description>The zookeeper remoting module of dubbo project</description>
- <properties>
- <skip_maven_deploy>false</skip_maven_deploy>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-remoting-api</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-common</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-recipes</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.zookeeper</groupId>
- <artifactId>zookeeper</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-test</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
diff --git a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/ChildListener.java b/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/ChildListener.java
deleted file mode 100644
index 0e876af..0000000
--- a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/ChildListener.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.remoting.zookeeper;
-
-import java.util.List;
-
-public interface ChildListener {
-
- void childChanged(String path, List<String> children);
-
-}
diff --git a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/DataListener.java b/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/DataListener.java
deleted file mode 100644
index 95b948a..0000000
--- a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/DataListener.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.remoting.zookeeper;
-
-/**
- * 2019-02-26
- */
-public interface DataListener {
-
- void dataChanged(String path, Object value, EventType eventType);
-}
diff --git a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/EventType.java b/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/EventType.java
deleted file mode 100644
index a1de037..0000000
--- a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/EventType.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.remoting.zookeeper;
-
-import org.apache.zookeeper.Watcher;
-
-/**
- * 2019-02-26
- */
-public enum EventType {
- None(-1),
- NodeCreated(1),
- NodeDeleted(2),
- NodeDataChanged(3),
- NodeChildrenChanged(4),
- CONNECTION_SUSPENDED(11),
- CONNECTION_RECONNECTED(12),
- CONNECTION_LOST(12),
- INITIALIZED(10);
-
-
-
- private final int intValue; // Integer representation of value
- // for sending over wire
-
- EventType(int intValue) {
- this.intValue = intValue;
- }
-
- public int getIntValue() {
- return intValue;
- }
-
- public static Watcher.Event.EventType fromInt(int intValue) {
- switch (intValue) {
- case -1:
- return Watcher.Event.EventType.None;
- case 1:
- return Watcher.Event.EventType.NodeCreated;
- case 2:
- return Watcher.Event.EventType.NodeDeleted;
- case 3:
- return Watcher.Event.EventType.NodeDataChanged;
- case 4:
- return Watcher.Event.EventType.NodeChildrenChanged;
-
- default:
- throw new RuntimeException("Invalid integer value for conversion to EventType");
- }
- }
-}
diff --git a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/StateListener.java b/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/StateListener.java
deleted file mode 100644
index ca4dbe0..0000000
--- a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/StateListener.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.remoting.zookeeper;
-
-public interface StateListener {
-
- int SESSION_LOST = 0;
-
- int CONNECTED = 1;
-
- int RECONNECTED = 2;
-
- int SUSPENDED = 3;
-
- int NEW_SESSION_CREATED = 4;
-
- void stateChanged(int connected);
-
-}
diff --git a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperClient.java b/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperClient.java
deleted file mode 100644
index cbb3747..0000000
--- a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperClient.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.remoting.zookeeper;
-
-import org.apache.dubbo.common.URL;
-
-import java.util.List;
-import java.util.concurrent.Executor;
-
-public interface ZookeeperClient {
-
- void create(String path, boolean ephemeral);
-
- void delete(String path);
-
- List<String> getChildren(String path);
-
- List<String> addChildListener(String path, ChildListener listener);
-
- /**
- * @param path: directory. All of child of path will be listened.
- * @param listener
- */
- void addDataListener(String path, DataListener listener);
-
- /**
- * @param path: directory. All of child of path will be listened.
- * @param listener
- * @param executor another thread
- */
- void addDataListener(String path, DataListener listener, Executor executor);
-
- void removeDataListener(String path, DataListener listener);
-
- void removeChildListener(String path, ChildListener listener);
-
- void addStateListener(StateListener listener);
-
- void removeStateListener(StateListener listener);
-
- boolean isConnected();
-
- void close();
-
- URL getUrl();
-
- void create(String path, String content, boolean ephemeral);
-
- String getContent(String path);
-
-}
diff --git a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperTransporter.java b/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperTransporter.java
deleted file mode 100644
index 638f3ed..0000000
--- a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/ZookeeperTransporter.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.remoting.zookeeper;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.Adaptive;
-import org.apache.dubbo.common.extension.SPI;
-import org.apache.dubbo.remoting.Constants;
-
-@SPI("curator")
-public interface ZookeeperTransporter {
-
- @Adaptive({Constants.CLIENT_KEY, Constants.TRANSPORTER_KEY})
- ZookeeperClient connect(URL url);
-
-}
diff --git a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java b/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java
deleted file mode 100644
index e830e11..0000000
--- a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java
+++ /dev/null
@@ -1,398 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.remoting.zookeeper.curator;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.logger.Logger;
-import org.apache.dubbo.common.logger.LoggerFactory;
-import org.apache.dubbo.remoting.zookeeper.ChildListener;
-import org.apache.dubbo.remoting.zookeeper.DataListener;
-import org.apache.dubbo.remoting.zookeeper.EventType;
-import org.apache.dubbo.remoting.zookeeper.StateListener;
-import org.apache.dubbo.remoting.zookeeper.support.AbstractZookeeperClient;
-
-import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.CuratorFrameworkFactory;
-import org.apache.curator.framework.api.CuratorWatcher;
-import org.apache.curator.framework.recipes.cache.TreeCache;
-import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
-import org.apache.curator.framework.recipes.cache.TreeCacheListener;
-import org.apache.curator.framework.state.ConnectionState;
-import org.apache.curator.framework.state.ConnectionStateListener;
-import org.apache.curator.retry.RetryNTimes;
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException.NoNodeException;
-import org.apache.zookeeper.KeeperException.NodeExistsException;
-import org.apache.zookeeper.WatchedEvent;
-import org.apache.zookeeper.Watcher;
-
-import java.nio.charset.Charset;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.Executor;
-import java.util.concurrent.TimeUnit;
-
-import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
-
-public class CuratorZookeeperClient extends AbstractZookeeperClient<CuratorZookeeperClient.CuratorWatcherImpl, CuratorZookeeperClient.CuratorWatcherImpl> {
-
- protected static final Logger logger = LoggerFactory.getLogger(CuratorZookeeperClient.class);
- private static final String ZK_SESSION_EXPIRE_KEY = "zk.session.expire";
-
- static final Charset CHARSET = Charset.forName("UTF-8");
- private final CuratorFramework client;
- private Map<String, TreeCache> treeCacheMap = new ConcurrentHashMap<>();
-
- public CuratorZookeeperClient(URL url) {
- super(url);
- try {
- int timeout = url.getParameter(TIMEOUT_KEY, DEFAULT_CONNECTION_TIMEOUT_MS);
- int sessionExpireMs = url.getParameter(ZK_SESSION_EXPIRE_KEY, DEFAULT_SESSION_TIMEOUT_MS);
- CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
- .connectString(url.getBackupAddress())
- .retryPolicy(new RetryNTimes(1, 1000))
- .connectionTimeoutMs(timeout)
- .sessionTimeoutMs(sessionExpireMs);
- String authority = url.getAuthority();
- if (authority != null && authority.length() > 0) {
- builder = builder.authorization("digest", authority.getBytes());
- }
- client = builder.build();
- client.getConnectionStateListenable().addListener(new CuratorConnectionStateListener(url));
- client.start();
- boolean connected = client.blockUntilConnected(timeout, TimeUnit.MILLISECONDS);
- if (!connected) {
- throw new IllegalStateException("zookeeper not connected");
- }
- } catch (Exception e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
-
- @Override
- public void createPersistent(String path) {
- try {
- client.create().forPath(path);
- } catch (NodeExistsException e) {
- logger.warn("ZNode " + path + " already exists.", e);
- } catch (Exception e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
-
- @Override
- public void createEphemeral(String path) {
- try {
- client.create().withMode(CreateMode.EPHEMERAL).forPath(path);
- } catch (NodeExistsException e) {
- logger.warn("ZNode " + path + " already exists, since we will only try to recreate a node on a session expiration" +
- ", this duplication might be caused by a delete delay from the zk server, which means the old expired session" +
- " may still holds this ZNode and the server just hasn't got time to do the deletion. In this case, " +
- "we can just try to delete and create again.", e);
- deletePath(path);
- createEphemeral(path);
- } catch (Exception e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
-
- @Override
- protected void createPersistent(String path, String data) {
- byte[] dataBytes = data.getBytes(CHARSET);
- try {
- client.create().forPath(path, dataBytes);
- } catch (NodeExistsException e) {
- try {
- client.setData().forPath(path, dataBytes);
- } catch (Exception e1) {
- throw new IllegalStateException(e.getMessage(), e1);
- }
- } catch (Exception e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
-
- @Override
- protected void createEphemeral(String path, String data) {
- byte[] dataBytes = data.getBytes(CHARSET);
- try {
- client.create().withMode(CreateMode.EPHEMERAL).forPath(path, dataBytes);
- } catch (NodeExistsException e) {
- logger.warn("ZNode " + path + " already exists, since we will only try to recreate a node on a session expiration" +
- ", this duplication might be caused by a delete delay from the zk server, which means the old expired session" +
- " may still holds this ZNode and the server just hasn't got time to do the deletion. In this case, " +
- "we can just try to delete and create again.", e);
- deletePath(path);
- createEphemeral(path, data);
- } catch (Exception e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
-
- @Override
- protected void deletePath(String path) {
- try {
- client.delete().deletingChildrenIfNeeded().forPath(path);
- } catch (NoNodeException e) {
- } catch (Exception e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
-
- @Override
- public List<String> getChildren(String path) {
- try {
- return client.getChildren().forPath(path);
- } catch (NoNodeException e) {
- return null;
- } catch (Exception e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
-
- @Override
- public boolean checkExists(String path) {
- try {
- if (client.checkExists().forPath(path) != null) {
- return true;
- }
- } catch (Exception e) {
- }
- return false;
- }
-
- @Override
- public boolean isConnected() {
- return client.getZookeeperClient().isConnected();
- }
-
- @Override
- public String doGetContent(String path) {
- try {
- byte[] dataBytes = client.getData().forPath(path);
- return (dataBytes == null || dataBytes.length == 0) ? null : new String(dataBytes, CHARSET);
- } catch (NoNodeException e) {
- // ignore NoNode Exception.
- } catch (Exception e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- return null;
- }
-
- @Override
- public void doClose() {
- client.close();
- }
-
- @Override
- public CuratorZookeeperClient.CuratorWatcherImpl createTargetChildListener(String path, ChildListener listener) {
- return new CuratorZookeeperClient.CuratorWatcherImpl(client, listener, path);
- }
-
- @Override
- public List<String> addTargetChildListener(String path, CuratorWatcherImpl listener) {
- try {
- return client.getChildren().usingWatcher(listener).forPath(path);
- } catch (NoNodeException e) {
- return null;
- } catch (Exception e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
-
- @Override
- protected CuratorZookeeperClient.CuratorWatcherImpl createTargetDataListener(String path, DataListener listener) {
- return new CuratorWatcherImpl(client, listener);
- }
-
- @Override
- protected void addTargetDataListener(String path, CuratorZookeeperClient.CuratorWatcherImpl treeCacheListener) {
- this.addTargetDataListener(path, treeCacheListener, null);
- }
-
- @Override
- protected void addTargetDataListener(String path, CuratorZookeeperClient.CuratorWatcherImpl treeCacheListener, Executor executor) {
- try {
- TreeCache treeCache = TreeCache.newBuilder(client, path).setCacheData(false).build();
- treeCacheMap.putIfAbsent(path, treeCache);
-
- if (executor == null) {
- treeCache.getListenable().addListener(treeCacheListener);
- } else {
- treeCache.getListenable().addListener(treeCacheListener, executor);
- }
-
- treeCache.start();
- } catch (Exception e) {
- throw new IllegalStateException("Add treeCache listener for path:" + path, e);
- }
- }
-
- @Override
- protected void removeTargetDataListener(String path, CuratorZookeeperClient.CuratorWatcherImpl treeCacheListener) {
- TreeCache treeCache = treeCacheMap.get(path);
- if (treeCache != null) {
- treeCache.getListenable().removeListener(treeCacheListener);
- }
- treeCacheListener.dataListener = null;
- }
-
- @Override
- public void removeTargetChildListener(String path, CuratorWatcherImpl listener) {
- listener.unwatch();
- }
-
- static class CuratorWatcherImpl implements CuratorWatcher, TreeCacheListener {
-
- private CuratorFramework client;
- private volatile ChildListener childListener;
- private volatile DataListener dataListener;
- private String path;
-
- public CuratorWatcherImpl(CuratorFramework client, ChildListener listener, String path) {
- this.client = client;
- this.childListener = listener;
- this.path = path;
- }
-
- public CuratorWatcherImpl(CuratorFramework client, DataListener dataListener) {
- this.dataListener = dataListener;
- }
-
- protected CuratorWatcherImpl() {
- }
-
- public void unwatch() {
- this.childListener = null;
- }
-
- @Override
- public void process(WatchedEvent event) throws Exception {
- // if client connect or disconnect to server, zookeeper will queue
- // watched event(Watcher.Event.EventType.None, .., path = null).
- if (event.getType() == Watcher.Event.EventType.None) {
- return;
- }
-
- if (childListener != null) {
- childListener.childChanged(path, client.getChildren().usingWatcher(this).forPath(path));
- }
- }
-
- @Override
- public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception {
- if (dataListener != null) {
- if (logger.isDebugEnabled()) {
- logger.debug("listen the zookeeper changed. The changed data:" + event.getData());
- }
- TreeCacheEvent.Type type = event.getType();
- EventType eventType = null;
- String content = null;
- String path = null;
- switch (type) {
- case NODE_ADDED:
- eventType = EventType.NodeCreated;
- path = event.getData().getPath();
- content = event.getData().getData() == null ? "" : new String(event.getData().getData(), CHARSET);
- break;
- case NODE_UPDATED:
- eventType = EventType.NodeDataChanged;
- path = event.getData().getPath();
- content = event.getData().getData() == null ? "" : new String(event.getData().getData(), CHARSET);
- break;
- case NODE_REMOVED:
- path = event.getData().getPath();
- eventType = EventType.NodeDeleted;
- break;
- case INITIALIZED:
- eventType = EventType.INITIALIZED;
- break;
- case CONNECTION_LOST:
- eventType = EventType.CONNECTION_LOST;
- break;
- case CONNECTION_RECONNECTED:
- eventType = EventType.CONNECTION_RECONNECTED;
- break;
- case CONNECTION_SUSPENDED:
- eventType = EventType.CONNECTION_SUSPENDED;
- break;
-
- }
- dataListener.dataChanged(path, content, eventType);
- }
- }
- }
-
- private class CuratorConnectionStateListener implements ConnectionStateListener {
- private final long UNKNOWN_SESSION_ID = -1L;
-
- private long lastSessionId;
- private URL url;
-
- public CuratorConnectionStateListener(URL url) {
- this.url = url;
- }
-
- @Override
- public void stateChanged(CuratorFramework client, ConnectionState state) {
- int timeout = url.getParameter(TIMEOUT_KEY, DEFAULT_CONNECTION_TIMEOUT_MS);
- int sessionExpireMs = url.getParameter(ZK_SESSION_EXPIRE_KEY, DEFAULT_SESSION_TIMEOUT_MS);
-
- long sessionId = UNKNOWN_SESSION_ID;
- try {
- sessionId = client.getZookeeperClient().getZooKeeper().getSessionId();
- } catch (Exception e) {
- logger.warn("Curator client state changed, but failed to get the related zk session instance.");
- }
-
- if (state == ConnectionState.LOST) {
- logger.warn("Curator zookeeper session " + Long.toHexString(lastSessionId) + " expired.");
- CuratorZookeeperClient.this.stateChanged(StateListener.SESSION_LOST);
- } else if (state == ConnectionState.SUSPENDED) {
- logger.warn("Curator zookeeper connection of session " + Long.toHexString(sessionId) + " timed out. " +
- "connection timeout value is " + timeout + ", session expire timeout value is " + sessionExpireMs);
- CuratorZookeeperClient.this.stateChanged(StateListener.SUSPENDED);
- } else if (state == ConnectionState.CONNECTED) {
- lastSessionId = sessionId;
- logger.info("Curator zookeeper client instance initiated successfully, session id is " + Long.toHexString(sessionId));
- CuratorZookeeperClient.this.stateChanged(StateListener.CONNECTED);
- } else if (state == ConnectionState.RECONNECTED) {
- if (lastSessionId == sessionId && sessionId != UNKNOWN_SESSION_ID) {
- logger.warn("Curator zookeeper connection recovered from connection lose, " +
- "reuse the old session " + Long.toHexString(sessionId));
- CuratorZookeeperClient.this.stateChanged(StateListener.RECONNECTED);
- } else {
- logger.warn("New session created after old session lost, " +
- "old session " + Long.toHexString(lastSessionId) + ", new session " + Long.toHexString(sessionId));
- lastSessionId = sessionId;
- CuratorZookeeperClient.this.stateChanged(StateListener.NEW_SESSION_CREATED);
- }
- }
- }
-
- }
-
- /**
- * just for unit test
- *
- * @return
- */
- CuratorFramework getClient() {
- return client;
- }
-}
diff --git a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperTransporter.java b/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperTransporter.java
deleted file mode 100644
index 21a2e09..0000000
--- a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperTransporter.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.remoting.zookeeper.curator;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
-import org.apache.dubbo.remoting.zookeeper.support.AbstractZookeeperTransporter;
-
-public class CuratorZookeeperTransporter extends AbstractZookeeperTransporter {
- @Override
- public ZookeeperClient createZookeeperClient(URL url) {
- return new CuratorZookeeperClient(url);
- }
-
-
-}
diff --git a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperClient.java b/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperClient.java
deleted file mode 100644
index d17697c..0000000
--- a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperClient.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.remoting.zookeeper.support;
-
-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.ConcurrentHashSet;
-import org.apache.dubbo.remoting.zookeeper.ChildListener;
-import org.apache.dubbo.remoting.zookeeper.DataListener;
-import org.apache.dubbo.remoting.zookeeper.StateListener;
-import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
-
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.concurrent.Executor;
-
-public abstract class AbstractZookeeperClient<TargetDataListener, TargetChildListener> implements ZookeeperClient {
-
- protected static final Logger logger = LoggerFactory.getLogger(AbstractZookeeperClient.class);
-
- protected int DEFAULT_CONNECTION_TIMEOUT_MS = 5 * 1000;
- protected int DEFAULT_SESSION_TIMEOUT_MS = 60 * 1000;
-
- private final URL url;
-
- private final Set<StateListener> stateListeners = new CopyOnWriteArraySet<StateListener>();
-
- private final ConcurrentMap<String, ConcurrentMap<ChildListener, TargetChildListener>> childListeners = new ConcurrentHashMap<String, ConcurrentMap<ChildListener, TargetChildListener>>();
-
- private final ConcurrentMap<String, ConcurrentMap<DataListener, TargetDataListener>> listeners = new ConcurrentHashMap<String, ConcurrentMap<DataListener, TargetDataListener>>();
-
- private volatile boolean closed = false;
-
- private final Set<String> persistentExistNodePath = new ConcurrentHashSet<>();
-
- public AbstractZookeeperClient(URL url) {
- this.url = url;
- }
-
- @Override
- public URL getUrl() {
- return url;
- }
-
- @Override
- public void delete(String path){
- //never mind if ephemeral
- persistentExistNodePath.remove(path);
- deletePath(path);
- }
-
-
- @Override
- public void create(String path, boolean ephemeral) {
- if (!ephemeral) {
- if(persistentExistNodePath.contains(path)){
- return;
- }
- if (checkExists(path)) {
- persistentExistNodePath.add(path);
- return;
- }
- }
- int i = path.lastIndexOf('/');
- if (i > 0) {
- create(path.substring(0, i), false);
- }
- if (ephemeral) {
- createEphemeral(path);
- } else {
- createPersistent(path);
- persistentExistNodePath.add(path);
- }
- }
-
- @Override
- public void addStateListener(StateListener listener) {
- stateListeners.add(listener);
- }
-
- @Override
- public void removeStateListener(StateListener listener) {
- stateListeners.remove(listener);
- }
-
- public Set<StateListener> getSessionListeners() {
- return stateListeners;
- }
-
- @Override
- public List<String> addChildListener(String path, final ChildListener listener) {
- ConcurrentMap<ChildListener, TargetChildListener> listeners = childListeners.computeIfAbsent(path, k -> new ConcurrentHashMap<>());
- TargetChildListener targetListener = listeners.computeIfAbsent(listener, k -> createTargetChildListener(path, k));
- return addTargetChildListener(path, targetListener);
- }
-
- @Override
- public void addDataListener(String path, DataListener listener) {
- this.addDataListener(path, listener, null);
- }
-
- @Override
- public void addDataListener(String path, DataListener listener, Executor executor) {
- ConcurrentMap<DataListener, TargetDataListener> dataListenerMap = listeners.computeIfAbsent(path, k -> new ConcurrentHashMap<>());
- TargetDataListener targetListener = dataListenerMap.computeIfAbsent(listener, k -> createTargetDataListener(path, k));
- addTargetDataListener(path, targetListener, executor);
- }
-
- @Override
- public void removeDataListener(String path, DataListener listener ){
- ConcurrentMap<DataListener, TargetDataListener> dataListenerMap = listeners.get(path);
- if (dataListenerMap != null) {
- TargetDataListener targetListener = dataListenerMap.remove(listener);
- if(targetListener != null){
- removeTargetDataListener(path, targetListener);
- }
- }
- }
-
- @Override
- public void removeChildListener(String path, ChildListener listener) {
- ConcurrentMap<ChildListener, TargetChildListener> listeners = childListeners.get(path);
- if (listeners != null) {
- TargetChildListener targetListener = listeners.remove(listener);
- if (targetListener != null) {
- removeTargetChildListener(path, targetListener);
- }
- }
- }
-
- protected void stateChanged(int state) {
- for (StateListener sessionListener : getSessionListeners()) {
- sessionListener.stateChanged(state);
- }
- }
-
- @Override
- public void close() {
- if (closed) {
- return;
- }
- closed = true;
- try {
- doClose();
- } catch (Throwable t) {
- logger.warn(t.getMessage(), t);
- }
- }
-
- @Override
- public void create(String path, String content, boolean ephemeral) {
- if (checkExists(path)) {
- delete(path);
- }
- int i = path.lastIndexOf('/');
- if (i > 0) {
- create(path.substring(0, i), false);
- }
- if (ephemeral) {
- createEphemeral(path, content);
- } else {
- createPersistent(path, content);
- }
- }
-
- @Override
- public String getContent(String path) {
- if (!checkExists(path)) {
- return null;
- }
- return doGetContent(path);
- }
-
- protected abstract void doClose();
-
- protected abstract void createPersistent(String path);
-
- protected abstract void createEphemeral(String path);
-
- protected abstract void createPersistent(String path, String data);
-
- protected abstract void createEphemeral(String path, String data);
-
- protected abstract boolean checkExists(String path);
-
- protected abstract TargetChildListener createTargetChildListener(String path, ChildListener listener);
-
- protected abstract List<String> addTargetChildListener(String path, TargetChildListener listener);
-
- protected abstract TargetDataListener createTargetDataListener(String path, DataListener listener);
-
- protected abstract void addTargetDataListener(String path, TargetDataListener listener);
-
- protected abstract void addTargetDataListener(String path, TargetDataListener listener, Executor executor);
-
- protected abstract void removeTargetDataListener(String path, TargetDataListener listener);
-
- protected abstract void removeTargetChildListener(String path, TargetChildListener listener);
-
- protected abstract String doGetContent(String path);
-
- /**
- * we invoke the zookeeper client to delete the node
- * @param path the node path
- */
- protected abstract void deletePath(String path);
-
-}
diff --git a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporter.java b/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporter.java
deleted file mode 100644
index b861c15..0000000
--- a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporter.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.remoting.zookeeper.support;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.constants.RemotingConstants;
-import org.apache.dubbo.common.logger.Logger;
-import org.apache.dubbo.common.logger.LoggerFactory;
-import org.apache.dubbo.common.utils.StringUtils;
-import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
-import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
-
-/**
- * AbstractZookeeperTransporter is abstract implements of ZookeeperTransporter.
- * <p>
- * If you want to extends this, implements createZookeeperClient.
- */
-public abstract class AbstractZookeeperTransporter implements ZookeeperTransporter {
- private static final Logger logger = LoggerFactory.getLogger(ZookeeperTransporter.class);
- private final Map<String, ZookeeperClient> zookeeperClientMap = new ConcurrentHashMap<>();
-
- /**
- * share connnect for registry, metadata, etc..
- * <p>
- * Make sure the connection is connected.
- *
- * @param url
- * @return
- */
- @Override
- public ZookeeperClient connect(URL url) {
- ZookeeperClient zookeeperClient;
- // address format: {[username:password@]address}
- List<String> addressList = getURLBackupAddress(url);
- // The field define the zookeeper server , including protocol, host, port, username, password
- if ((zookeeperClient = fetchAndUpdateZookeeperClientCache(addressList)) != null && zookeeperClient.isConnected()) {
- logger.info("find valid zookeeper client from the cache for address: " + url);
- return zookeeperClient;
- }
- // avoid creating too many connections, so add lock
- synchronized (zookeeperClientMap) {
- if ((zookeeperClient = fetchAndUpdateZookeeperClientCache(addressList)) != null && zookeeperClient.isConnected()) {
- logger.info("find valid zookeeper client from the cache for address: " + url);
- return zookeeperClient;
- }
-
- zookeeperClient = createZookeeperClient(url);
- logger.info("No valid zookeeper client found from cache, therefore create a new client for url. " + url);
- writeToClientMap(addressList, zookeeperClient);
- }
- return zookeeperClient;
- }
-
- /**
- * @param url the url that will create zookeeper connection .
- * The url in AbstractZookeeperTransporter#connect parameter is rewritten by this one.
- * such as: zookeeper://127.0.0.1:2181/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter
- * @return
- */
- protected abstract ZookeeperClient createZookeeperClient(URL url);
-
- /**
- * get the ZookeeperClient from cache, the ZookeeperClient must be connected.
- * <p>
- * It is not private method for unit test.
- *
- * @param addressList
- * @return
- */
- ZookeeperClient fetchAndUpdateZookeeperClientCache(List<String> addressList) {
-
- ZookeeperClient zookeeperClient = null;
- for (String address : addressList) {
- if ((zookeeperClient = zookeeperClientMap.get(address)) != null && zookeeperClient.isConnected()) {
- break;
- }
- }
- if (zookeeperClient != null && zookeeperClient.isConnected()) {
- writeToClientMap(addressList, zookeeperClient);
- }
- return zookeeperClient;
- }
-
- /**
- * get all zookeeper urls (such as :zookeeper://127.0.0.1:2181?127.0.0.1:8989,127.0.0.1:9999)
- *
- * @param url such as:zookeeper://127.0.0.1:2181?127.0.0.1:8989,127.0.0.1:9999
- * @return such as 127.0.0.1:2181,127.0.0.1:8989,127.0.0.1:9999
- */
- List<String> getURLBackupAddress(URL url) {
- List<String> addressList = new ArrayList<String>();
- addressList.add(url.getAddress());
- addressList.addAll(url.getParameter(RemotingConstants.BACKUP_KEY, Collections.EMPTY_LIST));
-
- String authPrefix = null;
- if (StringUtils.isNotEmpty(url.getUsername())) {
- StringBuilder buf = new StringBuilder();
- buf.append(url.getUsername());
- if (StringUtils.isNotEmpty(url.getPassword())) {
- buf.append(":");
- buf.append(url.getPassword());
- }
- buf.append("@");
- authPrefix = buf.toString();
- }
-
- if (StringUtils.isNotEmpty(authPrefix)) {
- List<String> authedAddressList = new ArrayList<>(addressList.size());
- for (String addr : addressList) {
- authedAddressList.add(authPrefix + addr);
- }
- return authedAddressList;
- }
-
-
- return addressList;
- }
-
- /**
- * write address-ZookeeperClient relationship to Map
- *
- * @param addressList
- * @param zookeeperClient
- */
- void writeToClientMap(List<String> addressList, ZookeeperClient zookeeperClient) {
- for (String address : addressList) {
- zookeeperClientMap.put(address, zookeeperClient);
- }
- }
-
- /**
- * redefine the url for zookeeper. just keep protocol, username, password, host, port, and individual parameter.
- *
- * @param url
- * @return
- */
- URL toClientURL(URL url) {
- Map<String, String> parameterMap = new HashMap<>();
- // for CuratorZookeeperClient
- if (url.getParameter(TIMEOUT_KEY) != null) {
- parameterMap.put(TIMEOUT_KEY, url.getParameter(TIMEOUT_KEY));
- }
- if (url.getParameter(RemotingConstants.BACKUP_KEY) != null) {
- parameterMap.put(RemotingConstants.BACKUP_KEY, url.getParameter(RemotingConstants.BACKUP_KEY));
- }
-
- return new URL(url.getProtocol(), url.getUsername(), url.getPassword(), url.getHost(), url.getPort(),
- ZookeeperTransporter.class.getName(), parameterMap);
- }
-
- /**
- * for unit test
- *
- * @return
- */
- Map<String, ZookeeperClient> getZookeeperClientMap() {
- return zookeeperClientMap;
- }
-}
diff --git a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter b/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter
deleted file mode 100644
index 44f9374..0000000
--- a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter
+++ /dev/null
@@ -1 +0,0 @@
-curator=org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperTransporter
diff --git a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClientTest.java b/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClientTest.java
deleted file mode 100644
index 2f2b2f5..0000000
--- a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClientTest.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.remoting.zookeeper.curator;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.utils.NetUtils;
-import org.apache.dubbo.remoting.zookeeper.ChildListener;
-
-import org.apache.curator.framework.CuratorFramework;
-import org.apache.curator.framework.CuratorFrameworkFactory;
-import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
-import org.apache.curator.retry.ExponentialBackoffRetry;
-import org.apache.curator.test.TestingServer;
-import org.apache.zookeeper.WatchedEvent;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.mockito.Mockito.mock;
-
-public class CuratorZookeeperClientTest {
- private TestingServer zkServer;
- private CuratorZookeeperClient curatorClient;
- CuratorFramework client = null;
-
- @BeforeEach
- public void setUp() throws Exception {
- int zkServerPort = NetUtils.getAvailablePort();
- zkServer = new TestingServer(zkServerPort, true);
- curatorClient = new CuratorZookeeperClient(URL.valueOf("zookeeper://127.0.0.1:" +
- zkServerPort + "/org.apache.dubbo.registry.RegistryService"));
- client = CuratorFrameworkFactory.newClient(zkServer.getConnectString(), new ExponentialBackoffRetry(1000, 3));
- client.start();
- }
-
- @Test
- public void testCheckExists() {
- String path = "/dubbo/org.apache.dubbo.demo.DemoService/providers";
- curatorClient.create(path, false);
- assertThat(curatorClient.checkExists(path), is(true));
- assertThat(curatorClient.checkExists(path + "/noneexits"), is(false));
- }
-
- @Test
- public void testChildrenPath() {
- String path = "/dubbo/org.apache.dubbo.demo.DemoService/providers";
- curatorClient.create(path, false);
- curatorClient.create(path + "/provider1", false);
- curatorClient.create(path + "/provider2", false);
-
- List<String> children = curatorClient.getChildren(path);
- assertThat(children.size(), is(2));
- }
-
- @Test
- public void testChildrenListener() throws InterruptedException {
- String path = "/dubbo/org.apache.dubbo.demo.DemoService/providers";
- curatorClient.create(path, false);
- final CountDownLatch countDownLatch = new CountDownLatch(1);
- curatorClient.addTargetChildListener(path, new CuratorZookeeperClient.CuratorWatcherImpl() {
-
- @Override
- public void process(WatchedEvent watchedEvent) throws Exception {
- countDownLatch.countDown();
- }
- });
- curatorClient.createPersistent(path + "/provider1");
- countDownLatch.await();
- }
-
-
- @Test
- public void testWithInvalidServer() {
- Assertions.assertThrows(IllegalStateException.class, () -> {
- curatorClient = new CuratorZookeeperClient(URL.valueOf("zookeeper://127.0.0.1:1/service"));
- curatorClient.create("/testPath", true);
- });
- }
-
- @Test
- public void testWithStoppedServer() throws IOException {
- Assertions.assertThrows(IllegalStateException.class, () -> {
- curatorClient.create("/testPath", true);
- zkServer.stop();
- curatorClient.delete("/testPath");
- });
- }
-
- @Test
- public void testRemoveChildrenListener() {
- ChildListener childListener = mock(ChildListener.class);
- curatorClient.addChildListener("/children", childListener);
- curatorClient.removeChildListener("/children", childListener);
- }
-
- @Test
- public void testCreateExistingPath() {
- curatorClient.create("/pathOne", false);
- curatorClient.create("/pathOne", false);
- }
-
- @Test
- public void testConnectedStatus() {
- curatorClient.createEphemeral("/testPath");
- boolean connected = curatorClient.isConnected();
- assertThat(connected, is(true));
- }
-
- @Test
- public void testCreateContent4Persistent() {
- String path = "/curatorTest4CrContent/content.data";
- String content = "createContentTest";
- curatorClient.delete(path);
- assertThat(curatorClient.checkExists(path), is(false));
- assertNull(curatorClient.getContent(path));
-
- curatorClient.create(path, content, false);
- assertThat(curatorClient.checkExists(path), is(true));
- assertEquals(curatorClient.getContent(path), content);
- }
-
- @Test
- public void testCreateContent4Temp() {
- String path = "/curatorTest4CrContent/content.data";
- String content = "createContentTest";
- curatorClient.delete(path);
- assertThat(curatorClient.checkExists(path), is(false));
- assertNull(curatorClient.getContent(path));
-
- curatorClient.create(path, content, true);
- assertThat(curatorClient.checkExists(path), is(true));
- assertEquals(curatorClient.getContent(path), content);
- }
-
- @AfterEach
- public void tearDown() throws Exception {
- curatorClient.close();
- zkServer.stop();
- }
-
- @Test
- public void testAddTargetDataListener() throws Exception {
- String listenerPath = "/dubbo/service.name/configuration";
- String path = listenerPath + "/dat/data";
- String value = "vav";
-
- curatorClient.create(path + "/d.json", value, true);
- String valueFromCache = curatorClient.getContent(path + "/d.json");
- Assertions.assertEquals(value, valueFromCache);
- final AtomicInteger atomicInteger = new AtomicInteger(0);
- curatorClient.addTargetDataListener(listenerPath, new CuratorZookeeperClient.CuratorWatcherImpl() {
- @Override
- public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception {
- System.out.println("===" + event);
- atomicInteger.incrementAndGet();
- }
- });
-
- valueFromCache = curatorClient.getContent(path + "/d.json");
- Assertions.assertNotNull(valueFromCache);
- curatorClient.getClient().setData().forPath(path + "/d.json", "sdsdf".getBytes());
- curatorClient.getClient().setData().forPath(path + "/d.json", "dfsasf".getBytes());
- curatorClient.delete(path + "/d.json");
- curatorClient.delete(path);
- valueFromCache = curatorClient.getContent(path + "/d.json");
- Assertions.assertNull(valueFromCache);
- Thread.sleep(2000L);
- Assertions.assertTrue(9L >= atomicInteger.get());
- Assertions.assertTrue(2L <= atomicInteger.get());
- }
-}
diff --git a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperTransporterTest.java b/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperTransporterTest.java
deleted file mode 100644
index e051dc9..0000000
--- a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperTransporterTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.remoting.zookeeper.curator;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.utils.NetUtils;
-import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
-
-import org.apache.curator.test.TestingServer;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.IsNot.not;
-import static org.hamcrest.core.IsNull.nullValue;
-
-public class CuratorZookeeperTransporterTest {
- private TestingServer zkServer;
- private ZookeeperClient zookeeperClient;
- private CuratorZookeeperTransporter curatorZookeeperTransporter;
- private int zkServerPort;
-
- @BeforeEach
- public void setUp() throws Exception {
- zkServerPort = NetUtils.getAvailablePort();
- zkServer = new TestingServer(zkServerPort, true);
- zookeeperClient = new CuratorZookeeperTransporter().connect(URL.valueOf("zookeeper://127.0.0.1:" +
- zkServerPort + "/service"));
- curatorZookeeperTransporter = new CuratorZookeeperTransporter();
- }
-
- @Test
- public void testZookeeperClient() {
- assertThat(zookeeperClient, not(nullValue()));
- zookeeperClient.close();
- }
-
- @AfterEach
- public void tearDown() throws Exception {
- zkServer.stop();
- }
-}
diff --git a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporterTest.java b/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporterTest.java
deleted file mode 100644
index 3662d8f..0000000
--- a/dubbo-spi-remoting/dubbo-remoting-zookeeper/src/test/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperTransporterTest.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.remoting.zookeeper.support;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.utils.NetUtils;
-import org.apache.dubbo.remoting.zookeeper.ZookeeperClient;
-import org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperTransporter;
-
-import org.apache.curator.test.TestingServer;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import java.util.List;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.IsNot.not;
-import static org.hamcrest.core.IsNull.nullValue;
-
-/**
- * AbstractZookeeperTransporterTest
- */
-public class AbstractZookeeperTransporterTest {
- private TestingServer zkServer;
- private ZookeeperClient zookeeperClient;
- private AbstractZookeeperTransporter abstractZookeeperTransporter;
- private int zkServerPort;
-
- @BeforeEach
- public void setUp() throws Exception {
- zkServerPort = NetUtils.getAvailablePort();
- zkServer = new TestingServer(zkServerPort, true);
- zookeeperClient = new CuratorZookeeperTransporter().connect(URL.valueOf("zookeeper://127.0.0.1:" +
- zkServerPort + "/service"));
- abstractZookeeperTransporter = new CuratorZookeeperTransporter();
- }
-
-
- @AfterEach
- public void tearDown() throws Exception {
- zkServer.stop();
- }
-
- @Test
- public void testZookeeperClient() {
- assertThat(zookeeperClient, not(nullValue()));
- zookeeperClient.close();
- }
-
- @Test
- public void testGetURLBackupAddress() {
- URL url = URL.valueOf("zookeeper://127.0.0.1:" + zkServerPort + "/org.apache.dubbo.registry.RegistryService?backup=127.0.0.1:" + 9099 + "&application=metadatareport-local-xml-provider2&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=47418&specVersion=2.7.0-SNAPSHOT×tamp=1547102428828");
- List<String> stringList = abstractZookeeperTransporter.getURLBackupAddress(url);
- Assertions.assertEquals(stringList.size(), 2);
- Assertions.assertEquals(stringList.get(0), "127.0.0.1:" + zkServerPort);
- Assertions.assertEquals(stringList.get(1), "127.0.0.1:9099");
- }
-
- @Test
- public void testGetURLBackupAddressNoBack() {
- URL url = URL.valueOf("zookeeper://127.0.0.1:" + zkServerPort + "/org.apache.dubbo.registry.RegistryService?application=metadatareport-local-xml-provider2&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=47418&specVersion=2.7.0-SNAPSHOT×tamp=1547102428828");
- List<String> stringList = abstractZookeeperTransporter.getURLBackupAddress(url);
- Assertions.assertEquals(stringList.size(), 1);
- Assertions.assertEquals(stringList.get(0), "127.0.0.1:" + zkServerPort);
- }
-
- @Test
- public void testFetchAndUpdateZookeeperClientCache() throws Exception {
- int zkServerPort2 = NetUtils.getAvailablePort();
- TestingServer zkServer2 = new TestingServer(zkServerPort2, true);
-
- int zkServerPort3 = NetUtils.getAvailablePort();
- TestingServer zkServer3 = new TestingServer(zkServerPort3, true);
-
- URL url = URL.valueOf("zookeeper://127.0.0.1:" + zkServerPort + "/org.apache.dubbo.registry.RegistryService?backup=127.0.0.1:" + zkServerPort3 + ",127.0.0.1:" + zkServerPort2 + "&application=metadatareport-local-xml-provider2&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=47418&specVersion=2.7.0-SNAPSHOT×tamp=1547102428828");
- ZookeeperClient newZookeeperClient = abstractZookeeperTransporter.connect(url);
- //just for connected
- newZookeeperClient.getContent("/dubbo/test");
- Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().size(), 3);
- Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zkServerPort), newZookeeperClient);
-
- URL url2 = URL.valueOf("zookeeper://127.0.0.1:" + zkServerPort + "/org.apache.dubbo.metadata.store.MetadataReport?address=zookeeper://127.0.0.1:2181&application=metadatareport-local-xml-provider2&cycle-report=false&interface=org.apache.dubbo.metadata.store.MetadataReport&retry-period=4590&retry-times=23&sync-report=true");
- checkFetchAndUpdateCacheNotNull(url2);
- URL url3 = URL.valueOf("zookeeper://127.0.0.1:8778/org.apache.dubbo.metadata.store.MetadataReport?backup=127.0.0.1:" + zkServerPort3 + "&address=zookeeper://127.0.0.1:2181&application=metadatareport-local-xml-provider2&cycle-report=false&interface=org.apache.dubbo.metadata.store.MetadataReport&retry-period=4590&retry-times=23&sync-report=true");
- checkFetchAndUpdateCacheNotNull(url3);
-
- zkServer2.stop();
- zkServer3.stop();
- }
-
- private void checkFetchAndUpdateCacheNotNull(URL url) {
- List<String> addressList = abstractZookeeperTransporter.getURLBackupAddress(url);
- ZookeeperClient zookeeperClient = abstractZookeeperTransporter.fetchAndUpdateZookeeperClientCache(addressList);
- Assertions.assertNotNull(zookeeperClient);
- }
-
- @Test
- public void testRepeatConnect() {
- URL url = URL.valueOf("zookeeper://127.0.0.1:" + zkServerPort + "/org.apache.dubbo.registry.RegistryService?application=metadatareport-local-xml-provider2&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=47418&specVersion=2.7.0-SNAPSHOT×tamp=1547102428828");
- URL url2 = URL.valueOf("zookeeper://127.0.0.1:" + zkServerPort + "/org.apache.dubbo.metadata.store.MetadataReport?address=zookeeper://127.0.0.1:2181&application=metadatareport-local-xml-provider2&cycle-report=false&interface=org.apache.dubbo.metadata.store.MetadataReport&retry-period=4590&retry-times=23&sync-report=true");
- ZookeeperClient newZookeeperClient = abstractZookeeperTransporter.connect(url);
- //just for connected
- newZookeeperClient.getContent("/dubbo/test");
- Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().size(), 1);
- Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zkServerPort), newZookeeperClient);
- Assertions.assertTrue(newZookeeperClient.isConnected());
-
- ZookeeperClient newZookeeperClient2 = abstractZookeeperTransporter.connect(url2);
- //just for connected
- newZookeeperClient2.getContent("/dubbo/test");
- Assertions.assertEquals(newZookeeperClient, newZookeeperClient2);
- Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().size(), 1);
- Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zkServerPort), newZookeeperClient);
- }
-
- @Test
- public void testNotRepeatConnect() throws Exception {
- int zkServerPort2 = NetUtils.getAvailablePort();
- TestingServer zkServer2 = new TestingServer(zkServerPort2, true);
-
- URL url = URL.valueOf("zookeeper://127.0.0.1:" + zkServerPort + "/org.apache.dubbo.registry.RegistryService?application=metadatareport-local-xml-provider2&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=47418&specVersion=2.7.0-SNAPSHOT×tamp=1547102428828");
- URL url2 = URL.valueOf("zookeeper://127.0.0.1:" + zkServerPort2 + "/org.apache.dubbo.metadata.store.MetadataReport?address=zookeeper://127.0.0.1:2181&application=metadatareport-local-xml-provider2&cycle-report=false&interface=org.apache.dubbo.metadata.store.MetadataReport&retry-period=4590&retry-times=23&sync-report=true");
- ZookeeperClient newZookeeperClient = abstractZookeeperTransporter.connect(url);
- //just for connected
- newZookeeperClient.getContent("/dubbo/test");
- Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().size(), 1);
- Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zkServerPort), newZookeeperClient);
-
- ZookeeperClient newZookeeperClient2 = abstractZookeeperTransporter.connect(url2);
- //just for connected
- newZookeeperClient2.getContent("/dubbo/test");
- Assertions.assertNotEquals(newZookeeperClient, newZookeeperClient2);
- Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().size(), 2);
- Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zkServerPort2), newZookeeperClient2);
-
- zkServer2.stop();
- }
-
- @Test
- public void testRepeatConnectForBackUpAdd() throws Exception {
- int zkServerPort2 = NetUtils.getAvailablePort();
- TestingServer zkServer2 = new TestingServer(zkServerPort2, true);
-
- int zkServerPort3 = NetUtils.getAvailablePort();
- TestingServer zkServer3 = new TestingServer(zkServerPort3, true);
-
- URL url = URL.valueOf("zookeeper://127.0.0.1:" + zkServerPort + "/org.apache.dubbo.registry.RegistryService?backup=127.0.0.1:" + zkServerPort2 + "&application=metadatareport-local-xml-provider2&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=47418&specVersion=2.7.0-SNAPSHOT×tamp=1547102428828");
- URL url2 = URL.valueOf("zookeeper://127.0.0.1:" + zkServerPort2 + "/org.apache.dubbo.metadata.store.MetadataReport?backup=127.0.0.1:" + zkServerPort3 + "&address=zookeeper://127.0.0.1:2181&application=metadatareport-local-xml-provider2&cycle-report=false&interface=org.apache.dubbo.metadata.store.MetadataReport&retry-period=4590&retry-times=23&sync-report=true");
- ZookeeperClient newZookeeperClient = abstractZookeeperTransporter.connect(url);
- //just for connected
- newZookeeperClient.getContent("/dubbo/test");
- Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().size(), 2);
- Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zkServerPort), newZookeeperClient);
-
- ZookeeperClient newZookeeperClient2 = abstractZookeeperTransporter.connect(url2);
- //just for connected
- newZookeeperClient2.getContent("/dubbo/test");
- Assertions.assertEquals(newZookeeperClient, newZookeeperClient2);
- Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().size(), 3);
- Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zkServerPort2), newZookeeperClient2);
-
- zkServer2.stop();
- zkServer3.stop();
- }
-
- @Test
- public void testRepeatConnectForNoMatchBackUpAdd() throws Exception {
- int zkServerPort2 = NetUtils.getAvailablePort();
- TestingServer zkServer2 = new TestingServer(zkServerPort2, true);
-
- int zkServerPort3 = NetUtils.getAvailablePort();
- TestingServer zkServer3 = new TestingServer(zkServerPort3, true);
-
- URL url = URL.valueOf("zookeeper://127.0.0.1:" + zkServerPort + "/org.apache.dubbo.registry.RegistryService?backup=127.0.0.1:" + zkServerPort3 + "&application=metadatareport-local-xml-provider2&dubbo=2.0.2&interface=org.apache.dubbo.registry.RegistryService&pid=47418&specVersion=2.7.0-SNAPSHOT×tamp=1547102428828");
- URL url2 = URL.valueOf("zookeeper://127.0.0.1:" + zkServerPort2 + "/org.apache.dubbo.metadata.store.MetadataReport?address=zookeeper://127.0.0.1:2181&application=metadatareport-local-xml-provider2&cycle-report=false&interface=org.apache.dubbo.metadata.store.MetadataReport&retry-period=4590&retry-times=23&sync-report=true");
- ZookeeperClient newZookeeperClient = abstractZookeeperTransporter.connect(url);
- //just for connected
- newZookeeperClient.getContent("/dubbo/test");
- Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().size(), 2);
- Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zkServerPort), newZookeeperClient);
-
- ZookeeperClient newZookeeperClient2 = abstractZookeeperTransporter.connect(url2);
- //just for connected
- newZookeeperClient2.getContent("/dubbo/test");
- Assertions.assertNotEquals(newZookeeperClient, newZookeeperClient2);
- Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().size(), 3);
- Assertions.assertEquals(abstractZookeeperTransporter.getZookeeperClientMap().get("127.0.0.1:" + zkServerPort2), newZookeeperClient2);
-
- zkServer2.stop();
- zkServer3.stop();
- }
-
- @Test
- public void testSameHostWithDifferentUser() throws Exception {
- int zkPort1 = NetUtils.getAvailablePort();
- int zkPort2 = NetUtils.getAvailablePort();
- try (TestingServer zkServer1 = new TestingServer(zkPort1, true)) {
- try (TestingServer zkServer2 = new TestingServer(zkPort2, true)) {
- URL url1 = URL.valueOf("zookeeper://us1:pw1@127.0.0.1:" + zkPort1 + "/path1");
- URL url2 = URL.valueOf("zookeeper://us2:pw2@127.0.0.1:" + zkPort1 + "/path2");
-
- ZookeeperClient client1 = abstractZookeeperTransporter.connect(url1);
- ZookeeperClient client2 = abstractZookeeperTransporter.connect(url2);
-
- assertThat(client1, not(client2));
- }
- }
- }
-}
diff --git a/dubbo-spi-remoting/pom.xml b/dubbo-spi-remoting/pom.xml
index fe73221..152782f 100644
--- a/dubbo-spi-remoting/pom.xml
+++ b/dubbo-spi-remoting/pom.xml
@@ -34,7 +34,6 @@
<module>dubbo-remoting-grizzly</module>
<module>dubbo-remoting-p2p</module>
<module>dubbo-remoting-http</module>
- <module>dubbo-remoting-zookeeper</module>
<module>dubbo-remoting-etcd3</module>
</modules>
</project>
\ No newline at end of file
diff --git a/dubbo-spi-serialization/dubbo-serialization-jdk/pom.xml b/dubbo-spi-serialization/dubbo-serialization-jdk/pom.xml
deleted file mode 100644
index 0b70869..0000000
--- a/dubbo-spi-serialization/dubbo-serialization-jdk/pom.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<!--
-Licensed to the Apache Software Foundation (ASF) under one or more
-contributor license agreements. See the NOTICE file distributed with
-this work for additional information regarding copyright ownership.
-The ASF licenses this file to You under the Apache License, Version 2.0
-(the "License"); you may not use this file except in compliance with
-the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
--->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-serialization</artifactId>
- <version>2.7.7-SNAPSHOT</version>
- </parent>
- <artifactId>dubbo-serialization-jdk</artifactId>
- <packaging>jar</packaging>
- <name>${project.artifactId}</name>
- <description>The jdk serialization module of dubbo project</description>
- <properties>
- <skip_maven_deploy>false</skip_maven_deploy>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-serialization-api</artifactId>
- <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>hessian-lite</artifactId>
- </dependency>
- </dependencies>
-</project>
\ No newline at end of file
diff --git a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedJavaSerialization.java b/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedJavaSerialization.java
deleted file mode 100644
index 2df9db1..0000000
--- a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedJavaSerialization.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.serialize.java;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.serialize.ObjectInput;
-import org.apache.dubbo.common.serialize.ObjectOutput;
-import org.apache.dubbo.common.serialize.Serialization;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import static org.apache.dubbo.common.serialize.Constants.COMPACTED_JAVA_SERIALIZATION_ID;
-
-/**
- * Compacted java serialization implementation
- *
- * <pre>
- * e.g. <dubbo:protocol serialization="compactedjava" />
- * </pre>
- */
-public class CompactedJavaSerialization implements Serialization {
-
- @Override
- public byte getContentTypeId() {
- return COMPACTED_JAVA_SERIALIZATION_ID;
- }
-
- @Override
- public String getContentType() {
- return "x-application/compactedjava";
- }
-
- @Override
- public ObjectOutput serialize(URL url, OutputStream out) throws IOException {
- return new JavaObjectOutput(out, true);
- }
-
- @Override
- public ObjectInput deserialize(URL url, InputStream is) throws IOException {
- return new JavaObjectInput(is, true);
- }
-
-}
diff --git a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedObjectInputStream.java b/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedObjectInputStream.java
deleted file mode 100644
index e881774..0000000
--- a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedObjectInputStream.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.serialize.java;
-
-
-import org.apache.dubbo.common.utils.ClassUtils;
-
-import java.io.EOFException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectStreamClass;
-import java.io.StreamCorruptedException;
-
-/**
- * Compacted java object input implementation
- */
-public class CompactedObjectInputStream extends ObjectInputStream {
- private ClassLoader mClassLoader;
-
- public CompactedObjectInputStream(InputStream in) throws IOException {
- this(in, Thread.currentThread().getContextClassLoader());
- }
-
- public CompactedObjectInputStream(InputStream in, ClassLoader cl) throws IOException {
- super(in);
- mClassLoader = cl == null ? ClassUtils.getClassLoader() : cl;
- }
-
- @Override
- protected ObjectStreamClass readClassDescriptor() throws IOException, ClassNotFoundException {
- int type = read();
- if (type < 0) {
- throw new EOFException();
- }
- switch (type) {
- case 0:
- return super.readClassDescriptor();
- case 1:
- Class<?> clazz = loadClass(readUTF());
- return ObjectStreamClass.lookup(clazz);
- default:
- throw new StreamCorruptedException("Unexpected class descriptor type: " + type);
- }
- }
-
- private Class<?> loadClass(String className) throws ClassNotFoundException {
- return mClassLoader.loadClass(className);
- }
-}
\ No newline at end of file
diff --git a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedObjectOutputStream.java b/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedObjectOutputStream.java
deleted file mode 100644
index 56847e5..0000000
--- a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedObjectOutputStream.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.serialize.java;
-
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.io.ObjectStreamClass;
-import java.io.OutputStream;
-
-/**
- * Compacted java object output implementation
- */
-public class CompactedObjectOutputStream extends ObjectOutputStream {
- public CompactedObjectOutputStream(OutputStream out) throws IOException {
- super(out);
- }
-
- @Override
- protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException {
- Class<?> clazz = desc.forClass();
- if (clazz.isPrimitive() || clazz.isArray()) {
- write(0);
- super.writeClassDescriptor(desc);
- } else {
- write(1);
- writeUTF(desc.getName());
- }
- }
-}
\ No newline at end of file
diff --git a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaObjectInput.java b/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaObjectInput.java
deleted file mode 100644
index 936ab26..0000000
--- a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaObjectInput.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.serialize.java;
-
-import org.apache.dubbo.common.serialize.nativejava.NativeJavaObjectInput;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.lang.reflect.Type;
-
-/**
- * Java object input implementation
- */
-public class JavaObjectInput extends NativeJavaObjectInput {
- public final static int MAX_BYTE_ARRAY_LENGTH = 8 * 1024 * 1024;
-
- public JavaObjectInput(InputStream is) throws IOException {
- super(new ObjectInputStream(is));
- }
-
- public JavaObjectInput(InputStream is, boolean compacted) throws IOException {
- super(compacted ? new CompactedObjectInputStream(is) : new ObjectInputStream(is));
- }
-
- @Override
- public byte[] readBytes() throws IOException {
- int len = getObjectInputStream().readInt();
- if (len < 0) {
- return null;
- }
- if (len == 0) {
- return new byte[0];
- }
- if (len > MAX_BYTE_ARRAY_LENGTH) {
- throw new IOException("Byte array length too large. " + len);
- }
-
- byte[] b = new byte[len];
- getObjectInputStream().readFully(b);
- return b;
- }
-
- @Override
- public String readUTF() throws IOException {
- int len = getObjectInputStream().readInt();
- if (len < 0) {
- return null;
- }
-
- return getObjectInputStream().readUTF();
- }
-
- @Override
- public Object readObject() throws IOException, ClassNotFoundException {
- byte b = getObjectInputStream().readByte();
- if (b == 0) {
- return null;
- }
-
- return getObjectInputStream().readObject();
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public <T> T readObject(Class<T> cls) throws IOException,
- ClassNotFoundException {
- return (T) readObject();
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public <T> T readObject(Class<T> cls, Type type) throws IOException, ClassNotFoundException {
- return (T) readObject();
- }
-
-}
diff --git a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaObjectOutput.java b/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaObjectOutput.java
deleted file mode 100644
index 0e78747..0000000
--- a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaObjectOutput.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.serialize.java;
-
-import org.apache.dubbo.common.serialize.nativejava.NativeJavaObjectOutput;
-
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-
-/**
- * Java object output implementation
- */
-public class JavaObjectOutput extends NativeJavaObjectOutput {
- public JavaObjectOutput(OutputStream os) throws IOException {
- super(new ObjectOutputStream(os));
- }
-
- public JavaObjectOutput(OutputStream os, boolean compact) throws IOException {
- super(compact ? new CompactedObjectOutputStream(os) : new ObjectOutputStream(os));
- }
-
- @Override
- public void writeUTF(String v) throws IOException {
- if (v == null) {
- getObjectOutputStream().writeInt(-1);
- } else {
- getObjectOutputStream().writeInt(v.length());
- getObjectOutputStream().writeUTF(v);
- }
- }
-
- @Override
- public void writeObject(Object obj) throws IOException {
- if (obj == null) {
- getObjectOutputStream().writeByte(0);
- } else {
- getObjectOutputStream().writeByte(1);
- getObjectOutputStream().writeObject(obj);
- }
- }
-
- @Override
- public void flushBuffer() throws IOException {
- getObjectOutputStream().flush();
- }
-}
diff --git a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaSerialization.java b/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaSerialization.java
deleted file mode 100644
index 2045e4e..0000000
--- a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaSerialization.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.serialize.java;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.serialize.ObjectInput;
-import org.apache.dubbo.common.serialize.ObjectOutput;
-import org.apache.dubbo.common.serialize.Serialization;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import static org.apache.dubbo.common.serialize.Constants.JAVA_SERIALIZATION_ID;
-
-/**
- * Java serialization implementation
- *
- * <pre>
- * e.g. <dubbo:protocol serialization="java" />
- * </pre>
- */
-public class JavaSerialization implements Serialization {
-
- @Override
- public byte getContentTypeId() {
- return JAVA_SERIALIZATION_ID;
- }
-
- @Override
- public String getContentType() {
- return "x-application/java";
- }
-
- @Override
- public ObjectOutput serialize(URL url, OutputStream out) throws IOException {
- return new JavaObjectOutput(out);
- }
-
- @Override
- public ObjectInput deserialize(URL url, InputStream is) throws IOException {
- return new JavaObjectInput(is);
- }
-
-}
diff --git a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaObjectInput.java b/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaObjectInput.java
deleted file mode 100644
index c791250..0000000
--- a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaObjectInput.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.dubbo.common.serialize.nativejava;
-
-import org.apache.dubbo.common.serialize.ObjectInput;
-import org.apache.dubbo.common.utils.Assert;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.lang.reflect.Type;
-
-/**
- * Native java object input implementation
- */
-public class NativeJavaObjectInput implements ObjectInput {
-
- private final ObjectInputStream inputStream;
-
- public NativeJavaObjectInput(InputStream is) throws IOException {
- this(new ObjectInputStream(is));
- }
-
- protected NativeJavaObjectInput(ObjectInputStream is) {
- Assert.notNull(is, "input == null");
- inputStream = is;
- }
-
- protected ObjectInputStream getObjectInputStream() {
- return inputStream;
- }
-
- @Override
- public Object readObject() throws IOException, ClassNotFoundException {
- return inputStream.readObject();
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException {
- return (T) readObject();
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public <T> T readObject(Class<T> cls, Type type) throws IOException, ClassNotFoundException {
- return (T) readObject();
- }
-
- @Override
- public boolean readBool() throws IOException {
- return inputStream.readBoolean();
- }
-
- @Override
- public byte readByte() throws IOException {
- return inputStream.readByte();
- }
-
- @Override
- public short readShort() throws IOException {
- return inputStream.readShort();
- }
-
- @Override
- public int readInt() throws IOException {
- return inputStream.readInt();
- }
-
- @Override
- public long readLong() throws IOException {
- return inputStream.readLong();
- }
-
- @Override
- public float readFloat() throws IOException {
- return inputStream.readFloat();
- }
-
- @Override
- public double readDouble() throws IOException {
- return inputStream.readDouble();
- }
-
- @Override
- public String readUTF() throws IOException {
- return inputStream.readUTF();
- }
-
- @Override
- public byte[] readBytes() throws IOException {
- int len = inputStream.readInt();
- if (len < 0) {
- return null;
- } else if (len == 0) {
- return new byte[]{};
- } else {
- byte[] result = new byte[len];
- inputStream.readFully(result);
- return result;
- }
- }
-}
diff --git a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaObjectOutput.java b/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaObjectOutput.java
deleted file mode 100644
index 2ff82f7..0000000
--- a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaObjectOutput.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.dubbo.common.serialize.nativejava;
-
-import org.apache.dubbo.common.serialize.ObjectOutput;
-import org.apache.dubbo.common.utils.Assert;
-
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-
-/**
- * Native java object output implementation
- */
-public class NativeJavaObjectOutput implements ObjectOutput {
-
- private final ObjectOutputStream outputStream;
-
- public NativeJavaObjectOutput(OutputStream os) throws IOException {
- this(new ObjectOutputStream(os));
- }
-
- protected NativeJavaObjectOutput(ObjectOutputStream out) {
- Assert.notNull(out, "output == null");
- this.outputStream = out;
- }
-
- protected ObjectOutputStream getObjectOutputStream() {
- return outputStream;
- }
-
- @Override
- public void writeObject(Object obj) throws IOException {
- outputStream.writeObject(obj);
- }
-
- @Override
- public void writeBool(boolean v) throws IOException {
- outputStream.writeBoolean(v);
- }
-
- @Override
- public void writeByte(byte v) throws IOException {
- outputStream.writeByte(v);
- }
-
- @Override
- public void writeShort(short v) throws IOException {
- outputStream.writeShort(v);
- }
-
- @Override
- public void writeInt(int v) throws IOException {
- outputStream.writeInt(v);
- }
-
- @Override
- public void writeLong(long v) throws IOException {
- outputStream.writeLong(v);
- }
-
- @Override
- public void writeFloat(float v) throws IOException {
- outputStream.writeFloat(v);
- }
-
- @Override
- public void writeDouble(double v) throws IOException {
- outputStream.writeDouble(v);
- }
-
- @Override
- public void writeUTF(String v) throws IOException {
- outputStream.writeUTF(v);
- }
-
- @Override
- public void writeBytes(byte[] v) throws IOException {
- if (v == null) {
- outputStream.writeInt(-1);
- } else {
- writeBytes(v, 0, v.length);
- }
- }
-
- @Override
- public void writeBytes(byte[] v, int off, int len) throws IOException {
- if (v == null) {
- outputStream.writeInt(-1);
- } else {
- outputStream.writeInt(len);
- outputStream.write(v, off, len);
- }
- }
-
- @Override
- public void flushBuffer() throws IOException {
- outputStream.flush();
- }
-}
diff --git a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaSerialization.java b/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaSerialization.java
deleted file mode 100644
index 6617d29..0000000
--- a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaSerialization.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.dubbo.common.serialize.nativejava;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.serialize.ObjectInput;
-import org.apache.dubbo.common.serialize.ObjectOutput;
-import org.apache.dubbo.common.serialize.Serialization;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import static org.apache.dubbo.common.serialize.Constants.NATIVE_JAVA_SERIALIZATION_ID;
-
-/**
- * Native java serialization implementation
- *
- * <pre>
- * e.g. <dubbo:protocol serialization="nativejava" />
- * </pre>
- */
-public class NativeJavaSerialization implements Serialization {
-
-
- @Override
- public byte getContentTypeId() {
- return NATIVE_JAVA_SERIALIZATION_ID;
- }
-
- @Override
- public String getContentType() {
- return "x-application/nativejava";
- }
-
- @Override
- public ObjectOutput serialize(URL url, OutputStream output) throws IOException {
- return new NativeJavaObjectOutput(output);
- }
-
- @Override
- public ObjectInput deserialize(URL url, InputStream input) throws IOException {
- return new NativeJavaObjectInput(input);
- }
-}
diff --git a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization b/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization
deleted file mode 100644
index bc1e4ef..0000000
--- a/dubbo-spi-serialization/dubbo-serialization-jdk/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.common.serialize.Serialization
+++ /dev/null
@@ -1,3 +0,0 @@
-java=org.apache.dubbo.common.serialize.java.JavaSerialization
-compactedjava=org.apache.dubbo.common.serialize.java.CompactedJavaSerialization
-nativejava=org.apache.dubbo.common.serialize.nativejava.NativeJavaSerialization
\ No newline at end of file
diff --git a/dubbo-spi-serialization/pom.xml b/dubbo-spi-serialization/pom.xml
index a978639..3536885 100644
--- a/dubbo-spi-serialization/pom.xml
+++ b/dubbo-spi-serialization/pom.xml
@@ -32,7 +32,6 @@
<module>dubbo-serialization-fastjson</module>
<module>dubbo-serialization-kryo</module>
<module>dubbo-serialization-fst</module>
- <module>dubbo-serialization-jdk</module>
<module>dubbo-serialization-protostuff</module>
<module>dubbo-serialization-avro</module>
<module>dubbo-serialization-test</module>