Skip to content

Commit

Permalink
fixed #469
Browse files Browse the repository at this point in the history
because of remove the collection item action inside of collection for each action.
  • Loading branch information
peng-yongsheng committed Sep 27, 2017
1 parent 2503604 commit 5609ef2
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.skywalking.apm.collector.cluster.zookeeper;

import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.HashSet;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
Expand Down Expand Up @@ -42,14 +42,14 @@ public ClusterZKDataMonitor() {
registrations = new LinkedHashMap<>();
}

@Override public void process(WatchedEvent event) {
@Override public synchronized void process(WatchedEvent event) {
logger.info("changed path {}, event type: {}", event.getPath(), event.getType().name());
if (listeners.containsKey(event.getPath())) {
List<String> paths;
try {
paths = client.getChildren(event.getPath(), true);
ClusterDataListener listener = listeners.get(event.getPath());
Set<String> remoteNodes = new HashSet<String>();
Set<String> remoteNodes = new HashSet<>();
Set<String> notifiedNodes = listener.getAddresses();
if (CollectionUtils.isNotEmpty(paths)) {
for (String serverPath : paths) {
Expand All @@ -65,9 +65,12 @@ public ClusterZKDataMonitor() {
}
}
}
for (String address : notifiedNodes) {

String[] notifiedNodeArray = notifiedNodes.toArray(new String[notifiedNodes.size()]);
for (int i = notifiedNodeArray.length - 1; i >= 0; i--) {
String address = notifiedNodeArray[i];
if (remoteNodes.isEmpty() || !remoteNodes.contains(address)) {
logger.info("path children has been changed, path and data: {}", event.getPath() + "/" + address);
logger.info("path children has been remove, path and data: {}", event.getPath() + "/" + address);
listener.removeAddress(address);
listener.serverQuitNotify(address);
}
Expand Down

0 comments on commit 5609ef2

Please sign in to comment.