Skip to content

Commit

Permalink
Merge pull request #2044 from nkorange/feature_stop_update_task_after…
Browse files Browse the repository at this point in the history
…_unsbscribe

fix #1858
  • Loading branch information
nkorange authored Nov 11, 2019
2 parents b9c3b54 + d034412 commit b3781ad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public void removeListener(String serviceName, String clusters, EventListener li
}
}

public boolean isSubscribed(String serviceName, String clusters) {
return observerMap.containsKey(ServiceInfo.getKey(serviceName, clusters));
}

public List<ServiceInfo> getSubscribeServices() {
List<ServiceInfo> serviceInfos = new ArrayList<ServiceInfo>();
for (String key : observerMap.keySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ public ServiceInfo getServiceInfo(final String serviceName, final String cluster
return serviceInfoMap.get(serviceObj.getKey());
}



public void scheduleUpdateIfAbsent(String serviceName, String clusters) {
if (futureMap.get(ServiceInfo.getKey(serviceName, clusters)) != null) {
return;
Expand Down Expand Up @@ -330,9 +332,18 @@ public void run() {
refreshOnly(serviceName, clusters);
}

lastRefTime = serviceObj.getLastRefTime();

if (!eventDispatcher.isSubscribed(serviceName, clusters) &&
!futureMap.containsKey(ServiceInfo.getKey(serviceName, clusters))) {
// abort the update task:
NAMING_LOGGER.info("update task is stopped, service:" + serviceName + ", clusters:" + clusters);
return;
}

executor.schedule(this, serviceObj.getCacheMillis(), TimeUnit.MILLISECONDS);

lastRefTime = serviceObj.getLastRefTime();

} catch (Throwable e) {
NAMING_LOGGER.warn("[NA] failed to update serviceName: " + serviceName, e);
}
Expand Down

0 comments on commit b3781ad

Please sign in to comment.