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

Fix #1591 #1592

Merged
merged 2 commits into from
Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public Thread newThread(Runnable r) {
private Map<String, String> syncChecksumTasks = new ConcurrentHashMap<>(16);

@PostConstruct
public void init() throws Exception {
public void init() {
GlobalExecutor.submit(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -154,6 +154,7 @@ public void put(String key, Record value) throws NacosException {
@Override
public void remove(String key) throws NacosException {
onRemove(key);
listeners.remove(key);
}

@Override
Expand Down Expand Up @@ -186,8 +187,6 @@ public void onRemove(String key) {
return;
}

listeners.remove(key);

notifier.addTask(key, ApplyAction.DELETE);
}

Expand Down Expand Up @@ -322,6 +321,11 @@ public void listen(String key, RecordListener listener) throws NacosException {
if (!listeners.containsKey(key)) {
listeners.put(key, new CopyOnWriteArrayList<>());
}

if (listeners.get(key).contains(listener)) {
return;
}

listeners.get(key).add(listener);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ public void onChange(String key, Service service) throws Exception {

if (oldDom != null) {
oldDom.update(service);
// re-listen to handle the situation when the underlying listener is removed:
consistencyService.listen(KeyBuilder.buildInstanceListKey(service.getNamespaceId(), service.getName(), true), oldDom);
consistencyService.listen(KeyBuilder.buildInstanceListKey(service.getNamespaceId(), service.getName(), false), oldDom);
} else {
putService(service);
service.init();
Expand Down