curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [7/7] git commit: Finished path children cache
Date Thu, 29 May 2014 20:54:28 GMT
Finished path children cache


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

Branch: refs/heads/curator-rpc
Commit: 6f9a9ab4ff218fb4aa8e961239bee45fe647f416
Parents: 4c626a7
Author: randgalt <randgalt@apache.org>
Authored: Thu May 29 15:54:10 2014 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Thu May 29 15:54:10 2014 -0500

----------------------------------------------------------------------
 .../curator/x/rpc/idl/event/RpcChildData.java   |   11 +
 .../idl/event/RpcPathChildrenCacheEvent.java    |    2 +-
 .../projection/CuratorProjectionService.java    |   46 +-
 curator-x-rpc/src/main/thrift/curator.thrift    |    2 +
 .../curator/generated/CuratorService.java       | 2071 ++++++++++++++++++
 .../org/apache/curator/x/rpc/TestClient.java    |    9 +
 6 files changed, 2128 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/6f9a9ab4/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/event/RpcChildData.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/event/RpcChildData.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/event/RpcChildData.java
index 4c7827b..e490493 100644
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/event/RpcChildData.java
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/event/RpcChildData.java
@@ -2,6 +2,7 @@ package org.apache.curator.x.rpc.idl.event;
 
 import com.facebook.swift.codec.ThriftField;
 import com.facebook.swift.codec.ThriftStruct;
+import org.apache.curator.framework.recipes.cache.ChildData;
 
 @ThriftStruct("ChildData")
 public class RpcChildData
@@ -19,6 +20,16 @@ public class RpcChildData
     {
     }
 
