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:47 UTC

[1/2] curator git commit: updated doc for new auto-resolve behavior

Repository: curator
Updated Branches:
  refs/heads/CURATOR-397 3338c05c9 -> 7a15af6ac


updated doc for new auto-resolve behavior


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

Branch: refs/heads/CURATOR-397
Commit: bb36c48ef420d48e345368d03e4696f22d394126
Parents: 3338c05
Author: randgalt <ra...@apache.org>
Authored: Thu May 11 16:53:30 2017 +0200
Committer: randgalt <ra...@apache.org>
Committed: Thu May 11 16:53:30 2017 +0200

----------------------------------------------------------------------
 .../confluence/modeled-components.confluence    | 34 ++++++++++++++++++++
 1 file changed, 34 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/bb36c48e/curator-x-async/src/site/confluence/modeled-components.confluence
----------------------------------------------------------------------
diff --git a/curator-x-async/src/site/confluence/modeled-components.confluence b/curator-x-async/src/site/confluence/modeled-components.confluence
index 280f006..62bcdeb 100644
--- a/curator-x-async/src/site/confluence/modeled-components.confluence
+++ b/curator-x-async/src/site/confluence/modeled-components.confluence
@@ -35,6 +35,21 @@ Parameters are resolved by calling {{toString()}} on the parameter. You can use
 to change this behavior. If a parameter implements {{NodeName}} the {{nodeName()}} method
 is used as the parameter value.
 
+h3. Partial Resolution
+
+Note: ZPaths can be partially resolved. E.g.
+
+{code}
+ZPath path = ZPath.parseWithIds("/foo/{type}/bar/{id}");
+
+...
+
+ZPath partial = path.resolve("standard");
+// partial is now "/foo/standard/bar/{id}"
+{code}
+
+ModeledFramework takes advantage of this. [[See below|#ModeledFramework]] for details.
+
 h2. ModelSpec
 
 A {{ModelSpec}} contains all the metadata needed to operate on a ZooKeeper path:
@@ -144,6 +159,25 @@ client.getData().forPath(path).whenComplete((data, e) -> {
 });
 {code}
 
+h3. Partially Resolved ZPaths and Set/Update
+
+ModeledFramework's various {{set}} and {{update}} methods check for unresolved ZPaths. If the current
+modelSpec has an unresolved ZPath when set/update is called, it is automatically resolved using the model
+instance being set/updated. E.g.
+
+{code}
+ZPath path = ZPath.parseWithIds("/root/{type}/instance/{id}");
+ModelSpec<MyModel> modelSpec = ModelSpec.builder(path, serializer);
+ModeledFramework<MyModel> modeledClient = ModeledFramework.wrap(modelSpec, client, modelSpec);
+
+...
+
+String currentType = ...
+MyModel model = ...
+modeledClient.resolved(currentType).set(model); // internally, ModeledFramework calls ZPath.resolved()
+                                                // using "model" as the argument to get the actual ZPath
+{code}
+
 h2. Caching and Typed Parameters
 
 In addition to the above features, Modeled Curator supports [[Integrated Caching|modeled-typed.html]],


[2/2] curator git commit: CachedModeledFramework now handles unresolved paths where the final node is a parameter.

Posted by ra...@apache.org.
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