Randgalt commented on a change in pull request #1106: ZOOKEEPER-1416 - 
Persistent, recursive watchers
URL: https://github.com/apache/zookeeper/pull/1106#discussion_r341853788
 
 

 ##########
 File path: zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeper.java
 ##########
 @@ -3142,74 +3148,53 @@ public void removeAllWatches(String path, WatcherType 
watcherType, boolean local
     }
 
     /**
-     * <p>
-     * Set a watcher on the given path that: a) does not get removed when 
triggered (i.e. it stays active
-     * until it is removed); b) optionally applies not only to the registered 
path but all child paths recursively. This watcher
-     * is triggered for both data and child events. To remove the watcher, use
-     * <tt>removeWatches()</tt> with <tt>WatcherType.Any</tt>
-     * </p>
-     *
-     * <p>
-     * If <tt>recursive</tt> is <tt>false</tt>, the watcher behaves as if you 
placed an exists() watch and
-     * a getData() watch on the ZNode at the given path.
-     * </p>
-     *
-     * <p>
-     * If <tt>recursive</tt> is <tt>true</tt>, the watcher behaves as if you 
placed an exists() watch and
-     * a getData() watch on the ZNode at the given path <strong>and</strong> 
any ZNodes that are children
-     * of the given path including children added later.
-     * </p>
-     *
-     * <p>
-     * NOTE: when there are active recursive watches there is a small 
performance decrease as all segments
-     * of ZNode paths must be checked for watch triggering.
-     * </p>
+     * Add a watch to the given znode using the given mode. Note: not all
+     * watch types can be set with this method. Only the modes available
+     * in {@link AddWatchMode} can be set with this method.
      *
-     * @param basePath the top path that the watcher applies to
+     * @param basePath the path that the watcher applies to
      * @param watcher the watcher
-     * @param recursive if true applies not only to the registered path but 
all child paths recursively including
-     *                  any child nodes added in the future
+     * @param mode type of watcher to add
      * @throws InterruptedException If the server transaction is interrupted.
      * @throws KeeperException If the server signals an error with a non-zero
      *  error code.
      */
-    public void addPersistentWatch(String basePath, Watcher watcher, boolean 
recursive)
+    public void addWatch(String basePath, Watcher watcher, AddWatchMode mode)
             throws KeeperException, InterruptedException {
         PathUtils.validatePath(basePath);
         String serverPath = prependChroot(basePath);
 
         RequestHeader h = new RequestHeader();
-        h.setType(ZooDefs.OpCode.addPersistentWatch);
-        AddPersistentWatcherRequest request = new 
AddPersistentWatcherRequest(serverPath, recursive);
+        h.setType(ZooDefs.OpCode.addWatch);
+        AddWatchRequest request = new AddWatchRequest(serverPath, 
mode.getMode());
         ReplyHeader r = cnxn.submitRequest(h, request, new ErrorResponse(),
-                new PersistentWatchRegistration(watcher, basePath, recursive));
+                new AddWatchRegistration(watcher, basePath, mode));
         if (r.getErr() != 0) {
             throw KeeperException.create(KeeperException.Code.get(r.getErr()),
                     basePath);
         }
     }
 
     /**
-     * Async version of {@link #addPersistentWatch(String, Watcher, boolean)} 
(see it for details)
+     * Async version of {@link #addWatch(String, Watcher, AddWatchMode)} (see 
it for details)
      *
-     * @param basePath the top path that the watcher applies to
+     * @param basePath the path that the watcher applies to
      * @param watcher the watcher
-     * @param recursive if true applies not only to the registered path but 
all child paths recursively including
-     *                  any child nodes added in the future
+     * @param mode type of watcher to add
      * @param cb a handler for the callback
      * @param ctx context to be provided to the callback
      * @throws IllegalArgumentException if an invalid path is specified
      */
-    public void addPersistentWatch(String basePath, Watcher watcher, boolean 
recursive,
-                                   VoidCallback cb, Object ctx) {
+    public void addWatch(String basePath, Watcher watcher, AddWatchMode mode,
+                         VoidCallback cb, Object ctx) {
         PathUtils.validatePath(basePath);
         String serverPath = prependChroot(basePath);
 
         RequestHeader h = new RequestHeader();
-        h.setType(ZooDefs.OpCode.addPersistentWatch);
-        AddPersistentWatcherRequest request = new 
AddPersistentWatcherRequest(serverPath, recursive);
+        h.setType(ZooDefs.OpCode.addWatch);
+        AddWatchRequest request = new AddWatchRequest(serverPath, 
mode.getMode());
         cnxn.queuePacket(h, new ReplyHeader(), request, new ErrorResponse(), 
cb,
-                basePath, serverPath, ctx, new 
PersistentWatchRegistration(watcher, basePath, recursive));
+                basePath, serverPath, ctx, new AddWatchRegistration(watcher, 
basePath, mode));
 
 Review comment:
   Anyone else agree? I don't remember why I did it this way TBH.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to