kezhuw commented on code in PR #1260:
URL: https://github.com/apache/curator/pull/1260#discussion_r2030395398


##########
curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentTtlNode.java:
##########
@@ -159,44 +160,45 @@ public PersistentTtlNode(
         this.client = Objects.requireNonNull(client, "client cannot be null");
         this.ttlMs = ttlMs;
         this.touchScheduleFactor = touchScheduleFactor;
-        node = new PersistentNode(client, CreateMode.CONTAINER, false, path, 
initData, useParentCreation) {
-            @Override
-            protected void deleteNode() {
-                // NOP
-            }
-        };
+        node =
+                new PersistentNode(
+                        client, CreateMode.PERSISTENT_WITH_TTL, false, path, 
initData, ttlMs, useParentCreation) {
+                    @Override
+                    protected void deleteNode() {
+                        // NOP
+                    }
+                };
         this.executorService = Objects.requireNonNull(executorService, 
"executorService cannot be null");
         childPath = ZKPaths.makePath(Objects.requireNonNull(path, "path cannot 
be null"), childNodeName);
     }
 
+    @VisibleForTesting
+    void touch() {
+        try {
+            try {
+                client.setData().forPath(childPath);
+            } catch (KeeperException.NoNodeException e) {
+                client.create()
+                        .orSetData()
+                        .withTtl(ttlMs)
+                        .withMode(CreateMode.PERSISTENT_WITH_TTL)
+                        .forPath(childPath);
+            }
+        } catch (KeeperException.NoNodeException ignore) {
+            // ignore
+        } catch (Exception e) {
+            if (!ThreadUtils.checkInterrupted(e)) {
+                log.debug("Could not touch child node", e);
+            }
+        }
+    }
+
     /**
      * You must call start() to initiate the persistent ttl node
      */
     public void start() {
         node.start();
-
-        Runnable touchTask = new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    try {
-                        client.setData().forPath(childPath);
-                    } catch (KeeperException.NoNodeException e) {
-                        client.create()
-                                .orSetData()
-                                .withTtl(ttlMs)
-                                .withMode(CreateMode.PERSISTENT_WITH_TTL)
-                                .forPath(childPath);
-                    }
-                } catch (KeeperException.NoNodeException ignore) {
-                    // ignore
-                } catch (Exception e) {
-                    if (!ThreadUtils.checkInterrupted(e)) {
-                        log.debug("Could not touch child node", e);
-                    }
-                }
-            }
-        };
+        final Runnable touchTask = () -> touch();
         Future<?> future = executorService.scheduleAtFixedRate(
                 touchTask, ttlMs / touchScheduleFactor, ttlMs / 
touchScheduleFactor, TimeUnit.MILLISECONDS);

Review Comment:
   ```suggestion
           Future<?> future = executorService.scheduleAtFixedRate(
                   this::touch, ttlMs / touchScheduleFactor, ttlMs / 
touchScheduleFactor, TimeUnit.MILLISECONDS);
   ```



-- 
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: commits-unsubscr...@curator.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to