You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ca...@apache.org on 2018/12/10 03:46:32 UTC
[1/8] curator git commit: added support for zkwatches
Repository: curator
Updated Branches:
refs/heads/CURATOR-477 [created] 2d4aa5778
added support for zkwatches
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/d4a0d954
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/d4a0d954
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/d4a0d954
Branch: refs/heads/CURATOR-477
Commit: d4a0d95488345bfb0983553bfbfbc40643ac031b
Parents: 8950151
Author: Rama <ra...@salesforce.com>
Authored: Mon Aug 20 12:16:12 2018 +0530
Committer: Rama <ra...@salesforce.com>
Committed: Mon Aug 20 12:16:12 2018 +0530
----------------------------------------------------------------------
.../framework/recipes/cache/TreeCache.java | 41 +++++++++++++++++---
.../framework/recipes/cache/TestTreeCache.java | 25 ++++++++++++
2 files changed, 60 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/d4a0d954/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
index 7f8aad7..7bcc8d1 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
@@ -73,6 +73,7 @@ public class TreeCache implements Closeable
{
private static final Logger LOG = LoggerFactory.getLogger(TreeCache.class);
private final boolean createParentNodes;
+ private final boolean createZkWatches;
private final TreeCacheSelector selector;
public static final class Builder
@@ -84,6 +85,7 @@ public class TreeCache implements Closeable
private ExecutorService executorService = null;
private int maxDepth = Integer.MAX_VALUE;
private boolean createParentNodes = false;
+ private boolean createZkWatches = true;
private TreeCacheSelector selector = new DefaultTreeCacheSelector();
private Builder(CuratorFramework client, String path)
@@ -102,7 +104,7 @@ public class TreeCache implements Closeable
{
executor = Executors.newSingleThreadExecutor(defaultThreadFactory);
}
- return new TreeCache(client, path, cacheData, dataIsCompressed, maxDepth, executor, createParentNodes, selector);
+ return new TreeCache(client, path, cacheData, dataIsCompressed, maxDepth, executor, createParentNodes, createZkWatches, selector);
}
/**
@@ -166,6 +168,18 @@ public class TreeCache implements Closeable
}
/**
+ * By default, TreeCache creates {@link org.apache.zookeeper.ZooKeeper} watches for every created path.
+ * Change this behavior with this method.
+ * @param createZkWatches true to create watches
+ * @return this for chaining
+ */
+ public Builder setCreateZkWatches(boolean createZkWatches)
+ {
+ this.createZkWatches = createZkWatches;
+ return this;
+ }
+
+ /**
* By default, {@link DefaultTreeCacheSelector} is used. Change the selector here.
*
* @param selector new selector
@@ -253,7 +267,11 @@ public class TreeCache implements Closeable
{
if ( treeState.get() == TreeState.STARTED )
{
- client.getChildren().usingWatcher(this).inBackground(this).forPath(path);
+ if (createZkWatches) {
+ client.getChildren().usingWatcher(this).inBackground(this).forPath(path);
+ } else {
+ client.getChildren().inBackground(this).forPath(path);
+ }
}
}
@@ -263,11 +281,20 @@ public class TreeCache implements Closeable
{
if ( dataIsCompressed )
{
- client.getData().decompressed().usingWatcher(this).inBackground(this).forPath(path);
+ if (createZkWatches) {
+ client.getData().decompressed().usingWatcher(this).inBackground(this).forPath(path);
+ } else {
+ client.getData().decompressed().inBackground(this).forPath(path);
+ }
}
else
{
- client.getData().usingWatcher(this).inBackground(this).forPath(path);
+ if (createZkWatches) {
+ client.getData().usingWatcher(this).inBackground(this).forPath(path);
+ } else {
+ client.getData().inBackground(this).forPath(path);
+
+ }
}
}
}
@@ -535,7 +562,7 @@ public class TreeCache implements Closeable
*/
public TreeCache(CuratorFramework client, String path)
{
- this(client, path, true, false, Integer.MAX_VALUE, Executors.newSingleThreadExecutor(defaultThreadFactory), false, new DefaultTreeCacheSelector());
+ this(client, path, true, false, Integer.MAX_VALUE, Executors.newSingleThreadExecutor(defaultThreadFactory), false, true, new DefaultTreeCacheSelector());
}
/**
@@ -545,9 +572,10 @@ public class TreeCache implements Closeable
* @param dataIsCompressed if true, data in the path is compressed
* @param executorService Closeable ExecutorService to use for the TreeCache's background thread
* @param createParentNodes true to create parent nodes as containers
+ * @param createZkWatches true to create Zookeeper watches
* @param selector the selector to use
*/
- TreeCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, int maxDepth, final ExecutorService executorService, boolean createParentNodes, TreeCacheSelector selector)
+ TreeCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, int maxDepth, final ExecutorService executorService, boolean createParentNodes, boolean createZkWatches, TreeCacheSelector selector)
{
this.createParentNodes = createParentNodes;
this.selector = Preconditions.checkNotNull(selector, "selector cannot be null");
@@ -557,6 +585,7 @@ public class TreeCache implements Closeable
this.cacheData = cacheData;
this.dataIsCompressed = dataIsCompressed;
this.maxDepth = maxDepth;
+ this.createZkWatches = createZkWatches;
this.executorService = Preconditions.checkNotNull(executorService, "executorService cannot be null");
}
http://git-wip-us.apache.org/repos/asf/curator/blob/d4a0d954/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
index ebaf43e..ae15314 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
@@ -468,6 +468,31 @@ public class TestTreeCache extends BaseTestTreeCache
}
@Test
+ public void testBasicsWithNoZkWatches() throws Exception
+ {
+ client.create().forPath("/test");
+ client.create().forPath("/test/one", "hey there".getBytes());
+
+
+ cache = buildWithListeners(TreeCache.newBuilder(client, "/test").setCreateZkWatches(false));
+
+ cache.start();
+ assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test");
+ assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test/one");
+
+ assertEvent(TreeCacheEvent.Type.INITIALIZED);
+ Assert.assertEquals(cache.getCurrentChildren("/test").keySet(), ImmutableSet.of("one"));
+ Assert.assertEquals(new String(cache.getCurrentData("/test/one").getData()), "hey there");
+ Assert.assertEquals(cache.getCurrentChildren("/test/one").keySet(), ImmutableSet.of());
+ Assert.assertNull(cache.getCurrentChildren("/test/o"));
+ Assert.assertNull(cache.getCurrentChildren("/test/onely"));
+ Assert.assertNull(cache.getCurrentChildren("/t"));
+ Assert.assertNull(cache.getCurrentChildren("/testing"));
+
+ assertNoMoreEvents();
+ }
+
+ @Test
public void testBasicsOnTwoCaches() throws Exception
{
TreeCache cache2 = newTreeCacheWithListeners(client, "/test");
[2/8] curator git commit: address review feedback
Posted by ca...@apache.org.
address review feedback
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/88df79b4
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/88df79b4
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/88df79b4
Branch: refs/heads/CURATOR-477
Commit: 88df79b474c252ddb97096c6e967daa38a02b545
Parents: d4a0d95
Author: Rama <ra...@salesforce.com>
Authored: Sun Sep 23 13:28:23 2018 +0530
Committer: Rama <ra...@salesforce.com>
Committed: Sun Sep 23 13:28:23 2018 +0530
----------------------------------------------------------------------
.../framework/recipes/cache/TreeCache.java | 90 +++++++++++---------
.../framework/recipes/cache/TestTreeCache.java | 2 +-
2 files changed, 51 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/88df79b4/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
index 7bcc8d1..7c68868 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
@@ -19,15 +19,35 @@
package org.apache.curator.framework.recipes.cache;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.curator.utils.PathUtils.validatePath;
+
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
+import java.io.Closeable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.WatcherRemoveCuratorFramework;
import org.apache.curator.framework.api.BackgroundCallback;
import org.apache.curator.framework.api.CuratorEvent;
+import org.apache.curator.framework.api.ErrorListenerPathable;
+import org.apache.curator.framework.api.GetDataBuilder;
+import org.apache.curator.framework.api.GetDataWatchBackgroundStatable;
import org.apache.curator.framework.api.UnhandledErrorListener;
import org.apache.curator.framework.listen.Listenable;
import org.apache.curator.framework.listen.ListenerContainer;
@@ -42,23 +62,6 @@ import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.Closeable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.concurrent.atomic.AtomicReference;
-import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.curator.utils.PathUtils.validatePath;
/**
* <p>A utility that attempts to keep all data from all children of a ZK path locally cached. This class
@@ -73,7 +76,7 @@ public class TreeCache implements Closeable
{
private static final Logger LOG = LoggerFactory.getLogger(TreeCache.class);
private final boolean createParentNodes;
- private final boolean createZkWatches;
+ private final boolean disableZkWatches;
private final TreeCacheSelector selector;
public static final class Builder
@@ -85,7 +88,7 @@ public class TreeCache implements Closeable
private ExecutorService executorService = null;
private int maxDepth = Integer.MAX_VALUE;
private boolean createParentNodes = false;
- private boolean createZkWatches = true;
+ private boolean disableZkWatches = false;
private TreeCacheSelector selector = new DefaultTreeCacheSelector();
private Builder(CuratorFramework client, String path)
@@ -104,7 +107,7 @@ public class TreeCache implements Closeable
{
executor = Executors.newSingleThreadExecutor(defaultThreadFactory);
}
- return new TreeCache(client, path, cacheData, dataIsCompressed, maxDepth, executor, createParentNodes, createZkWatches, selector);
+ return new TreeCache(client, path, cacheData, dataIsCompressed, maxDepth, executor, createParentNodes, disableZkWatches, selector);
}
/**
@@ -170,12 +173,12 @@ public class TreeCache implements Closeable
/**
* By default, TreeCache creates {@link org.apache.zookeeper.ZooKeeper} watches for every created path.
* Change this behavior with this method.
- * @param createZkWatches true to create watches
+ * @param disableZkWatches false to create watches
* @return this for chaining
*/
- public Builder setCreateZkWatches(boolean createZkWatches)
+ public Builder disableZkWatches(boolean disableZkWatches)
{
- this.createZkWatches = createZkWatches;
+ this.disableZkWatches = disableZkWatches;
return this;
}
@@ -267,10 +270,10 @@ public class TreeCache implements Closeable
{
if ( treeState.get() == TreeState.STARTED )
{
- if (createZkWatches) {
- client.getChildren().usingWatcher(this).inBackground(this).forPath(path);
- } else {
+ if (disableZkWatches) {
client.getChildren().inBackground(this).forPath(path);
+ } else {
+ client.getChildren().usingWatcher(this).inBackground(this).forPath(path);
}
}
}
@@ -281,24 +284,31 @@ public class TreeCache implements Closeable
{
if ( dataIsCompressed )
{
- if (createZkWatches) {
- client.getData().decompressed().usingWatcher(this).inBackground(this).forPath(path);
- } else {
- client.getData().decompressed().inBackground(this).forPath(path);
- }
+ maybeWatch(client.getData().decompressed()).forPath(path);
}
else
{
- if (createZkWatches) {
- client.getData().usingWatcher(this).inBackground(this).forPath(path);
- } else {
- client.getData().inBackground(this).forPath(path);
-
- }
+ maybeWatch(client.getData()).forPath(path);
}
}
}
+ private ErrorListenerPathable<byte[]> maybeWatch(GetDataWatchBackgroundStatable dataBuilder) {
+ if (disableZkWatches) {
+ return dataBuilder.inBackground(this);
+ } else {
+ return dataBuilder.usingWatcher(this).inBackground(this);
+ }
+ }
+
+ private ErrorListenerPathable<byte[]> maybeWatch(GetDataBuilder dataBuilder) {
+ if (disableZkWatches) {
+ return dataBuilder.inBackground(this);
+ } else {
+ return dataBuilder.usingWatcher(this).inBackground(this);
+ }
+ }
+
void wasReconnected() throws Exception
{
refresh();
@@ -572,10 +582,10 @@ public class TreeCache implements Closeable
* @param dataIsCompressed if true, data in the path is compressed
* @param executorService Closeable ExecutorService to use for the TreeCache's background thread
* @param createParentNodes true to create parent nodes as containers
- * @param createZkWatches true to create Zookeeper watches
+ * @param disableZkWatches false to create Zookeeper watches
* @param selector the selector to use
*/
- TreeCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, int maxDepth, final ExecutorService executorService, boolean createParentNodes, boolean createZkWatches, TreeCacheSelector selector)
+ TreeCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, int maxDepth, final ExecutorService executorService, boolean createParentNodes, boolean disableZkWatches, TreeCacheSelector selector)
{
this.createParentNodes = createParentNodes;
this.selector = Preconditions.checkNotNull(selector, "selector cannot be null");
@@ -585,7 +595,7 @@ public class TreeCache implements Closeable
this.cacheData = cacheData;
this.dataIsCompressed = dataIsCompressed;
this.maxDepth = maxDepth;
- this.createZkWatches = createZkWatches;
+ this.disableZkWatches = disableZkWatches;
this.executorService = Preconditions.checkNotNull(executorService, "executorService cannot be null");
}
http://git-wip-us.apache.org/repos/asf/curator/blob/88df79b4/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
index ae15314..762bdd8 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestTreeCache.java
@@ -474,7 +474,7 @@ public class TestTreeCache extends BaseTestTreeCache
client.create().forPath("/test/one", "hey there".getBytes());
- cache = buildWithListeners(TreeCache.newBuilder(client, "/test").setCreateZkWatches(false));
+ cache = buildWithListeners(TreeCache.newBuilder(client, "/test").disableZkWatches(true));
cache.start();
assertEvent(TreeCacheEvent.Type.NODE_ADDED, "/test");
[3/8] curator git commit: fix test case
Posted by ca...@apache.org.
fix test case
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/60e9be8f
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/60e9be8f
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/60e9be8f
Branch: refs/heads/CURATOR-477
Commit: 60e9be8fce41368f25931c998bb287b3750d41ba
Parents: 88df79b
Author: Rama <ra...@salesforce.com>
Authored: Mon Sep 24 09:56:48 2018 +0530
Committer: Rama <ra...@salesforce.com>
Committed: Mon Sep 24 09:56:48 2018 +0530
----------------------------------------------------------------------
.../org/apache/curator/framework/recipes/cache/TreeCache.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/60e9be8f/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
index 7c68868..70e0abd 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
@@ -173,7 +173,7 @@ public class TreeCache implements Closeable
/**
* By default, TreeCache creates {@link org.apache.zookeeper.ZooKeeper} watches for every created path.
* Change this behavior with this method.
- * @param disableZkWatches false to create watches
+ * @param disableZkWatches true to disable zk watches
* @return this for chaining
*/
public Builder disableZkWatches(boolean disableZkWatches)
@@ -572,7 +572,7 @@ public class TreeCache implements Closeable
*/
public TreeCache(CuratorFramework client, String path)
{
- this(client, path, true, false, Integer.MAX_VALUE, Executors.newSingleThreadExecutor(defaultThreadFactory), false, true, new DefaultTreeCacheSelector());
+ this(client, path, true, false, Integer.MAX_VALUE, Executors.newSingleThreadExecutor(defaultThreadFactory), false, false, new DefaultTreeCacheSelector());
}
/**
@@ -582,7 +582,7 @@ public class TreeCache implements Closeable
* @param dataIsCompressed if true, data in the path is compressed
* @param executorService Closeable ExecutorService to use for the TreeCache's background thread
* @param createParentNodes true to create parent nodes as containers
- * @param disableZkWatches false to create Zookeeper watches
+ * @param disableZkWatches true to disable Zookeeper watches
* @param selector the selector to use
*/
TreeCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, int maxDepth, final ExecutorService executorService, boolean createParentNodes, boolean disableZkWatches, TreeCacheSelector selector)
[8/8] curator git commit: Merge branch 'CURATOR-477' of
https://github.com/ramaraochavali/curator into CURATOR-477
Posted by ca...@apache.org.
Merge branch 'CURATOR-477' of https://github.com/ramaraochavali/curator into CURATOR-477
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/2d4aa577
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/2d4aa577
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/2d4aa577
Branch: refs/heads/CURATOR-477
Commit: 2d4aa5778aaca926e59e3fd3dcec6c46e4fbe1b4
Parents: 5b15f5f 7e9628e
Author: Cam McKenzie <ca...@apache.org>
Authored: Mon Dec 10 14:46:10 2018 +1100
Committer: Cam McKenzie <ca...@apache.org>
Committed: Mon Dec 10 14:46:10 2018 +1100
----------------------------------------------------------------------
.../framework/recipes/cache/TreeCache.java | 42 ++++++++++++++++----
.../framework/recipes/cache/TestTreeCache.java | 25 ++++++++++++
2 files changed, 60 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
[7/8] curator git commit: use maybeWatch
Posted by ca...@apache.org.
use maybeWatch
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/7e9628ee
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/7e9628ee
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/7e9628ee
Branch: refs/heads/CURATOR-477
Commit: 7e9628ee5ea90d7260ce04e0625d52a68a5d2789
Parents: b7c902a
Author: Rama <ra...@salesforce.com>
Authored: Tue Sep 25 17:18:05 2018 +0530
Committer: Rama <ra...@salesforce.com>
Committed: Tue Sep 25 17:18:05 2018 +0530
----------------------------------------------------------------------
.../org/apache/curator/framework/recipes/cache/TreeCache.java | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/7e9628ee/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
index e6119f5..f42c1d5 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
@@ -347,11 +347,7 @@ public class TreeCache implements Closeable
if ( parent == null )
{
// Root node; use an exist query to watch for existence.
- if (disableZkWatches) {
- client.checkExists().forPath(path);
- } else {
- client.checkExists().usingWatcher(this).inBackground(this).forPath(path);
- }
+ maybeWatch(client.checkExists()).forPath(path);
}
else
{
[5/8] curator git commit: reorder imports
Posted by ca...@apache.org.
reorder imports
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/7680e15c
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/7680e15c
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/7680e15c
Branch: refs/heads/CURATOR-477
Commit: 7680e15ca191f4d09d7475b1e3d3e3a857a80b91
Parents: 53c4770
Author: Rama <ra...@salesforce.com>
Authored: Mon Sep 24 13:19:40 2018 +0530
Committer: Rama <ra...@salesforce.com>
Committed: Mon Sep 24 13:19:40 2018 +0530
----------------------------------------------------------------------
.../framework/recipes/cache/TreeCache.java | 34 ++++++++++----------
1 file changed, 17 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/7680e15c/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
index b6911f3..dc2afc5 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
@@ -19,28 +19,11 @@
package org.apache.curator.framework.recipes.cache;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.curator.utils.PathUtils.validatePath;
-
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
-import java.io.Closeable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.concurrent.atomic.AtomicReference;
-import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.WatcherRemoveCuratorFramework;
import org.apache.curator.framework.api.BackgroundCallback;
@@ -62,6 +45,23 @@ import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.Closeable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.curator.utils.PathUtils.validatePath;
/**
* <p>A utility that attempts to keep all data from all children of a ZK path locally cached. This class
[4/8] curator git commit: address review comments
Posted by ca...@apache.org.
address review comments
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/53c47706
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/53c47706
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/53c47706
Branch: refs/heads/CURATOR-477
Commit: 53c47706913cc4e22c4fc229bc8bc95a730077fd
Parents: 60e9be8
Author: Rama <ra...@salesforce.com>
Authored: Mon Sep 24 13:17:15 2018 +0530
Committer: Rama <ra...@salesforce.com>
Committed: Mon Sep 24 13:17:15 2018 +0530
----------------------------------------------------------------------
.../framework/recipes/cache/TreeCache.java | 23 +++++---------------
1 file changed, 6 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/53c47706/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
index 70e0abd..b6911f3 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
@@ -44,11 +44,11 @@ import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.WatcherRemoveCuratorFramework;
import org.apache.curator.framework.api.BackgroundCallback;
+import org.apache.curator.framework.api.BackgroundPathable;
import org.apache.curator.framework.api.CuratorEvent;
-import org.apache.curator.framework.api.ErrorListenerPathable;
-import org.apache.curator.framework.api.GetDataBuilder;
-import org.apache.curator.framework.api.GetDataWatchBackgroundStatable;
+import org.apache.curator.framework.api.Pathable;
import org.apache.curator.framework.api.UnhandledErrorListener;
+import org.apache.curator.framework.api.Watchable;
import org.apache.curator.framework.listen.Listenable;
import org.apache.curator.framework.listen.ListenerContainer;
import org.apache.curator.framework.state.ConnectionState;
@@ -270,11 +270,7 @@ public class TreeCache implements Closeable
{
if ( treeState.get() == TreeState.STARTED )
{
- if (disableZkWatches) {
- client.getChildren().inBackground(this).forPath(path);
- } else {
- client.getChildren().usingWatcher(this).inBackground(this).forPath(path);
- }
+ maybeWatch(client.getChildren()).forPath(path);
}
}
@@ -293,15 +289,8 @@ public class TreeCache implements Closeable
}
}
- private ErrorListenerPathable<byte[]> maybeWatch(GetDataWatchBackgroundStatable dataBuilder) {
- if (disableZkWatches) {
- return dataBuilder.inBackground(this);
- } else {
- return dataBuilder.usingWatcher(this).inBackground(this);
- }
- }
-
- private ErrorListenerPathable<byte[]> maybeWatch(GetDataBuilder dataBuilder) {
+ private <T, P extends Watchable<BackgroundPathable<T>> & BackgroundPathable<T>> Pathable<T> maybeWatch(
+ P dataBuilder) {
if (disableZkWatches) {
return dataBuilder.inBackground(this);
} else {
[6/8] curator git commit: added for exists watcher also
Posted by ca...@apache.org.
added for exists watcher also
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/b7c902ae
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/b7c902ae
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/b7c902ae
Branch: refs/heads/CURATOR-477
Commit: b7c902ae01c58806e09316898883406ad5c7edd7
Parents: 7680e15
Author: Rama <ra...@salesforce.com>
Authored: Tue Sep 25 13:08:47 2018 +0530
Committer: Rama <ra...@salesforce.com>
Committed: Tue Sep 25 13:08:47 2018 +0530
----------------------------------------------------------------------
.../org/apache/curator/framework/recipes/cache/TreeCache.java | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/b7c902ae/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
index dc2afc5..e6119f5 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java
@@ -347,7 +347,11 @@ public class TreeCache implements Closeable
if ( parent == null )
{
// Root node; use an exist query to watch for existence.
- client.checkExists().usingWatcher(this).inBackground(this).forPath(path);
+ if (disableZkWatches) {
+ client.checkExists().forPath(path);
+ } else {
+ client.checkExists().usingWatcher(this).inBackground(this).forPath(path);
+ }
}
else
{