qqu0127 commented on code in PR #2460:
URL: https://github.com/apache/helix/pull/2460#discussion_r1180816751
##########
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/util/ZkPathRecursiveWatcherTrie.java:
##########
@@ -139,17 +139,88 @@ public void addRecursiveListener(final String path,
RecursivePersistListener lis
if (path.isEmpty()) {
throw new IllegalArgumentException("Empty path: " + path);
}
- final List<String> pathComponents = split(path);
+ final List<String> pathComponents = split(path);
- synchronized(this) {
+ synchronized (this) {
TrieNode parent = _rootNode;
for (final String part : pathComponents) {
- parent = parent.getChildren().computeIfAbsent(part, (p)-> new
TrieNode(part) );
+ parent = parent.getChildren().computeIfAbsent(part, (p) -> new
TrieNode(part));
Review Comment:
nit: the lambda can be simplified by `TrieNode::new`
##########
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/util/ZkPathRecursiveWatcherTrie.java:
##########
@@ -1,5 +1,17 @@
package org.apache.helix.zookeeper.zkclient.util;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.apache.helix.zookeeper.zkclient.RecursivePersistListener;
+
Review Comment:
Acidental change?
##########
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/util/ZkPathRecursiveWatcherTrie.java:
##########
@@ -139,17 +139,88 @@ public void addRecursiveListener(final String path,
RecursivePersistListener lis
if (path.isEmpty()) {
throw new IllegalArgumentException("Empty path: " + path);
}
- final List<String> pathComponents = split(path);
+ final List<String> pathComponents = split(path);
- synchronized(this) {
+ synchronized (this) {
TrieNode parent = _rootNode;
for (final String part : pathComponents) {
- parent = parent.getChildren().computeIfAbsent(part, (p)-> new
TrieNode(part) );
+ parent = parent.getChildren().computeIfAbsent(part, (p) -> new
TrieNode(part));
}
parent._recursiveListeners.add(listener);
}
}
+ public Set<RecursivePersistListener> getAllRecursiveListeners(String path) {
+ Objects.requireNonNull(path, "Path cannot be null");
+
+ final List<String> pathComponents = split(path);
+ Set<RecursivePersistListener> result = new HashSet<>();
+ synchronized (this) {
+ TrieNode cur = _rootNode;
+ for (final String element : pathComponents) {
+ cur = cur.getChild(element);
+ if (cur == null) {
+ break;
+ }
+ result.addAll(cur.getRecursiveListeners());
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Removing a RecursivePersistWatcherListener on a path.
+ *
+ * Delete a path from the nearest trie node to current node if this is the
only listener and there
+ * is no child on the trie node.
+ *
+ * @param path the of the lister registered
+ * @param listener the RecursivePersistListener to be removed
+ */
+ public void removeRecursiveListener(final String path,
RecursivePersistListener listener) {
+ Objects.requireNonNull(path, "Path cannot be null");
+
+ if (path.length() == 0) {
+ throw new IllegalArgumentException("Invalid path: " + path);
Review Comment:
Let's just say empty path
##########
zookeeper-api/src/main/java/org/apache/helix/zookeeper/zkclient/util/ZkPathRecursiveWatcherTrie.java:
##########
@@ -139,17 +139,88 @@ public void addRecursiveListener(final String path,
RecursivePersistListener lis
if (path.isEmpty()) {
throw new IllegalArgumentException("Empty path: " + path);
}
- final List<String> pathComponents = split(path);
+ final List<String> pathComponents = split(path);
- synchronized(this) {
+ synchronized (this) {
TrieNode parent = _rootNode;
for (final String part : pathComponents) {
- parent = parent.getChildren().computeIfAbsent(part, (p)-> new
TrieNode(part) );
+ parent = parent.getChildren().computeIfAbsent(part, (p) -> new
TrieNode(part));
}
parent._recursiveListeners.add(listener);
}
}
+ public Set<RecursivePersistListener> getAllRecursiveListeners(String path) {
+ Objects.requireNonNull(path, "Path cannot be null");
+
+ final List<String> pathComponents = split(path);
+ Set<RecursivePersistListener> result = new HashSet<>();
+ synchronized (this) {
+ TrieNode cur = _rootNode;
+ for (final String element : pathComponents) {
+ cur = cur.getChild(element);
+ if (cur == null) {
+ break;
+ }
+ result.addAll(cur.getRecursiveListeners());
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Removing a RecursivePersistWatcherListener on a path.
+ *
+ * Delete a path from the nearest trie node to current node if this is the
only listener and there
+ * is no child on the trie node.
+ *
+ * @param path the of the lister registered
+ * @param listener the RecursivePersistListener to be removed
+ */
+ public void removeRecursiveListener(final String path,
RecursivePersistListener listener) {
+ Objects.requireNonNull(path, "Path cannot be null");
+
+ if (path.length() == 0) {
Review Comment:
prefer `path.isEmpty()`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]