diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/ServiceMetada.java b/dubbo-common/src/main/java/org/apache/dubbo/common/ServiceMetada.java new file mode 100644 index 0000000000..eeaddc8d3d --- /dev/null +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/ServiceMetada.java @@ -0,0 +1,62 @@ +/* + * 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; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * data related to service level such as name, version, classloader of business service, + * security info, etc. Also with a AttributeMap for extension. + */ +public class ServiceMetada { + + private final String serviceKey; + private final Class<?> serviceType; + + /* will be transferred to remote side */ + private final Map<String, Object> attachments = new ConcurrentHashMap<String, Object>(); + /* used locally*/ + private final Map<String, Object> attributeMap = new ConcurrentHashMap<String, Object>(); + + public ServiceMetada(String serviceKey, Class<?> serviceType) { + this.serviceKey = serviceKey; + this.serviceType = serviceType; + } + + public String getServiceKey() { + return serviceKey; + } + + public Map<String, Object> getAttachments() { + return attachments; + } + + public Map<String, Object> getAttributeMap() { + return attributeMap; + } + + public void addAttribute(String key, Object value) { + this.attributeMap.put(key, value); + } + + public void addAttachment(String key, Object value) { + this.attributeMap.put(key, value); + } + + +} 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 new file mode 100644 index 0000000000..2e3306b4fa --- /dev/null +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/AddressListener.java @@ -0,0 +1,34 @@ +/* + * 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.ServiceMetada; +import org.apache.dubbo.common.URL; + +import java.util.List; + +public interface AddressListener { + + /** + * processing when receiving the address list + * + * @param serviceMetadata + * @param addresses + */ + void notify(ServiceMetada serviceMetadata, List<URL> addresses); + +} \ No newline at end of file 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 527f6b6454..d00b06d753 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 @@ -17,6 +17,7 @@ package org.apache.dubbo.registry.integration; import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.ServiceMetada; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.Version; import org.apache.dubbo.common.extension.ExtensionLoader; @@ -27,6 +28,7 @@ import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.configcenter.ConfigChangeEvent; import org.apache.dubbo.configcenter.DynamicConfiguration; +import org.apache.dubbo.registry.AddressListener; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.Registry; import org.apache.dubbo.rpc.Invocation; @@ -89,6 +91,7 @@ private final Map<String, String> queryMap; // Initialization at construction time, assertion not null private final URL directoryUrl; // Initialization at construction time, assertion not null, and always assign non null value private final String[] serviceMethods; + private final ServiceMetada serviceMetada; private final boolean multiGroup; private Protocol protocol; // Initialization at the time of injection, the assertion is not null private Registry registry; // Initialization at the time of injection, the assertion is not null @@ -135,6 +138,8 @@ public RegistryDirectory(Class<T> serviceType, URL url) { this.multiGroup = group != null && ("*".equals(group) || group.contains(",")); String methods = queryMap.get(Constants.METHODS_KEY); this.serviceMethods = methods == null ? null : Constants.COMMA_SPLIT_PATTERN.split(methods); + + this.serviceMetada = new ServiceMetada(serviceKey, serviceType); } /** @@ -241,6 +246,14 @@ public void destroy() { @Override public synchronized void notify(List<URL> urls) { + ExtensionLoader<AddressListener> addressListenerExtensionLoader = ExtensionLoader.getExtensionLoader(AddressListener.class); + Set<String> surpportedListeners = addressListenerExtensionLoader.getSupportedExtensions(); + if (surpportedListeners != null) { + for (String addressListenerName : surpportedListeners) { + addressListenerExtensionLoader.getExtension(addressListenerName).notify(this.serviceMetada, urls); + } + } + List<URL> categoryUrls = urls.stream() .filter(this::isValidCategory) .filter(this::isNotCompatibleFor26x)
With regards, Apache Git Services
