diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/directory/MockDirInvocation.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/directory/MockDirInvocation.java index f08bfbe424..a7c77ac519 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/directory/MockDirInvocation.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/directory/MockDirInvocation.java @@ -34,6 +34,11 @@ import static org.apache.dubbo.rpc.Constants.TOKEN_KEY; */ public class MockDirInvocation implements Invocation { + @Override + public String getTargetServiceUniqueName() { + return null; + } + public String getMethodName() { return "echo"; } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java index 03a5393843..47b19cfde8 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java @@ -668,6 +668,13 @@ public class ExtensionLoader { urls = ClassLoader.getSystemResources(fileName); } if (urls != null) { + if (!urls.hasMoreElements()) { + // try to load from ExtensionLoader's ClassLoader + ClassLoader extensionLoaderClassLoader = this.getClass().getClassLoader(); + if (ClassLoader.getSystemClassLoader() != extensionLoaderClassLoader) { + urls = extensionLoaderClassLoader.getResources(fileName); + } + } while (urls.hasMoreElements()) { java.net.URL resourceURL = urls.nextElement(); loadResource(extensionClasses, classLoader, resourceURL); diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/bytecode/MixinTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/bytecode/MixinTest.java index 954ea51fda..544c9c6fed 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/bytecode/MixinTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/bytecode/MixinTest.java @@ -18,7 +18,6 @@ package org.apache.dubbo.common.bytecode; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; public class MixinTest { diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/threadlocal/InternalThreadLocalTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/threadlocal/InternalThreadLocalTest.java index 8c63ec0aec..df0b908a6c 100644 --- a/dubbo-common/src/test/java/org/apache/dubbo/common/threadlocal/InternalThreadLocalTest.java +++ b/dubbo-common/src/test/java/org/apache/dubbo/common/threadlocal/InternalThreadLocalTest.java @@ -20,7 +20,6 @@ package org.apache.dubbo.common.threadlocal; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.util.Objects; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; diff --git a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invocation.java b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invocation.java index 3a91b00bfa..bf0acd4ca9 100644 --- a/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invocation.java +++ b/dubbo-compatible/src/main/java/com/alibaba/dubbo/rpc/Invocation.java @@ -51,6 +51,11 @@ public interface Invocation extends org.apache.dubbo.rpc.Invocation { this.delegate = invocation; } + @Override + public String getTargetServiceUniqueName() { + return delegate.getTargetServiceUniqueName(); + } + @Override public String getMethodName() { return delegate.getMethodName(); diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/cache/CacheTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/cache/CacheTest.java index 0c9a82ecae..b8300cfe93 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/cache/CacheTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/cache/CacheTest.java @@ -24,7 +24,6 @@ import com.alibaba.dubbo.cache.CacheFactory; import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.rpc.Invocation; import com.alibaba.dubbo.rpc.Invoker; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -49,6 +48,11 @@ public class CacheTest { } static class NullInvocation implements Invocation { + @Override + public String getTargetServiceUniqueName() { + return null; + } + @Override public String getMethodName() { return null; diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/filter/LegacyInvocation.java b/dubbo-compatible/src/test/java/org/apache/dubbo/filter/LegacyInvocation.java index 3544c0b46a..b6d3c10bdd 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/filter/LegacyInvocation.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/filter/LegacyInvocation.java @@ -41,6 +41,11 @@ public class LegacyInvocation implements Invocation { this.arg0 = arg0; } + @Override + public String getTargetServiceUniqueName() { + return null; + } + public String getMethodName() { return "echo"; } diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/service/MockInvocation.java b/dubbo-compatible/src/test/java/org/apache/dubbo/service/MockInvocation.java index 1f0e47b9ae..5285a8bcd3 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/service/MockInvocation.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/service/MockInvocation.java @@ -40,6 +40,11 @@ public class MockInvocation implements Invocation { this.arg0 = arg0; } + @Override + public String getTargetServiceUniqueName() { + return null; + } + public String getMethodName() { return "echo"; } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java index 0755fcb442..4b4b91dd12 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java @@ -867,6 +867,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig { } public void setMetadataReportConfig(MetadataReportConfig metadataReportConfig) { + ConfigManager.getInstance().setMetadataReportConfig(metadataReportConfig); this.metadataReportConfig = metadataReportConfig; } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java index e5d04d4d41..deff5d64bb 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -38,6 +38,7 @@ import org.apache.dubbo.rpc.cluster.directory.StaticDirectory; import org.apache.dubbo.rpc.cluster.support.ClusterUtils; import org.apache.dubbo.rpc.cluster.support.RegistryAwareCluster; import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.model.ConsumerMethodModel; import org.apache.dubbo.rpc.model.ConsumerModel; import org.apache.dubbo.rpc.model.ServiceMetadata; import org.apache.dubbo.rpc.model.ServiceModel; @@ -337,7 +338,11 @@ public class ReferenceConfig extends AbstractReferenceConfig { map.put(methodConfig.getName() + ".retries", "0"); } } - attributes.put(methodConfig.getName(), convertMethodConfig2AyncInfo(methodConfig)); + ConsumerMethodModel.AsyncMethodInfo asyncMethodInfo = convertMethodConfig2AsyncInfo(methodConfig); + if (asyncMethodInfo != null) { +// consumerModel.getMethodModel(methodConfig.getName()).addAttribute(ASYNC_KEY, asyncMethodInfo); + attributes.put(methodConfig.getName(), asyncMethodInfo); + } } } @@ -351,10 +356,11 @@ public class ReferenceConfig extends AbstractReferenceConfig { serviceMetadata.getAttachments().putAll(map); - ref = createProxy(map); - ServiceModel serviceModel = ApplicationModel.registerServiceModel(interfaceClass); ApplicationModel.initConsumerModel(serviceMetadata.getServiceKey(), buildConsumerModel(attributes, serviceModel)); + + ref = createProxy(map); + serviceMetadata.setTarget(ref); serviceMetadata.addAttribute(PROXY_CLASS_REF, ref); initialized = true; @@ -409,7 +415,7 @@ public class ReferenceConfig extends AbstractReferenceConfig { } } else { // assemble URL from register center's configuration // if protocols not injvm checkRegistry - if (!LOCAL_PROTOCOL.equalsIgnoreCase(getProtocol())){ + if (!LOCAL_PROTOCOL.equalsIgnoreCase(getProtocol())) { checkRegistry(); List us = loadRegistries(false); if (CollectionUtils.isNotEmpty(us)) { diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/context/ConfigManager.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/context/ConfigManager.java index 79b097a0db..124bffb201 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/context/ConfigManager.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/context/ConfigManager.java @@ -23,6 +23,7 @@ import org.apache.dubbo.config.AbstractConfig; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ConfigCenterConfig; import org.apache.dubbo.config.ConsumerConfig; +import org.apache.dubbo.config.MetadataReportConfig; import org.apache.dubbo.config.ModuleConfig; import org.apache.dubbo.config.MonitorConfig; import org.apache.dubbo.config.ProtocolConfig; @@ -79,6 +80,7 @@ public class ConfigManager { private MonitorConfig monitor; private ModuleConfig module; private ConfigCenterConfig configCenter; + private MetadataReportConfig metadataReportConfig; private Map protocols = new ConcurrentHashMap<>(); private Map registries = new ConcurrentHashMap<>(); @@ -137,6 +139,17 @@ public class ConfigManager { } } + public Optional getMetadataReportConfig() { + return Optional.ofNullable(metadataReportConfig); + } + + public void setMetadataReportConfig(MetadataReportConfig metadataReportConfig) { + if (metadataReportConfig != null) { + checkDuplicate(this.metadataReportConfig, metadataReportConfig); + this.metadataReportConfig = metadataReportConfig; + } + } + public Optional getProvider(String id) { return Optional.ofNullable(providers.get(id)); } diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java index 7b28d82e1f..0242361ac8 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/ConfigTest.java @@ -44,7 +44,6 @@ import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.Filter; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcException; -import org.apache.dubbo.rpc.service.GenericException; import org.apache.dubbo.rpc.service.GenericService; import org.junit.Assert; @@ -57,6 +56,8 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; import java.util.Collection; import java.util.List; +import static org.apache.dubbo.rpc.Constants.GENERIC_KEY; +import static org.apache.dubbo.rpc.Constants.GENERIC_SERIALIZATION_BEAN; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -65,9 +66,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.junit.matchers.JUnitMatchers.containsString; -import static org.apache.dubbo.rpc.Constants.GENERIC_SERIALIZATION_BEAN; -import static org.apache.dubbo.rpc.Constants.GENERIC_KEY; - /** * ConfigTest diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessorTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessorTest.java index 17d3023dc6..a509b43f41 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessorTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessorTest.java @@ -17,7 +17,6 @@ package org.apache.dubbo.config.spring.beans.factory.annotation; import org.apache.dubbo.config.spring.ServiceBean; -import org.apache.dubbo.config.spring.api.DemoService; import org.apache.dubbo.config.spring.api.HelloService; import org.junit.Assert; diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/config/YamlPropertySourceFactory.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/config/YamlPropertySourceFactory.java index 060a0e4782..271b179ecb 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/config/YamlPropertySourceFactory.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/config/YamlPropertySourceFactory.java @@ -30,7 +30,6 @@ import org.yaml.snakeyaml.resolver.Resolver; import java.io.IOException; import java.util.LinkedHashMap; import java.util.Map; -import java.util.Properties; import java.util.regex.Pattern; /** diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml index 168678d550..6031d9e181 100644 --- a/dubbo-dependencies-bom/pom.xml +++ b/dubbo-dependencies-bom/pom.xml @@ -153,7 +153,7 @@ 6.1.26 2.0 1.1.0 - 2.7.4-SNAPSHOT + 2.7.4-hsf3-SNAPSHOT diff --git a/dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml b/dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml index 49f4a56223..92b10d3db8 100644 --- a/dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml +++ b/dubbo-dependencies/dubbo-dependencies-zookeeper/pom.xml @@ -32,7 +32,7 @@ pom - 2.7.4-SNAPSHOT + 2.7.4-hsf3-SNAPSHOT 1.1.0 diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/AddressListener.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/AddressListener.java index 9c79f15819..e1d8809374 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/AddressListener.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/AddressListener.java @@ -18,6 +18,7 @@ package org.apache.dubbo.registry; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.SPI; +import org.apache.dubbo.rpc.cluster.Directory; import java.util.List; @@ -29,7 +30,8 @@ public interface AddressListener { * * @param addresses provider address list * @param registryDirectoryUrl + * @param registryDirectory */ - List notify(List addresses, URL registryDirectoryUrl); + List notify(List addresses, URL registryDirectoryUrl, Directory registryDirectory); } \ No newline at end of file diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/ListenerRegistryWrapper.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/ListenerRegistryWrapper.java new file mode 100644 index 0000000000..503407bc3f --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/ListenerRegistryWrapper.java @@ -0,0 +1,154 @@ +/* + * 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; + +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.CollectionUtils; + +import java.util.List; + +public class ListenerRegistryWrapper implements Registry { + private static final Logger logger = LoggerFactory.getLogger(ListenerRegistryWrapper.class); + + private final Registry registry; + private final List listeners; + + + public ListenerRegistryWrapper(Registry registry, List listeners) { + this.registry = registry; + this.listeners = listeners; + } + + @Override + public URL getUrl() { + return registry.getUrl(); + } + + @Override + public boolean isAvailable() { + return registry.isAvailable(); + } + + @Override + public void destroy() { + registry.destroy(); + } + + @Override + public void register(URL url) { + try { + registry.register(url); + } finally { + if (CollectionUtils.isNotEmpty(listeners)) { + RuntimeException exception = null; + for (RegistryServiceListener listener : listeners) { + if (listener != null) { + try { + listener.onRegister(url); + } catch (RuntimeException t) { + logger.error(t.getMessage(), t); + exception = t; + } + } + } + if (exception != null) { + throw exception; + } + } + } + } + + @Override + public void unregister(URL url) { + try { + registry.unregister(url); + } finally { + if (CollectionUtils.isNotEmpty(listeners)) { + RuntimeException exception = null; + for (RegistryServiceListener listener : listeners) { + if (listener != null) { + try { + listener.onUnregister(url); + } catch (RuntimeException t) { + logger.error(t.getMessage(), t); + exception = t; + } + } + } + if (exception != null) { + throw exception; + } + } + } + } + + @Override + public void subscribe(URL url, NotifyListener listener) { + try { + registry.subscribe(url, listener); + } finally { + if (CollectionUtils.isNotEmpty(listeners)) { + RuntimeException exception = null; + for (RegistryServiceListener registryListener : listeners) { + if (registryListener != null) { + try { + registryListener.onSubscribe(url); + } catch (RuntimeException t) { + logger.error(t.getMessage(), t); + exception = t; + } + } + } + if (exception != null) { + throw exception; + } + } + } + } + + @Override + public void unsubscribe(URL url, NotifyListener listener) { + try { + registry.unsubscribe(url, listener); + } finally { + if (CollectionUtils.isNotEmpty(listeners)) { + RuntimeException exception = null; + for (RegistryServiceListener registryListener : listeners) { + if (registryListener != null) { + try { + registryListener.onUnsubscribe(url); + } catch (RuntimeException t) { + logger.error(t.getMessage(), t); + exception = t; + } + } + } + if (exception != null) { + throw exception; + } + } + } + } + + @Override + public List lookup(URL url) { + return registry.lookup(url); + } +} diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryFactoryWrapper.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryFactoryWrapper.java new file mode 100644 index 0000000000..568b86aa85 --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryFactoryWrapper.java @@ -0,0 +1,38 @@ +/* + * 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; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.extension.ExtensionLoader; + +import java.util.Collections; + +public class RegistryFactoryWrapper implements RegistryFactory { + private RegistryFactory registryFactory; + + public RegistryFactoryWrapper(RegistryFactory registryFactory) { + this.registryFactory = registryFactory; + } + + @Override + public Registry getRegistry(URL url) { + return new ListenerRegistryWrapper(registryFactory.getRegistry(url), + Collections.unmodifiableList(ExtensionLoader.getExtensionLoader(RegistryServiceListener.class) + .getActivateExtension(url, "registry.listeners"))); + } +} diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryServiceListener.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryServiceListener.java new file mode 100644 index 0000000000..3f88f6eeab --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/RegistryServiceListener.java @@ -0,0 +1,41 @@ +/* + * 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; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.extension.SPI; + +@SPI +public interface RegistryServiceListener { + default void onRegister(URL url) { + + } + + + default void onUnregister(URL url) { + + } + + default void onSubscribe(URL url) { + + } + + default void onUnsubscribe(URL url) { + + } +} 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 062f23b30d..6c7f167bfc 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 @@ -236,7 +236,7 @@ public class RegistryDirectory extends AbstractDirectory implements Notify List supportedListeners = addressListenerExtensionLoader.getActivateExtension(getUrl(), (String[]) null); if (supportedListeners != null && !supportedListeners.isEmpty()) { for (AddressListener addressListener : supportedListeners) { - providerURLs = addressListener.notify(providerURLs, getUrl()); + providerURLs = addressListener.notify(providerURLs, getUrl(),this); } } refreshOverrideAndInvoker(providerURLs); diff --git a/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory b/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory new file mode 100644 index 0000000000..89b4b0ef6e --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory @@ -0,0 +1 @@ +wrapper=org.apache.dubbo.registry.RegistryFactoryWrapper \ No newline at end of file diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/RegistryFactoryWrapperTest.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/RegistryFactoryWrapperTest.java new file mode 100644 index 0000000000..01d310dbac --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/RegistryFactoryWrapperTest.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; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.extension.ExtensionLoader; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +public class RegistryFactoryWrapperTest { + private RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension(); + + @Test + public void test() throws Exception { + RegistryServiceListener listener1 = Mockito.mock(RegistryServiceListener.class); + RegistryServiceListener1.delegate = listener1; + RegistryServiceListener listener2 = Mockito.mock(RegistryServiceListener.class); + RegistryServiceListener2.delegate = listener2; + + Registry registry = registryFactory.getRegistry(URL.valueOf("simple://localhost:8080/registry-service")); + URL url = URL.valueOf("dubbo://localhost:8081/simple.service"); + registry.register(url); + + Mockito.verify(listener1, Mockito.times(1)).onRegister(url); + Mockito.verify(listener2, Mockito.times(1)).onRegister(url); + + registry.unregister(url); + Mockito.verify(listener1, Mockito.times(1)).onUnregister(url); + Mockito.verify(listener2, Mockito.times(1)).onUnregister(url); + + registry.subscribe(url, Mockito.mock(NotifyListener.class)); + Mockito.verify(listener1, Mockito.times(1)).onSubscribe(url); + Mockito.verify(listener2, Mockito.times(1)).onSubscribe(url); + + registry.unsubscribe(url, Mockito.mock(NotifyListener.class)); + Mockito.verify(listener1, Mockito.times(1)).onUnsubscribe(url); + Mockito.verify(listener2, Mockito.times(1)).onUnsubscribe(url); + } + +} diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/RegistryServiceListener1.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/RegistryServiceListener1.java new file mode 100644 index 0000000000..0584a7860b --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/RegistryServiceListener1.java @@ -0,0 +1,46 @@ +/* + * 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; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.extension.Activate; + +@Activate(order = 1) +public class RegistryServiceListener1 implements RegistryServiceListener { + static RegistryServiceListener delegate; + + @Override + public void onRegister(URL url) { + delegate.onRegister(url); + } + + @Override + public void onUnregister(URL url) { + delegate.onUnregister(url); + } + + @Override + public void onSubscribe(URL url) { + delegate.onSubscribe(url); + } + + @Override + public void onUnsubscribe(URL url) { + delegate.onUnsubscribe(url); + } +} diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/RegistryServiceListener2.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/RegistryServiceListener2.java new file mode 100644 index 0000000000..c0f6927be8 --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/RegistryServiceListener2.java @@ -0,0 +1,46 @@ +/* + * 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; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.extension.Activate; + +@Activate(order = 2) +public class RegistryServiceListener2 implements RegistryServiceListener { + static RegistryServiceListener delegate; + + @Override + public void onRegister(URL url) { + delegate.onRegister(url); + } + + @Override + public void onUnregister(URL url) { + delegate.onUnregister(url); + } + + @Override + public void onSubscribe(URL url) { + delegate.onSubscribe(url); + } + + @Override + public void onUnsubscribe(URL url) { + delegate.onUnsubscribe(url); + } +} diff --git a/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/SimpleRegistryFactory.java b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/SimpleRegistryFactory.java new file mode 100644 index 0000000000..b39a37a181 --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/SimpleRegistryFactory.java @@ -0,0 +1,28 @@ +/* + * 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; + +import org.apache.dubbo.common.URL; +import org.mockito.Mockito; + +public class SimpleRegistryFactory implements RegistryFactory { + @Override + public Registry getRegistry(URL url) { + return Mockito.mock(Registry.class); + } +} diff --git a/dubbo-registry/dubbo-registry-api/src/test/resources/META-INF/dubbo/org.apache.dubbo.registry.RegistryFactory b/dubbo-registry/dubbo-registry-api/src/test/resources/META-INF/dubbo/org.apache.dubbo.registry.RegistryFactory new file mode 100644 index 0000000000..70eb5c3db7 --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/test/resources/META-INF/dubbo/org.apache.dubbo.registry.RegistryFactory @@ -0,0 +1 @@ +simple=org.apache.dubbo.registry.SimpleRegistryFactory \ No newline at end of file diff --git a/dubbo-registry/dubbo-registry-api/src/test/resources/META-INF/dubbo/org.apache.dubbo.registry.RegistryServiceListener b/dubbo-registry/dubbo-registry-api/src/test/resources/META-INF/dubbo/org.apache.dubbo.registry.RegistryServiceListener new file mode 100644 index 0000000000..2cfe6c4587 --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/test/resources/META-INF/dubbo/org.apache.dubbo.registry.RegistryServiceListener @@ -0,0 +1,2 @@ +listener-one=org.apache.dubbo.registry.RegistryServiceListener1 +listener-two=org.apache.dubbo.registry.RegistryServiceListener2 \ No newline at end of file diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Invocation.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Invocation.java index f5d2a62b4f..fb068608d4 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Invocation.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/Invocation.java @@ -27,6 +27,8 @@ import java.util.Map; */ public interface Invocation { + String getTargetServiceUniqueName(); + /** * get method name. * diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java index 7bc6bfc348..960e091a6b 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java @@ -44,6 +44,8 @@ public class RpcInvocation implements Invocation, Serializable { private static final long serialVersionUID = -4355285085441097045L; + private String targetServiceUniqueName; + private String methodName; private String serviceName; @@ -93,11 +95,13 @@ public class RpcInvocation implements Invocation, Serializable { setAttachment(APPLICATION_KEY, url.getParameter(APPLICATION_KEY)); } } + this.targetServiceUniqueName = invocation.getTargetServiceUniqueName(); } public RpcInvocation(Invocation invocation) { this(invocation.getMethodName(), invocation.getServiceName(), invocation.getParameterTypes(), invocation.getArguments(), invocation.getAttachments(), invocation.getInvoker()); + this.targetServiceUniqueName = invocation.getTargetServiceUniqueName(); } public RpcInvocation(Method method, String serviceName, Object[] arguments) { @@ -157,6 +161,15 @@ public class RpcInvocation implements Invocation, Serializable { return attributes; } + @Override + public String getTargetServiceUniqueName() { + return targetServiceUniqueName; + } + + public void setTargetServiceUniqueName(String targetServiceUniqueName) { + this.targetServiceUniqueName = targetServiceUniqueName; + } + @Override public String getMethodName() { return methodName; diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java index 9eada7cf57..9b655212c0 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java @@ -134,7 +134,11 @@ public class GenericFilter implements Filter, Filter.Listener { args[0].getClass().getName()); } } - return invoker.invoke(new RpcInvocation(method, invoker.getInterface().getName(), args, inv.getAttachments(), inv.getAttributes())); + RpcInvocation rpcInvocation = new RpcInvocation(method, invoker.getInterface().getName(), args, inv.getAttachments(), inv.getAttributes()); + rpcInvocation.setInvoker(inv.getInvoker()); + rpcInvocation.setTargetServiceUniqueName(inv.getTargetServiceUniqueName()); + + return invoker.invoke(rpcInvocation); } catch (NoSuchMethodException e) { throw new RpcException(e.getMessage(), e); } catch (ClassNotFoundException e) { diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractProtocol.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractProtocol.java index ceeb92e180..8fe9886c9b 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractProtocol.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/protocol/AbstractProtocol.java @@ -28,6 +28,8 @@ import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.support.ProtocolUtils; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -92,4 +94,12 @@ public abstract class AbstractProtocol implements Protocol { } protected abstract Invoker protocolBindingRefer(Class type, URL url) throws RpcException; + + public Map> getExporterMap() { + return exporterMap; + } + + public Collection> getExporters() { + return Collections.unmodifiableCollection(exporterMap.values()); + } } diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java index e310ac7b48..09322a9552 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/proxy/InvokerInvocationHandler.java @@ -38,20 +38,22 @@ public class InvokerInvocationHandler implements InvocationHandler { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String methodName = method.getName(); -// Class[] parameterTypes = method.getParameterTypes(); -// if (method.getDeclaringClass() == Object.class) { -// return method.invoke(invoker, args); -// } -// if ("toString".equals(methodName) && parameterTypes.length == 0) { -// return invoker.toString(); -// } -// if ("hashCode".equals(methodName) && parameterTypes.length == 0) { -// return invoker.hashCode(); -// } -// if ("equals".equals(methodName) && parameterTypes.length == 1) { -// return invoker.equals(args[0]); -// } + Class[] parameterTypes = method.getParameterTypes(); + if (method.getDeclaringClass() == Object.class) { + return method.invoke(invoker, args); + } + if ("toString".equals(methodName) && parameterTypes.length == 0) { + return invoker.toString(); + } + if ("hashCode".equals(methodName) && parameterTypes.length == 0) { + return invoker.hashCode(); + } + if ("equals".equals(methodName) && parameterTypes.length == 1) { + return invoker.equals(args[0]); + } + RpcInvocation rpcInvocation = new RpcInvocation(method, invoker.getInterface().getName(), args); + rpcInvocation.setTargetServiceUniqueName(invoker.getUrl().getServiceKey()); - return invoker.invoke(new RpcInvocation(method, invoker.getInterface().getName(), args)).recreate(); + return invoker.invoke(rpcInvocation).recreate(); } } diff --git a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MockInvocation.java b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MockInvocation.java index a33f9785ff..7ba1692db5 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MockInvocation.java +++ b/dubbo-rpc/dubbo-rpc-api/src/test/java/org/apache/dubbo/rpc/support/MockInvocation.java @@ -34,6 +34,11 @@ import static org.apache.dubbo.rpc.Constants.TOKEN_KEY; */ public class MockInvocation implements Invocation { + @Override + public String getTargetServiceUniqueName() { + return null; + } + public String getMethodName() { return "echo"; } diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java index fdea261ede..771fda7125 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DecodeableRpcInvocation.java @@ -40,6 +40,8 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; +import static org.apache.dubbo.common.URL.buildKey; +import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY; import static org.apache.dubbo.remoting.Constants.DUBBO_VERSION_KEY; @@ -152,7 +154,10 @@ public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Dec } setArguments(args); - + String targetServiceName = buildKey((String) getAttachment(PATH_KEY), + (String) getAttachment(GROUP_KEY), + (String) getAttachment(VERSION_KEY)); + setTargetServiceUniqueName(targetServiceName); } catch (ClassNotFoundException e) { throw new IOException(StringUtils.toString("Read invocation data failed.", e)); } finally { diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java index bc526f826b..bc50e53610 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/org/apache/dubbo/rpc/protocol/dubbo/DubboProtocol.java @@ -232,14 +232,6 @@ public class DubboProtocol extends AbstractProtocol { return Collections.unmodifiableCollection(serverMap.values()); } - public Collection> getExporters() { - return Collections.unmodifiableCollection(exporterMap.values()); - } - - Map> getExporterMap() { - return exporterMap; - } - private boolean isClientSide(Channel channel) { InetSocketAddress address = channel.getRemoteAddress(); URL url = channel.getUrl(); diff --git a/pom.xml b/pom.xml index 91862d8471..931c43dd4d 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,7 @@ true true - 2.7.4-SNAPSHOT + 2.7.4-hsf3-SNAPSHOT