curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject git commit: More work on Node caches and nulls
Date Mon, 10 Mar 2014 14:40:14 GMT
Repository: curator
Updated Branches:
  refs/heads/CURATOR-88 a8f716d7a -> 05fb0b873


More work on Node caches and nulls


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

Branch: refs/heads/CURATOR-88
Commit: 05fb0b8737d7939322ee182362ba19efc5a477b5
Parents: a8f716d
Author: randgalt <randgalt@apache.org>
Authored: Mon Mar 10 09:40:06 2014 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Mon Mar 10 09:40:06 2014 -0500

----------------------------------------------------------------------
 .../org/apache/curator/x/rest/api/Constants.java    |  7 ++++---
 .../apache/curator/x/rest/entities/NodeData.java    | 16 ++--------------
 curator-x-rest/src/site/confluence/apis.confluence  |  4 ++--
 .../src/site/confluence/entities.confluence         |  3 +++
 .../apache/curator/x/rest/api/TestNodeCache.java    | 10 ++++++----
 .../curator/x/rest/support/NodeCacheBridge.java     |  5 +++--
 6 files changed, 20 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/05fb0b87/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/Constants.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/Constants.java b/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/Constants.java
index d8c8a3d..78ba9d0 100644
--- a/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/Constants.java
+++ b/curator-x-rest/src/main/java/org/apache/curator/x/rest/api/Constants.java
@@ -21,6 +21,7 @@ package org.apache.curator.x.rest.api;
 import org.apache.curator.framework.recipes.cache.ChildData;
 import org.apache.curator.x.rest.CuratorRestContext;
 import org.apache.curator.x.rest.entities.NodeData;
+import org.apache.curator.x.rest.entities.OptionalNodeData;
 import org.codehaus.jackson.node.ObjectNode;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Response;
@@ -71,14 +72,14 @@ class Constants
     {
     }
 
-    static NodeData toNodeData(ChildData c)
+    static OptionalNodeData toNodeData(ChildData c)
     {
         if ( c == null )
         {
-            return new NodeData();
+            return new OptionalNodeData(null);
         }
         String payload = (c.getData() != null) ? new String(c.getData()) : "";
-        return new NodeData(c.getPath(), c.getStat(), payload, true);
+        return new OptionalNodeData(new NodeData(c.getPath(), c.getStat(), payload));
     }
 
     public static String newId()

http://git-wip-us.apache.org/repos/asf/curator/blob/05fb0b87/curator-x-rest/src/main/java/org/apache/curator/x/rest/entities/NodeData.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/main/java/org/apache/curator/x/rest/entities/NodeData.java
b/curator-x-rest/src/main/java/org/apache/curator/x/rest/entities/NodeData.java
index d1a4ea1..8326165 100644
--- a/curator-x-rest/src/main/java/org/apache/curator/x/rest/entities/NodeData.java
+++ b/curator-x-rest/src/main/java/org/apache/curator/x/rest/entities/NodeData.java
@@ -27,19 +27,17 @@ public class NodeData
     private String path;
     private Stat stat;
     private String data;
-    private boolean created;
 
     public NodeData()
     {
-        this("/", new Stat(), "", false);
+        this("/", new Stat(), "");
     }
 
-    public NodeData(String path, Stat stat, String data, boolean created)
+    public NodeData(String path, Stat stat, String data)
     {
         this.path = path;
         this.stat = stat;
         this.data = data;
-        this.created = created;
     }
 
     public String getPath()
@@ -71,14 +69,4 @@ public class NodeData
     {
         this.data = data;
     }
-
-    public boolean isCreated()
-    {
-        return created;
-    }
-
-    public void setCreated(boolean created)
-    {
-        this.created = created;
-    }
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/05fb0b87/curator-x-rest/src/site/confluence/apis.confluence
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/site/confluence/apis.confluence b/curator-x-rest/src/site/confluence/apis.confluence
index 74e880f..84444e6 100644
--- a/curator-x-rest/src/site/confluence/apis.confluence
+++ b/curator-x-rest/src/site/confluence/apis.confluence
@@ -53,12 +53,12 @@ h2. Recipe APIs
 |/curator/v1/recipes/semaphore/{lock-id}/{release-qty}|DELETE|n/a|n/a|Release the specified
number of leases.|
 | *Node Cache* | | | | |
 |/curator/v1/recipes/node-cache|POST|NodeCacheSpec|Id|Start a NodeCache instance. NodeCache
updates will be notified via status.|
-|/curator/v1/recipes/node-cache/{cache-id}|GET|n/a|NodeData|Stop and delete a node cache.|
+|/curator/v1/recipes/node-cache/{cache-id}|GET|n/a|OptionalNodeData|Get the current node
value.|
 |/curator/v1/recipes/node-cache/{cache-id}|DELETE|n/a|n/a|Stop and delete a node cache.|
 | *Path Cache* | | | | |
 |/curator/v1/recipes/path-cache|POST|PathChildrenCacheSpec|Id|Start a PathChildrenCache instance.
PathChildrenCache updates will be notified via status.|
 |/curator/v1/recipes/path-cache/{cache-id}|GET|n/a|array of NodeData|Return the current cached
values.|
-|/curator/v1/recipes/path-cache/{cache-id}/{full-path}|GET|n/a|NodeData|Return the current
cached value for the node at the specified full path.|
+|/curator/v1/recipes/path-cache/{cache-id}/{full-path}|GET|n/a|OptionalNodeData|Return the
current cached value for the node at the specified full path.|
 |/curator/v1/recipes/path-cache/{cache-id}|DELETE|n/a|n/a|Stop and delete a path cache.|
 | *Persistent Ephemeral Node* | | | | |
 |/curator/v1/recipes/persistent-ephemeral-node|POST|PersistentEphemeralNodeSpec|Id|Start
