Skip to content

Commit

Permalink
Fixed failure to read provider metadata in dubbo-3.1.x (#1086)
Browse files Browse the repository at this point in the history
  • Loading branch information
wuwen5 authored Aug 25, 2023
1 parent 77683ba commit 9be25ab
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

package org.apache.dubbo.admin.registry.mapping;

import org.apache.dubbo.common.ProtocolServiceKey;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.registry.client.ServiceDiscovery;
import org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -32,7 +34,7 @@ public class AdminServiceInstancesChangedListener extends ServiceInstancesChange

private AddressChangeListener addressChangeListener;

private Map<String, List<ServiceInstancesChangedListener.ProtocolServiceKeyWithUrls>> oldServiceUrls;
private Map<ProtocolServiceKey, List<ServiceInstancesChangedListener.ProtocolServiceKeyWithUrls>> oldServiceUrls;

public AdminServiceInstancesChangedListener(Set<String> serviceNames, ServiceDiscovery serviceDiscovery, AddressChangeListener addressChangeListener) {
super(serviceNames, serviceDiscovery);
Expand All @@ -41,12 +43,18 @@ public AdminServiceInstancesChangedListener(Set<String> serviceNames, ServiceDis
}

protected void notifyAddressChanged() {
Map<ProtocolServiceKey, List<ProtocolServiceKeyWithUrls>> protocolServiceUrls = serviceUrls.values().stream()
.flatMap(Collection::stream)
.collect(Collectors.groupingBy(ProtocolServiceKeyWithUrls::getProtocolServiceKey));

oldServiceUrls.keySet().stream()
.filter(protocolServiceKey -> !serviceUrls.containsKey(protocolServiceKey))
.forEach(protocolServiceKey -> addressChangeListener.notifyAddressChanged(protocolServiceKey, new ArrayList<>()));
serviceUrls.forEach((protocolServiceKey, urls) -> addressChangeListener.notifyAddressChanged(protocolServiceKey, extractUrls(urls)));
.filter(protocolServiceKey -> !protocolServiceUrls.containsKey(protocolServiceKey))
.forEach(protocolServiceKey -> addressChangeListener.notifyAddressChanged(protocolServiceKey.toString(), new ArrayList<>()));

protocolServiceUrls
.forEach((protocolServiceKey, urls) -> addressChangeListener.notifyAddressChanged(protocolServiceKey.toString(), extractUrls(urls)));

oldServiceUrls = serviceUrls;
oldServiceUrls = protocolServiceUrls;
}

private List<URL> extractUrls(List<ServiceInstancesChangedListener.ProtocolServiceKeyWithUrls> keyUrls) {
Expand Down

0 comments on commit 9be25ab

Please sign in to comment.