提交 5609ef29 编写于 作者: P peng-yongsheng

fixed #469

because of remove the collection item action inside of collection for each action.
上级 25036048
package org.skywalking.apm.collector.cluster.zookeeper; package org.skywalking.apm.collector.cluster.zookeeper;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.HashSet;
import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher; import org.apache.zookeeper.Watcher;
...@@ -42,14 +42,14 @@ public class ClusterZKDataMonitor implements DataMonitor, Watcher { ...@@ -42,14 +42,14 @@ public class ClusterZKDataMonitor implements DataMonitor, Watcher {
registrations = new LinkedHashMap<>(); 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()); logger.info("changed path {}, event type: {}", event.getPath(), event.getType().name());
if (listeners.containsKey(event.getPath())) { if (listeners.containsKey(event.getPath())) {
List<String> paths; List<String> paths;
try { try {
paths = client.getChildren(event.getPath(), true); paths = client.getChildren(event.getPath(), true);
ClusterDataListener listener = listeners.get(event.getPath()); ClusterDataListener listener = listeners.get(event.getPath());
Set<String> remoteNodes = new HashSet<String>(); Set<String> remoteNodes = new HashSet<>();
Set<String> notifiedNodes = listener.getAddresses(); Set<String> notifiedNodes = listener.getAddresses();
if (CollectionUtils.isNotEmpty(paths)) { if (CollectionUtils.isNotEmpty(paths)) {
for (String serverPath : paths) { for (String serverPath : paths) {
...@@ -65,9 +65,12 @@ public class ClusterZKDataMonitor implements DataMonitor, Watcher { ...@@ -65,9 +65,12 @@ public class ClusterZKDataMonitor implements DataMonitor, Watcher {
} }
} }
} }
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)) { 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.removeAddress(address);
listener.serverQuitNotify(address); listener.serverQuitNotify(address);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册