You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2017/05/11 15:10:48 UTC
[2/2] curator git commit: CachedModeledFramework now handles
unresolved paths where the final node is a parameter.
CachedModeledFramework now handles unresolved paths where the final node is a parameter.
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/7a15af6a
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/7a15af6a
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/7a15af6a
Branch: refs/heads/CURATOR-397
Commit: 7a15af6ac5a58f1aba5dd6569d11b3a46fc45f9d
Parents: bb36c48
Author: randgalt <ra...@apache.org>
Authored: Thu May 11 17:10:43 2017 +0200
Committer: randgalt <ra...@apache.org>
Committed: Thu May 11 17:10:43 2017 +0200
----------------------------------------------------------------------
curator-examples/src/main/java/pubsub/SubPubTest.java | 6 +++++-
curator-examples/src/main/java/pubsub/Subscriber.java | 10 ++--------
.../x/async/modeled/details/ModeledCacheImpl.java | 5 +++++
.../curator/x/async/modeled/details/ZPathImpl.java | 6 ++++--
.../src/site/confluence/modeled-typed.confluence | 14 ++++++++++++++
5 files changed, 30 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/7a15af6a/curator-examples/src/main/java/pubsub/SubPubTest.java
----------------------------------------------------------------------
diff --git a/curator-examples/src/main/java/pubsub/SubPubTest.java b/curator-examples/src/main/java/pubsub/SubPubTest.java
index 79e8df6..354d568 100644
--- a/curator-examples/src/main/java/pubsub/SubPubTest.java
+++ b/curator-examples/src/main/java/pubsub/SubPubTest.java
@@ -63,13 +63,17 @@ public class SubPubTest implements Closeable
private static final Duration[] durations = {Duration.ofSeconds(1), Duration.ofMinutes(1), Duration.ofHours(1)};
private static final String[] positions = {"worker", "manager", "executive"};
- public static void main(String[] args) throws Exception
+ public static void main(String[] args)
{
try ( SubPubTest subPubTest = new SubPubTest() )
{
subPubTest.start();
TimeUnit.MINUTES.sleep(1); // run the test for a minute then exit
}
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
}
public SubPubTest() throws Exception
http://git-wip-us.apache.org/repos/asf/curator/blob/7a15af6a/curator-examples/src/main/java/pubsub/Subscriber.java
----------------------------------------------------------------------
diff --git a/curator-examples/src/main/java/pubsub/Subscriber.java b/curator-examples/src/main/java/pubsub/Subscriber.java
index d71b863..94a6247 100644
--- a/curator-examples/src/main/java/pubsub/Subscriber.java
+++ b/curator-examples/src/main/java/pubsub/Subscriber.java
@@ -70,20 +70,14 @@ public class Subscriber
*/
public CachedModeledFramework<Instance> startInstanceSubscriber(InstanceType instanceType)
{
- CachedModeledFramework<Instance> resolved = Clients.instanceClient
- .resolved(client, instanceType)
- .parent() // resolves to the parent path - models are children of this path
- .cached(); // makes a cached modeled instance
+ CachedModeledFramework<Instance> resolved = Clients.instanceClient.resolved(client, instanceType).cached();
resolved.start();
return resolved;
}
private <T extends Message> CachedModeledFramework<T> startSubscriber(TypedModeledFramework2<T, Group, Priority> typedClient, Group group, Priority priority)
{
- CachedModeledFramework<T> resolved = typedClient
- .resolved(client, group, priority)
- .parent() // resolves to the parent path - models are children of this path
- .cached(); // makes a cached modeled instance
+ CachedModeledFramework<T> resolved = typedClient.resolved(client, group, priority).cached();
resolved.start();
return resolved;
}
http://git-wip-us.apache.org/repos/asf/curator/blob/7a15af6a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCacheImpl.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCacheImpl.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCacheImpl.java
index 2de57c1..415e015 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCacheImpl.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ModeledCacheImpl.java
@@ -61,6 +61,11 @@ class ModeledCacheImpl<T> implements TreeCacheListener, ModeledCache<T>
ModeledCacheImpl(CuratorFramework client, ModelSpec<T> modelSpec, ExecutorService executor)
{
+ if ( !modelSpec.path().isResolved() && !modelSpec.path().isRoot() && modelSpec.path().parent().isResolved() )
+ {
+ modelSpec = modelSpec.parent(); // i.e. the last item is a parameter
+ }
+
this.serializer = modelSpec.serializer();
cache = TreeCache.newBuilder(client, modelSpec.path().fullPath())
.setCacheData(false)
http://git-wip-us.apache.org/repos/asf/curator/blob/7a15af6a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java
index f91b221..fff742e 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/ZPathImpl.java
@@ -18,7 +18,6 @@
*/
package org.apache.curator.x.async.modeled.details;
-import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import org.apache.curator.x.async.modeled.NodeName;
@@ -252,7 +251,10 @@ public class ZPathImpl implements ZPath
private void checkResolved()
{
- Preconditions.checkState(isResolved, "This ZPath has not been resolved");
+ if ( !isResolved)
+ {
+ throw new IllegalStateException("This ZPath has not been resolved: " + toString());
+ }
}
private static void validate(String nodeName)
http://git-wip-us.apache.org/repos/asf/curator/blob/7a15af6a/curator-x-async/src/site/confluence/modeled-typed.confluence
----------------------------------------------------------------------
diff --git a/curator-x-async/src/site/confluence/modeled-typed.confluence b/curator-x-async/src/site/confluence/modeled-typed.confluence
index ba872cb..c02ea80 100644
--- a/curator-x-async/src/site/confluence/modeled-typed.confluence
+++ b/curator-x-async/src/site/confluence/modeled-typed.confluence
@@ -22,6 +22,20 @@ cached.listenable.addListener((type, path, stat, model) -> {
});
{code}
+h3. Unresolved Paths and Caching
+
+If the last node in the ModelSpec's path is a parameter, CachedModeledFramework will automatically
+listen to the parent path. E.g.
+
+{code}
+ZPath path = ZPath.parseWithIds("/root/instance/{id}");
+ModelSpec<MyModel> modelSpec = ModelSpec.builder(path, serializer);
+ModeledFramework<MyModel> modeledClient = ModeledFramework.wrap(modelSpec, client, modelSpec);
+
+CachedModeledFramework<MyModel> cached = modeledClient.cached();
+cached.start(); // automatically listens to "/root/instance" and below
+{code}
+
h2. Typed Parameters
The "resolve" methods in ZPath et al consume untyped Objects. Ideally, we should be able to