curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [3/3] git commit: use getData() instead of exists() to avoid leaving unneeded watchers which is a type of resource leak. However, this might have performance affects. Therefore, added system proprety "curator-path-children-cache-use-exists" to use the ol
Date Fri, 23 May 2014 12:49:14 GMT
use getData() instead of exists() to avoid leaving unneeded watchers which is a type of resource
leak. However, this might have
performance affects. Therefore, added system proprety "curator-path-children-cache-use-exists"
to use the old behavior. i.e.
add -Dcurator-path-children-cache-use-exists=true or call System.setProperty("curator-path-children-cache-use-exists",
"true") to
use the old behavior of calling exists() instead.


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/0dcf8335
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/0dcf8335
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/0dcf8335

Branch: refs/heads/CURATOR-107
Commit: 0dcf8335745003c578dbaf09b3be658b89b4a045
Parents: 91d6503
Author: randgalt <randgalt@apache.org>
Authored: Fri May 23 07:48:11 2014 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Fri May 23 07:48:11 2014 -0500

----------------------------------------------------------------------
 .../recipes/cache/PathChildrenCache.java        | 30 ++++++++------------
 1 file changed, 12 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/0dcf8335/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
index 855d060..dc23e04 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java
@@ -89,6 +89,8 @@ public class PathChildrenCache implements Closeable
 
     private static final ChildData NULL_CHILD_DATA = new ChildData(null, null, null);
 
+    private static final boolean USE_EXISTS = Boolean.getBoolean("curator-path-children-cache-use-exists");
+
     private final Watcher childrenWatcher = new Watcher()
     {
         @Override
@@ -508,39 +510,31 @@ public class PathChildrenCache implements Closeable
 
     void getDataAndStat(final String fullPath) throws Exception
     {
-        BackgroundCallback existsCallback = new BackgroundCallback()
+        BackgroundCallback callback = new BackgroundCallback()
         {
             @Override
             public void processResult(CuratorFramework client, CuratorEvent event) throws
Exception
             {
-                applyNewData(fullPath, event.getResultCode(), event.getStat(), null);
+                applyNewData(fullPath, event.getResultCode(), event.getStat(), cacheData
? event.getData() : null);
             }
         };
 
-        BackgroundCallback getDataCallback = new BackgroundCallback()
+        if ( USE_EXISTS && !cacheData )
         {
-            @Override
-            public void processResult(CuratorFramework client, CuratorEvent event) throws
Exception
-            {
-                applyNewData(fullPath, event.getResultCode(), event.getStat(), event.getData());
-            }
-        };
-
-        if ( cacheData )
+            client.checkExists().usingWatcher(dataWatcher).inBackground(callback).forPath(fullPath);
+        }
+        else
         {
-            if ( dataIsCompressed )
+            // always use getData() instead of exists() to avoid leaving unneeded watchers
which is a type of resource leak
+            if ( dataIsCompressed && cacheData )
             {
-                client.getData().decompressed().usingWatcher(dataWatcher).inBackground(getDataCallback).forPath(fullPath);
+                client.getData().decompressed().usingWatcher(dataWatcher).inBackground(callback).forPath(fullPath);
             }
             else
             {
-                client.getData().usingWatcher(dataWatcher).inBackground(getDataCallback).forPath(fullPath);
+                client.getData().usingWatcher(dataWatcher).inBackground(callback).forPath(fullPath);
             }
         }
-        else
-        {
-            client.checkExists().usingWatcher(dataWatcher).inBackground(existsCallback).forPath(fullPath);
-        }
     }
 
     /**


Mime
View raw message