@@ -64,7 +64,12 @@
org.apache.dubbo
- dubbo-metadata
+ dubbo-metadata-api
+ ${project.parent.version}
+
+
+ org.apache.dubbo
+ dubbo-metadata-report-api
${project.parent.version}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java
index bcdcfd29e66..cd501e6cee0 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceInstance.java
@@ -16,8 +16,19 @@
*/
package org.apache.dubbo.registry.client;
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.URLBuilder;
+import org.apache.dubbo.metadata.MetadataService;
+
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
+import static java.lang.String.valueOf;
+import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getMetadataServiceURLsParams;
+import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getProviderHost;
+import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getProviderPort;
+
/**
* The model class of an instance of a service, which is used for service registration and discovery.
*
@@ -91,4 +102,37 @@ default boolean isHealthy() {
* @return if equals , return true
, or false
*/
boolean equals(Object another);
+
+ /**
+ * Build the {@link URL urls} from {@link ServiceInstance#getMetadata() the metadata} of {@link ServiceInstance}
+ *
+ * @param serviceInstance {@link ServiceInstance}
+ * @return the not-null {@link List}
+ */
+ static List toUrls(ServiceInstance serviceInstance) {
+
+ Map> paramsMap = getMetadataServiceURLsParams(serviceInstance);
+
+ List urls = new ArrayList<>(paramsMap.size());
+
+ for (Map.Entry> entry : paramsMap.entrySet()) {
+
+ URLBuilder urlBuilder = new URLBuilder();
+ String protocol = entry.getKey();
+ Map urlParams = entry.getValue();
+ String host = getProviderHost(urlParams);
+ Integer port = getProviderPort(urlParams);
+ urlBuilder.setHost(host)
+ .setPort(port)
+ .setProtocol(protocol)
+ .setPath(MetadataService.class.getName());
+
+ // add parameters
+ entry.getValue().forEach((name, value) -> urlBuilder.addParameter(name, valueOf(value)));
+
+ urls.add(urlBuilder.build());
+ }
+
+ return urls;
+ }
}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ExportedServicesRevisionMetadataCustomizer.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ExportedServicesRevisionMetadataCustomizer.java
index 5c1cc8e9d11..56797235a3f 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ExportedServicesRevisionMetadataCustomizer.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/ExportedServicesRevisionMetadataCustomizer.java
@@ -18,8 +18,8 @@
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.compiler.support.ClassUtils;
-import org.apache.dubbo.metadata.LocalMetadataService;
import org.apache.dubbo.metadata.MetadataService;
+import org.apache.dubbo.metadata.WritableMetadataService;
import org.apache.dubbo.registry.client.ServiceInstance;
import org.apache.dubbo.registry.client.ServiceInstanceMetadataCustomizer;
@@ -47,8 +47,8 @@ protected String buildMetadataKey(ServiceInstance serviceInstance) {
@Override
protected String buildMetadataValue(ServiceInstance serviceInstance) {
- LocalMetadataService localMetadataService = LocalMetadataService.getDefaultExtension();
- List exportedURLs = localMetadataService.getExportedURLs();
+ WritableMetadataService writableMetadataService = WritableMetadataService.getDefaultExtension();
+ List exportedURLs = writableMetadataService.getExportedURLs();
Object[] data = exportedURLs.stream()
.map(URL::valueOf) // String to URL
.map(URL::getServiceInterface) // get the service interface
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLParamsMetadataCustomizer.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLParamsMetadataCustomizer.java
index 97ba53c3404..b41873d45ca 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLParamsMetadataCustomizer.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/MetadataServiceURLParamsMetadataCustomizer.java
@@ -17,8 +17,8 @@
package org.apache.dubbo.registry.client.metadata;
import org.apache.dubbo.common.URL;
-import org.apache.dubbo.metadata.LocalMetadataService;
import org.apache.dubbo.metadata.MetadataService;
+import org.apache.dubbo.metadata.WritableMetadataService;
import org.apache.dubbo.registry.client.ServiceInstance;
import org.apache.dubbo.registry.client.ServiceInstanceMetadataCustomizer;
@@ -45,7 +45,7 @@ public String buildMetadataKey(ServiceInstance serviceInstance) {
@Override
public String buildMetadataValue(ServiceInstance serviceInstance) {
- LocalMetadataService localMetadataService = LocalMetadataService.getDefaultExtension();
+ WritableMetadataService writableMetadataService = WritableMetadataService.getDefaultExtension();
String serviceInterface = MetadataService.class.getName();
@@ -53,7 +53,7 @@ public String buildMetadataValue(ServiceInstance serviceInstance) {
String version = MetadataService.VERSION;
- List urls = localMetadataService.getExportedURLs(serviceInterface, group, version);
+ List urls = writableMetadataService.getExportedURLs(serviceInterface, group, version);
return getMetadataServiceParameter(toURLs(urls));
}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/DefaultMetadataServiceProxyFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/DefaultMetadataServiceProxyFactory.java
new file mode 100644
index 00000000000..58dca64ac10
--- /dev/null
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/DefaultMetadataServiceProxyFactory.java
@@ -0,0 +1,73 @@
+/*
+ * 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.client.metadata.proxy;
+
+import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.extension.ExtensionLoader;
+import org.apache.dubbo.metadata.MetadataService;
+import org.apache.dubbo.registry.client.ServiceInstance;
+import org.apache.dubbo.rpc.Invoker;
+import org.apache.dubbo.rpc.Protocol;
+import org.apache.dubbo.rpc.ProxyFactory;
+import org.apache.dubbo.rpc.cluster.Cluster;
+import org.apache.dubbo.rpc.cluster.directory.StaticDirectory;
+import org.apache.dubbo.rpc.cluster.support.AvailableCluster;
+
+import java.lang.reflect.Proxy;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * The factory of {@link MetadataService}'s {@link Proxy}
+ *
+ * @since 2.7.3
+ */
+public class DefaultMetadataServiceProxyFactory implements MetadataServiceProxyFactory {
+
+ private final Map proxys = new HashMap<>();
+
+ private ProxyFactory proxyFactory;
+
+ private Protocol protocol;
+
+ private Cluster cluster = ExtensionLoader.getExtensionLoader(Cluster.class).getExtension(AvailableCluster.NAME);
+
+ public void setProtocol(Protocol protocol) {
+ this.protocol = protocol;
+ }
+
+ public void setProxyFactory(ProxyFactory proxyFactory) {
+ this.proxyFactory = proxyFactory;
+ }
+
+ @Override
+ public MetadataService getProxy(ServiceInstance serviceInstance) {
+ return proxys.computeIfAbsent(serviceInstance.getId(), id -> createProxy(serviceInstance));
+ }
+
+ protected MetadataService createProxy(ServiceInstance serviceInstance) {
+ List urls = ServiceInstance.toUrls(serviceInstance);
+ List> invokers = urls.stream()
+ .map(url -> protocol.refer(MetadataService.class, url))
+ .collect(Collectors.toList());
+
+ Invoker invoker = cluster.join(new StaticDirectory<>(invokers));
+ return proxyFactory.getProxy(invoker);
+ }
+}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/MetadataServiceProxyFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/MetadataServiceProxyFactory.java
new file mode 100644
index 00000000000..9ec31dff55b
--- /dev/null
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/MetadataServiceProxyFactory.java
@@ -0,0 +1,55 @@
+/*
+ * 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.client.metadata.proxy;
+
+import org.apache.dubbo.common.extension.SPI;
+import org.apache.dubbo.metadata.MetadataService;
+import org.apache.dubbo.registry.client.ServiceInstance;
+
+import static org.apache.dubbo.common.extension.ExtensionLoader.getExtensionLoader;
+
+/**
+ * A factory to create a {@link MetadataService} proxy
+ *
+ * @see ServiceInstance
+ * @see MetadataService
+ * @since 2.7.3
+ */
+@SPI("local")
+public interface MetadataServiceProxyFactory {
+
+ /**
+ * Create a {@link MetadataService} proxy via the specified {@link ServiceInstance}
+ *
+ * @param serviceInstance the instance of {@link ServiceInstance}
+ * @return non-null
+ */
+ MetadataService getProxy(ServiceInstance serviceInstance);
+
+ /**
+ * Get the default extension of {@link MetadataServiceProxyFactory}
+ *
+ * @return non-null
+ */
+ static MetadataServiceProxyFactory getDefaultExtension() {
+ return getExtensionLoader(MetadataServiceProxyFactory.class).getDefaultExtension();
+ }
+
+ static MetadataServiceProxyFactory getExtension(String name) {
+ return getExtensionLoader(MetadataServiceProxyFactory.class).getExtension(name);
+ }
+}
diff --git a/dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/mock/MockDynamicConfigurationFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/RemoteMetadataServiceProxyFactory.java
similarity index 61%
rename from dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/mock/MockDynamicConfigurationFactory.java
rename to dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/RemoteMetadataServiceProxyFactory.java
index 13482b77296..3544294fe58 100644
--- a/dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/mock/MockDynamicConfigurationFactory.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/metadata/proxy/RemoteMetadataServiceProxyFactory.java
@@ -14,19 +14,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.configcenter.mock;
+package org.apache.dubbo.registry.client.metadata.proxy;
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.configcenter.AbstractDynamicConfigurationFactory;
-import org.apache.dubbo.configcenter.DynamicConfiguration;
+import org.apache.dubbo.metadata.MetadataService;
+import org.apache.dubbo.metadata.WritableMetadataService;
+import org.apache.dubbo.registry.client.ServiceInstance;
+
+import static org.apache.dubbo.common.constants.CommonConstants.METADATA_REMOTE;
/**
*
*/
-public class MockDynamicConfigurationFactory extends AbstractDynamicConfigurationFactory {
+public class RemoteMetadataServiceProxyFactory implements MetadataServiceProxyFactory {
@Override
- protected DynamicConfiguration createDynamicConfiguration(URL url) {
- return new MockDynamicConfiguration(url);
+ public MetadataService getProxy(ServiceInstance serviceInstance) {
+ return WritableMetadataService.getExtension(METADATA_REMOTE);
}
+
}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java
index 5258d24c9f4..7a135a79680 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java
@@ -16,14 +16,14 @@
*/
package org.apache.dubbo.registry.integration;
+import org.apache.dubbo.common.config.configcenter.ConfigChangeEvent;
+import org.apache.dubbo.common.config.configcenter.ConfigChangeType;
+import org.apache.dubbo.common.config.configcenter.ConfigurationListener;
+import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
import org.apache.dubbo.common.constants.CommonConstants;
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.configcenter.ConfigChangeEvent;
-import org.apache.dubbo.configcenter.ConfigChangeType;
-import org.apache.dubbo.configcenter.ConfigurationListener;
-import org.apache.dubbo.configcenter.DynamicConfiguration;
import org.apache.dubbo.rpc.cluster.Configurator;
import org.apache.dubbo.rpc.cluster.configurator.parser.ConfigParser;
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java
index 2f3a83567a4..20759a562f8 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java
@@ -19,6 +19,7 @@
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.URLBuilder;
import org.apache.dubbo.common.Version;
+import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
@@ -27,7 +28,6 @@
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.common.utils.UrlUtils;
-import org.apache.dubbo.configcenter.DynamicConfiguration;
import org.apache.dubbo.registry.NotifyListener;
import org.apache.dubbo.registry.Registry;
import org.apache.dubbo.remoting.Constants;
@@ -604,6 +604,11 @@ public Class getInterface() {
return serviceType;
}
+ @Override
+ public List> getAllInvokers() {
+ return invokers;
+ }
+
@Override
public URL getUrl() {
return this.overrideDirectoryUrl;
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
index 9afa7ab9fd9..a3943882fd3 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java
@@ -19,6 +19,7 @@
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.URLBuilder;
import org.apache.dubbo.common.config.ConfigurationUtils;
+import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
@@ -26,13 +27,10 @@
import org.apache.dubbo.common.utils.NamedThreadFactory;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.common.utils.UrlUtils;
-import org.apache.dubbo.configcenter.DynamicConfiguration;
import org.apache.dubbo.registry.NotifyListener;
import org.apache.dubbo.registry.Registry;
import org.apache.dubbo.registry.RegistryFactory;
import org.apache.dubbo.registry.RegistryService;
-import org.apache.dubbo.registry.support.ProviderConsumerRegTable;
-import org.apache.dubbo.registry.support.ProviderInvokerWrapper;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
@@ -41,6 +39,7 @@
import org.apache.dubbo.rpc.cluster.Cluster;
import org.apache.dubbo.rpc.cluster.Configurator;
import org.apache.dubbo.rpc.model.ApplicationModel;
+import org.apache.dubbo.rpc.model.invoker.ProviderInvokerWrapper;
import org.apache.dubbo.rpc.protocol.InvokerWrapper;
import java.util.ArrayList;
@@ -211,7 +210,7 @@ public Exporter export(final Invoker originInvoker) throws RpcExceptio
// url to registry
final Registry registry = getRegistry(originInvoker);
final URL registeredProviderUrl = getRegisteredProviderUrl(providerUrl, registryUrl);
- ProviderInvokerWrapper providerInvokerWrapper = ProviderConsumerRegTable.registerProvider(originInvoker,
+ ProviderInvokerWrapper providerInvokerWrapper = ApplicationModel.registerProviderInvoker(originInvoker,
registryUrl, registeredProviderUrl);
//to judge if we need to delay publish
boolean register = registeredProviderUrl.getParameter("register", true);
@@ -254,8 +253,8 @@ public void reExport(final Invoker originInvoker, URL newInvokerUrl) {
final URL registeredProviderUrl = getRegisteredProviderUrl(newInvokerUrl, registryUrl);
//decide if we need to re-publish
- ProviderInvokerWrapper providerInvokerWrapper = ProviderConsumerRegTable.getProviderWrapper(registeredProviderUrl, originInvoker);
- ProviderInvokerWrapper newProviderInvokerWrapper = ProviderConsumerRegTable.registerProvider(originInvoker, registryUrl, registeredProviderUrl);
+ ProviderInvokerWrapper providerInvokerWrapper = ApplicationModel.getProviderInvoker(registeredProviderUrl.getServiceKey(), originInvoker);
+ ProviderInvokerWrapper newProviderInvokerWrapper = ApplicationModel.registerProviderInvoker(originInvoker, registryUrl, registeredProviderUrl);
/**
* Only if the new url going to Registry is different with the previous one should we do unregister and register.
*/
@@ -412,7 +411,7 @@ private Invoker doRefer(Cluster cluster, Registry registry, Class type
PROVIDERS_CATEGORY + "," + CONFIGURATORS_CATEGORY + "," + ROUTERS_CATEGORY));
Invoker invoker = cluster.join(directory);
- ProviderConsumerRegTable.registerConsumer(invoker, url, subscribeUrl, directory);
+ ApplicationModel.registerConsumerInvoker(invoker, subscribeUrl.getServiceKey());
return invoker;
}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ConsumerInvokerWrapper.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ConsumerInvokerWrapper.java
deleted file mode 100644
index 141634de25b..00000000000
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ConsumerInvokerWrapper.java
+++ /dev/null
@@ -1,88 +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.support;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.registry.integration.RegistryDirectory;
-import org.apache.dubbo.rpc.Invocation;
-import org.apache.dubbo.rpc.Invoker;
-import org.apache.dubbo.rpc.Result;
-import org.apache.dubbo.rpc.RpcException;
-
-/**
- * @date 2017/11/23
- */
-public class ConsumerInvokerWrapper implements Invoker {
- private Invoker invoker;
- private URL originUrl;
- private URL registryUrl;
- private URL consumerUrl;
- private RegistryDirectory registryDirectory;
-
- public ConsumerInvokerWrapper(Invoker invoker, URL registryUrl, URL consumerUrl, RegistryDirectory registryDirectory) {
- this.invoker = invoker;
- this.originUrl = URL.valueOf(invoker.getUrl().toFullString());
- this.registryUrl = URL.valueOf(registryUrl.toFullString());
- this.consumerUrl = consumerUrl;
- this.registryDirectory = registryDirectory;
- }
-
- @Override
- public Class getInterface() {
- return invoker.getInterface();
- }
-
- @Override
- public URL getUrl() {
- return invoker.getUrl();
- }
-
- @Override
- public boolean isAvailable() {
- return invoker.isAvailable();
- }
-
- @Override
- public Result invoke(Invocation invocation) throws RpcException {
- return invoker.invoke(invocation);
- }
-
- @Override
- public void destroy() {
- invoker.destroy();
- }
-
- public URL getOriginUrl() {
- return originUrl;
- }
-
- public URL getRegistryUrl() {
- return registryUrl;
- }
-
- public Invoker getInvoker() {
- return invoker;
- }
-
- public URL getConsumerUrl() {
- return consumerUrl;
- }
-
- public RegistryDirectory getRegistryDirectory() {
- return registryDirectory;
- }
-}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ProviderConsumerRegTable.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ProviderConsumerRegTable.java
deleted file mode 100644
index 9af39888e21..00000000000
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ProviderConsumerRegTable.java
+++ /dev/null
@@ -1,112 +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.support;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.utils.ConcurrentHashSet;
-import org.apache.dubbo.registry.integration.RegistryDirectory;
-import org.apache.dubbo.rpc.Invoker;
-
-import java.util.Collections;
-import java.util.Map;
-import java.util.Objects;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-/**
- * @date 2017/11/23
- */
-public class ProviderConsumerRegTable {
- public static ConcurrentHashMap> providerInvokers = new ConcurrentHashMap<>();
- public static ConcurrentHashMap> consumerInvokers = new ConcurrentHashMap<>();
-
- public static ProviderInvokerWrapper registerProvider(Invoker invoker, URL registryUrl, URL providerUrl) {
- ProviderInvokerWrapper wrapperInvoker = new ProviderInvokerWrapper<>(invoker, registryUrl, providerUrl);
- String serviceUniqueName = providerUrl.getServiceKey();
- ConcurrentMap invokers = providerInvokers.get(serviceUniqueName);
- if (invokers == null) {
- providerInvokers.putIfAbsent(serviceUniqueName, new ConcurrentHashMap<>());
- invokers = providerInvokers.get(serviceUniqueName);
- }
- invokers.put(invoker, wrapperInvoker);
- return wrapperInvoker;
- }
-
- /*public static ProviderInvokerWrapper removeProviderWrapper(Invoker invoker, URL providerUrl) {
- String serviceUniqueName = providerUrl.getServiceKey();
- Set invokers = providerInvokers.get(serviceUniqueName);
- if (invokers == null) {
- return null;
- }
- return invokers.remove(new ProviderIndvokerWrapper(invoker, null, null));
- }*/
-
- public static Set getProviderInvoker(String serviceUniqueName) {
- ConcurrentMap invokers = providerInvokers.get(serviceUniqueName);
- if (invokers == null) {
- return Collections.emptySet();
- }
- return new HashSet<>(invokers.values());
- }
-
- public static ProviderInvokerWrapper getProviderWrapper(URL registeredProviderUrl, Invoker invoker) {
- String serviceUniqueName = registeredProviderUrl.getServiceKey();
- ConcurrentMap invokers = providerInvokers.get(serviceUniqueName);
- if (invokers == null) {
- return null;
- }
-
- for (Map.Entry entry : invokers.entrySet()) {
- if (entry.getKey() == invoker) {
- return entry.getValue();
- }
- }
-
- return null;
- }
-
- public static void registerConsumer(Invoker invoker, URL registryUrl, URL consumerUrl, RegistryDirectory registryDirectory) {
- ConsumerInvokerWrapper wrapperInvoker = new ConsumerInvokerWrapper(invoker, registryUrl, consumerUrl, registryDirectory);
- String serviceUniqueName = consumerUrl.getServiceKey();
- Set invokers = consumerInvokers.get(serviceUniqueName);
- if (invokers == null) {
- consumerInvokers.putIfAbsent(serviceUniqueName, new ConcurrentHashSet());
- invokers = consumerInvokers.get(serviceUniqueName);
- }
- invokers.add(wrapperInvoker);
- }
-
- public static Set getConsumerInvoker(String serviceUniqueName) {
- Set invokers = consumerInvokers.get(serviceUniqueName);
- return invokers == null ? Collections.emptySet() : invokers;
- }
-
- public static boolean isRegistered(String serviceUniqueName) {
- Set providerInvokerWrapperSet = ProviderConsumerRegTable.getProviderInvoker(serviceUniqueName);
- return providerInvokerWrapperSet.stream().anyMatch(ProviderInvokerWrapper::isReg);
- }
-
- public static int getConsumerAddressNum(String serviceUniqueName) {
- Set providerInvokerWrapperSet = ProviderConsumerRegTable.getConsumerInvoker(serviceUniqueName);
- return providerInvokerWrapperSet.stream()
- .map(w -> w.getRegistryDirectory().getUrlInvokerMap())
- .filter(Objects::nonNull)
- .mapToInt(Map::size).sum();
- }
-}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ServiceOrientedRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ServiceOrientedRegistry.java
index 945df0d680a..3d1f613b14c 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ServiceOrientedRegistry.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/ServiceOrientedRegistry.java
@@ -20,15 +20,15 @@
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.LocalMetadataService;
import org.apache.dubbo.metadata.MetadataService;
import org.apache.dubbo.metadata.ServiceNameMapping;
+import org.apache.dubbo.metadata.WritableMetadataService;
import org.apache.dubbo.registry.NotifyListener;
import org.apache.dubbo.registry.Registry;
import org.apache.dubbo.registry.client.ServiceDiscovery;
import org.apache.dubbo.registry.client.ServiceDiscoveryFactory;
import org.apache.dubbo.registry.client.ServiceInstance;
-import org.apache.dubbo.registry.client.metadata.MetadataServiceProxyFactory;
+import org.apache.dubbo.registry.client.metadata.proxy.MetadataServiceProxyFactory;
import org.apache.dubbo.registry.client.selector.ServiceInstanceSelector;
import java.util.ArrayList;
@@ -50,6 +50,7 @@
import static java.util.stream.Stream.of;
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_PROTOCOL;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
+import static org.apache.dubbo.common.constants.CommonConstants.METADATA_DEFAULT;
import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
@@ -61,6 +62,7 @@
import static org.apache.dubbo.common.utils.CollectionUtils.isEmpty;
import static org.apache.dubbo.common.utils.CollectionUtils.isNotEmpty;
import static org.apache.dubbo.common.utils.StringUtils.isBlank;
+import static org.apache.dubbo.metadata.support.Constants.METADATA_REPORT_KEY;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getExportedServicesRevision;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getMetadataServiceURLsParams;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getProviderHost;
@@ -87,18 +89,19 @@ public class ServiceOrientedRegistry extends FailbackRegistry {
private final ServiceNameMapping serviceNameMapping;
- private final LocalMetadataService localMetadataService;
+ private final WritableMetadataService writableMetadataService;
private final MetadataServiceProxyFactory metadataServiceProxyFactory;
-
public ServiceOrientedRegistry(URL registryURL) {
super(registryURL);
this.serviceDiscovery = buildServiceDiscovery(registryURL);
this.subscribedServices = buildSubscribedServices(registryURL);
this.serviceNameMapping = ServiceNameMapping.getDefaultExtension();
- this.localMetadataService = LocalMetadataService.getDefaultExtension();
- this.metadataServiceProxyFactory = MetadataServiceProxyFactory.getDefaultExtension();
+
+ String metadata = registryURL.getParameter(METADATA_REPORT_KEY, METADATA_DEFAULT);
+ this.writableMetadataService = WritableMetadataService.getExtension(metadata);
+ this.metadataServiceProxyFactory = MetadataServiceProxyFactory.getExtension(metadata);
}
private Set buildSubscribedServices(URL url) {
@@ -140,7 +143,7 @@ public void doRegister(URL url) {
if (!shouldRegister(url)) { // Should Not Register
return;
}
- if (localMetadataService.exportURL(url)) {
+ if (writableMetadataService.exportURL(url)) {
if (logger.isInfoEnabled()) {
logger.info(format("The URL[%s] registered successfully.", url.toString()));
}
@@ -156,7 +159,7 @@ public void doUnregister(URL url) {
if (!shouldRegister(url)) {
return;
}
- if (localMetadataService.unexportURL(url)) {
+ if (writableMetadataService.unexportURL(url)) {
if (logger.isInfoEnabled()) {
logger.info(format("The URL[%s] deregistered successfully.", url.toString()));
}
@@ -177,7 +180,7 @@ public void doSubscribe(URL url, NotifyListener listener) {
@Override
public void doUnsubscribe(URL url, NotifyListener listener) {
- localMetadataService.unsubscribeURL(url);
+ writableMetadataService.unsubscribeURL(url);
}
@Override
@@ -194,7 +197,7 @@ public void destroy() {
protected void subscribeURLs(URL url, NotifyListener listener) {
- localMetadataService.subscribeURL(url);
+ writableMetadataService.subscribeURL(url);
Set serviceNames = getServices(url);
@@ -397,7 +400,7 @@ protected List