a PersistentEphemeralNode instance.|

http://git-wip-us.apache.org/repos/asf/curator/blob/05fb0b87/curator-x-rest/src/site/confluence/entities.confluence
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/site/confluence/entities.confluence b/curator-x-rest/src/site/confluence/entities.confluence
index 4606919..b6624c7 100644
--- a/curator-x-rest/src/site/confluence/entities.confluence
+++ b/curator-x-rest/src/site/confluence/entities.confluence
@@ -105,6 +105,9 @@ Here are the entity descriptions for the entities used in the APIs:
 |buildInitial|boolean|true if the initial data should be populated without sending notifications|
 |data|string|the data from the node|
 | | | |
+| *OptionalNodeData* | | |
+|nodeData|NodeData|Either _null_ or node data|
+| | | |
 | *PathChildrenCacheSpec* | | |
 |path|string|The ZK path|
 |cacheData|boolean|if true to cache node data|

http://git-wip-us.apache.org/repos/asf/curator/blob/05fb0b87/curator-x-rest/src/test/java/org/apache/curator/x/rest/api/TestNodeCache.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/test/java/org/apache/curator/x/rest/api/TestNodeCache.java
b/curator-x-rest/src/test/java/org/apache/curator/x/rest/api/TestNodeCache.java
index 4f08923..53b1152 100644
--- a/curator-x-rest/src/test/java/org/apache/curator/x/rest/api/TestNodeCache.java
+++ b/curator-x-rest/src/test/java/org/apache/curator/x/rest/api/TestNodeCache.java
@@ -60,25 +60,27 @@ public class TestNodeCache extends BaseClassForTests
                 }
             );
 
-        Assert.assertFalse(cache.getCurrentData().isCreated());
+        Assert.assertNull(cache.getCurrentData().getNodeData());
 
         createSpec.setPath("/test/node");
         createSpec.setData("a");
         restClient.resource(uriMaker.getMethodUri("create")).type(MediaType.APPLICATION_JSON).post(PathAndId.class,
createSpec);
         Assert.assertTrue(timing.acquireSemaphore(semaphore));
-        Assert.assertEquals(cache.getCurrentData().getData(), "a");
+        Assert.assertNotNull(cache.getCurrentData().getNodeData());
+        Assert.assertEquals(cache.getCurrentData().getNodeData().getData(), "a");
 
         SetDataSpec setDataSpec = new SetDataSpec();
         setDataSpec.setPath("/test/node");
         setDataSpec.setData("b");
         restClient.resource(uriMaker.getMethodUri("setData")).type(MediaType.APPLICATION_JSON).post(setDataSpec);
         Assert.assertTrue(timing.acquireSemaphore(semaphore));
-        Assert.assertEquals(cache.getCurrentData().getData(), "b");
+        Assert.assertNotNull(cache.getCurrentData().getNodeData());
+        Assert.assertEquals(cache.getCurrentData().getNodeData().getData(), "b");
 
         DeleteSpec deleteSpec = new DeleteSpec();
         deleteSpec.setPath("/test/node");
         restClient.resource(uriMaker.getMethodUri("delete")).type(MediaType.APPLICATION_JSON).post(deleteSpec);
         Assert.assertTrue(timing.acquireSemaphore(semaphore));
-        Assert.assertFalse(cache.getCurrentData().isCreated());
+        Assert.assertNull(cache.getCurrentData().getNodeData());
     }
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/05fb0b87/curator-x-rest/src/test/java/org/apache/curator/x/rest/support/NodeCacheBridge.java
----------------------------------------------------------------------
diff --git a/curator-x-rest/src/test/java/org/apache/curator/x/rest/support/NodeCacheBridge.java
b/curator-x-rest/src/test/java/org/apache/curator/x/rest/support/NodeCacheBridge.java
index 476e05e..12da4c0 100644
--- a/curator-x-rest/src/test/java/org/apache/curator/x/rest/support/NodeCacheBridge.java
+++ b/curator-x-rest/src/test/java/org/apache/curator/x/rest/support/NodeCacheBridge.java
@@ -26,6 +26,7 @@ import org.apache.curator.framework.recipes.cache.NodeCacheListener;
 import org.apache.curator.x.rest.api.NodeCacheResource;
 import org.apache.curator.x.rest.entities.NodeCacheSpec;
 import org.apache.curator.x.rest.entities.NodeData;
+import org.apache.curator.x.rest.entities.OptionalNodeData;
 import org.apache.curator.x.rest.entities.PathAndId;
 import org.apache.curator.x.rest.entities.Status;
 import org.apache.curator.x.rest.entities.StatusMessage;
@@ -77,9 +78,9 @@ public class NodeCacheBridge implements Closeable, StatusListener
         return listeners;
     }
 
-    public NodeData getCurrentData() throws Exception
+    public OptionalNodeData getCurrentData() throws Exception
     {
-        return restClient.resource(uriMaker.getMethodUri(NodeCacheResource.class, null)).path(id).type(MediaType.APPLICATION_JSON).get(NodeData.class);
+        return restClient.resource(uriMaker.getMethodUri(NodeCacheResource.class, null)).path(id).type(MediaType.APPLICATION_JSON).get(OptionalNodeData.class);
     }
 
     @Override


Mime
View raw message