+    public RpcChildData(ChildData data)
+    {
+        if ( data != null )
+        {
+            this.path = data.getPath();
+            this.stat = RpcCuratorEvent.toRpcStat(data.getStat());
+            this.data = data.getData();
+        }
+    }
+
     public RpcChildData(String path, RpcStat stat, byte[] data)
     {
         this.path = path;

http://git-wip-us.apache.org/repos/asf/curator/blob/6f9a9ab4/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/event/RpcPathChildrenCacheEvent.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/event/RpcPathChildrenCacheEvent.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/event/RpcPathChildrenCacheEvent.java
index 9321157..59be6e2 100644
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/event/RpcPathChildrenCacheEvent.java
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/event/RpcPathChildrenCacheEvent.java
@@ -24,7 +24,7 @@ public class RpcPathChildrenCacheEvent
     {
         this.cachedPath = cachedPath;
         type = RpcPathChildrenCacheEventType.valueOf(event.getType().name());
-        data = (event.getData() != null) ? new RpcChildData(event.getData().getPath(), RpcCuratorEvent.toRpcStat(event.getData().getStat()),
event.getData().getData()) : null;
+        data = (event.getData() != null) ? new RpcChildData(event.getData()) : null;
     }
 
     public RpcPathChildrenCacheEvent(String cachedPath, RpcPathChildrenCacheEventType type,
RpcChildData data)

http://git-wip-us.apache.org/repos/asf/curator/blob/6f9a9ab4/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/CuratorProjectionService.java
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/CuratorProjectionService.java
b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/CuratorProjectionService.java
index 1084507..8b41353 100644
--- a/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/CuratorProjectionService.java
+++ b/curator-x-rpc/src/main/java/org/apache/curator/x/rpc/idl/projection/CuratorProjectionService.java
@@ -26,6 +26,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.api.*;
+import org.apache.curator.framework.recipes.cache.ChildData;
 import org.apache.curator.framework.recipes.cache.PathChildrenCache;
 import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
 import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener;
@@ -41,15 +42,7 @@ import org.apache.curator.x.rpc.connections.ConnectionManager;
 import org.apache.curator.x.rpc.connections.CuratorEntry;
 import org.apache.curator.x.rpc.details.RpcBackgroundCallback;
 import org.apache.curator.x.rpc.details.RpcWatcher;
-import org.apache.curator.x.rpc.idl.event.LeaderEvent;
-import org.apache.curator.x.rpc.idl.event.LeaderResult;
-import org.apache.curator.x.rpc.idl.event.OptionalChildrenList;
-import org.apache.curator.x.rpc.idl.event.OptionalPath;
-import org.apache.curator.x.rpc.idl.event.OptionalRpcStat;
-import org.apache.curator.x.rpc.idl.event.RpcCuratorEvent;
-import org.apache.curator.x.rpc.idl.event.RpcParticipant;
-import org.apache.curator.x.rpc.idl.event.RpcPathChildrenCacheEvent;
-import org.apache.curator.x.rpc.idl.event.RpcStat;
+import org.apache.curator.x.rpc.idl.event.*;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.data.Stat;
 import org.slf4j.Logger;
@@ -356,7 +349,7 @@ public class CuratorProjectionService
     {
         CuratorEntry entry = getEntry(projection);
 
-        LeaderLatch leaderLatch = getThis(entry, leaderProjection.projection.id, LeaderLatch.class);
+        LeaderLatch leaderLatch = getThing(entry, leaderProjection.projection.id, LeaderLatch.class);
         Collection<Participant> participants = leaderLatch.getParticipants();
         return Lists.transform(Lists.newArrayList(participants), new Function<Participant,
RpcParticipant>()
             {
@@ -373,7 +366,7 @@ public class CuratorProjectionService
     {
         CuratorEntry entry = getEntry(projection);
 
-        LeaderLatch leaderLatch = getThis(entry, leaderProjection.projection.id, LeaderLatch.class);
+        LeaderLatch leaderLatch = getThing(entry, leaderProjection.projection.id, LeaderLatch.class);
         return leaderLatch.hasLeadership();
     }
 
@@ -416,6 +409,35 @@ public class CuratorProjectionService
         return new PathChildrenCacheProjection(new GenericProjection(id));
     }
 
+    @ThriftMethod
+    public List<RpcChildData> getPathChildrenCacheData(CuratorProjection projection,
PathChildrenCacheProjection cacheProjection) throws Exception
+    {
+        CuratorEntry entry = getEntry(projection);
+
+        PathChildrenCache pathChildrenCache = getThing(entry, cacheProjection.projection.id,
PathChildrenCache.class);
+        return Lists.transform
+        (
+            pathChildrenCache.getCurrentData(),
+            new Function<ChildData, RpcChildData>()
+            {
+                @Override
+                public RpcChildData apply(ChildData childData)
+                {
+                    return new RpcChildData(childData);
+                }
+            }
+        );
+    }
+
+    @ThriftMethod
+    public RpcChildData getPathChildrenCacheDataForPath(CuratorProjection projection, PathChildrenCacheProjection
cacheProjection, String path) throws Exception
+    {
+        CuratorEntry entry = getEntry(projection);
+
+        PathChildrenCache pathChildrenCache = getThing(entry, cacheProjection.projection.id,
PathChildrenCache.class);
+        return new RpcChildData(pathChildrenCache.getCurrentData(path));
+    }
+
     public void addEvent(CuratorProjection projection, RpcCuratorEvent event)
     {
         CuratorEntry entry = connectionManager.get(projection.id);
@@ -444,7 +466,7 @@ public class CuratorProjectionService
         throw new Exception("That operation is not available");
     }
 
-    private <T> T getThis(CuratorEntry entry, String id, Class<T> clazz)
+    private <T> T getThing(CuratorEntry entry, String id, Class<T> clazz)
     {
         T thing = entry.getThing(id, clazz);
         Preconditions.checkNotNull(thing, "No item of type " + clazz.getSimpleName() + "
found with id " + id);

http://git-wip-us.apache.org/repos/asf/curator/blob/6f9a9ab4/curator-x-rpc/src/main/thrift/curator.thrift
----------------------------------------------------------------------
diff --git a/curator-x-rpc/src/main/thrift/curator.thrift b/curator-x-rpc/src/main/thrift/curator.thrift
index 765b93c..2b5e115 100644
--- a/curator-x-rpc/src/main/thrift/curator.thrift
+++ b/curator-x-rpc/src/main/thrift/curator.thrift
@@ -188,6 +188,8 @@ service CuratorService {
   OptionalChildrenList getChildren(1: CuratorProjection projection, 2: GetChildrenSpec spec);
   binary getData(1: CuratorProjection projection, 2: GetDataSpec spec);
   list<Participant> getLeaderParticipants(1: CuratorProjection projection, 2: LeaderProjection
leaderProjection);
+  list<ChildData> getPathChildrenCacheData(1: CuratorProjection projection, 2: PathChildrenCacheProjection
cacheProjection);
+  ChildData getPathChildrenCacheDataForPath(1: CuratorProjection projection, 2: PathChildrenCacheProjection
cacheProjection, 3: string path);
   bool isLeader(1: CuratorProjection projection, 2: LeaderProjection leaderProjection);
   CuratorProjection newCuratorProjection(1: string connectionName);
   Stat setData(1: CuratorProjection projection, 2: SetDataSpec spec);


Mime
View raw message