Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor ServiceInstancesChangedListener equals and hashcode method #12547

Merged
merged 5 commits into from Jul 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -65,8 +65,6 @@
import static org.apache.dubbo.metadata.RevisionResolver.EMPTY_REVISION;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.getExportedServicesRevision;

;

/**
* TODO, refactor to move revision-metadata mapping to ServiceDiscovery. Instances should have already been mapped with metadata when reached here.
* <p>
Expand Down Expand Up @@ -209,11 +207,7 @@ private synchronized void doOnEvent(ServiceInstancesChangedEvent event) {

Map<Integer, Map<Set<String>, Object>> portToRevisions = protocolRevisionsToUrls.computeIfAbsent(serviceInfo.getProtocol(), k -> new HashMap<>());
Map<Set<String>, Object> revisionsToUrls = portToRevisions.computeIfAbsent(serviceInfo.getPort(), k -> new HashMap<>());
Object urls = revisionsToUrls.get(revisions);
if (urls == null) {
urls = getServiceUrlsCache(revisionToInstances, revisions, serviceInfo.getProtocol(), serviceInfo.getPort());
revisionsToUrls.put(revisions, urls);
}
Object urls = revisionsToUrls.computeIfAbsent(revisions, k -> getServiceUrlsCache(revisionToInstances, revisions, serviceInfo.getProtocol(), serviceInfo.getPort()));

List<ProtocolServiceKeyWithUrls> list = newServiceUrls.computeIfAbsent(serviceInfo.getPath(), k -> new LinkedList<>());
list.add(new ProtocolServiceKeyWithUrls(serviceInfo.getProtocolServiceKey(), (List<URL>) urls));
Expand Down Expand Up @@ -255,7 +249,7 @@ public synchronized void removeListener(String serviceKey, NotifyListener notify
notifyListeners.removeIf(listener -> listener.getNotifyListener().equals(notifyListener));

// ServiceKey has no listener, remove set
if (notifyListeners.size() == 0) {
if (notifyListeners.isEmpty()) {
this.listeners.remove(serviceKey);
}
}
Expand Down Expand Up @@ -478,7 +472,7 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hash(getClass(), getServiceNames(), listeners);
return Objects.hash(getClass(), getServiceNames());
}

protected class AddressRefreshRetryTask implements Runnable {
Expand Down