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/06/10 04:55:25 UTC

[1/2] curator git commit: Added '0' versions of Typed classes as a convenience so that the same idiom can be used even if there are no real type arguments

Repository: curator
Updated Branches:
  refs/heads/CURATOR-397 523f0c809 -> 55df07e6a


Added '0' versions of Typed classes as a convenience so that the same idiom can be used even if there are no real type arguments


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

Branch: refs/heads/CURATOR-397
Commit: f32a5fb4eeb63251ad769f54f7fee255c2bee61e
Parents: 523f0c8
Author: randgalt <ra...@apache.org>
Authored: Fri Jun 9 23:54:51 2017 -0500
Committer: randgalt <ra...@apache.org>
Committed: Fri Jun 9 23:54:51 2017 -0500

----------------------------------------------------------------------
 .../x/async/modeled/typed/TypedModelSpec0.java  | 61 +++++++++++++++++++
 .../modeled/typed/TypedModeledFramework0.java   | 63 ++++++++++++++++++++
 .../x/async/modeled/typed/TypedZPath0.java      | 52 ++++++++++++++++
 3 files changed, 176 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/f32a5fb4/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedModelSpec0.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedModelSpec0.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedModelSpec0.java
new file mode 100644
index 0000000..dee3506
--- /dev/null
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedModelSpec0.java
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.async.modeled.typed;
+
+import org.apache.curator.x.async.modeled.ModelSpec;
+import org.apache.curator.x.async.modeled.ModelSpecBuilder;
+
+/**
+ * Same as {@link TypedModelSpec}, but with 0 parameters
+ */
+@FunctionalInterface
+public interface TypedModelSpec0<M>
+{
+    ModelSpec<M> resolved();
+
+    /**
+     * Return a new TypedModelSpec using the given model spec builder and typed path. When
+     * {@link #resolved()} is called the actual model spec is generated with the
+     * resolved path
+     *
+     * @param builder model spec builder
+     * @param path typed path
+     * @return new TypedModelSpec
+     */
+    static <M> TypedModelSpec0<M> from(ModelSpecBuilder<M> builder, TypedZPath0 path)
+    {
+        return () -> builder.withPath(path.resolved()).build();
+    }
+
+    /**
+     * Return a new TypedModelSpec using the given model spec builder and path. A TypedZPath
+     * is created from the given full path and When
+     * {@link #resolved()} is called the actual model spec is generated with the
+     * resolved path
+     *
+     * @param builder model spec builder
+     * @param pathWithIds typed path
+     * @return new TypedModelSpec
+     */
+    static <M> TypedModelSpec0<M> from(ModelSpecBuilder<M> builder, String pathWithIds)
+    {
+        TypedZPath0 zPath = TypedZPath0.from(pathWithIds);
+        return () -> builder.withPath(zPath.resolved()).build();
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/f32a5fb4/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedModeledFramework0.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedModeledFramework0.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedModeledFramework0.java
new file mode 100644
index 0000000..8c9de04
--- /dev/null
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedModeledFramework0.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.async.modeled.typed;
+
+import org.apache.curator.x.async.AsyncCuratorFramework;
+import org.apache.curator.x.async.modeled.ModelSpecBuilder;
+import org.apache.curator.x.async.modeled.ModeledFramework;
+import org.apache.curator.x.async.modeled.ModeledFrameworkBuilder;
+
+/**
+ * Same as {@link TypedModeledFramework}, but with 0 parameters
+ */
+@FunctionalInterface
+public interface TypedModeledFramework0<M>
+{
+    ModeledFramework<M> resolved(AsyncCuratorFramework client);
+
+    /**
+     * Return a new TypedModeledFramework using the given modeled framework builder and typed model spec.
+     * When {@link #resolved(org.apache.curator.x.async.AsyncCuratorFramework)} is called the actual ModeledFramework is generated with the
+     * resolved model spec
+     *
+     * @param frameworkBuilder ModeledFrameworkBuilder
+     * @param modelSpec TypedModelSpec
+     * @return new TypedModeledFramework
+     */
+    static <M> TypedModeledFramework0<M> from(ModeledFrameworkBuilder<M> frameworkBuilder, TypedModelSpec0<M> modelSpec)
+    {
+        return (client) -> frameworkBuilder.withClient(client).withModelSpec(modelSpec.resolved()).build();
+    }
+
+    /**
+     * Return a new TypedModeledFramework using the given modeled framework builder, model spec builder and a path with ids.
+     * When {@link #resolved(org.apache.curator.x.async.AsyncCuratorFramework)} is called the actual ModeledFramework is generated with the
+     * resolved model spec and resolved path
+     *
+     * @param frameworkBuilder ModeledFrameworkBuilder
+     * @param modelSpecBuilder model spec builder
+     * @param pathWithIds path with {XXXX} parameters
+     * @return new TypedModeledFramework
+     */
+    static <M> TypedModeledFramework0<M> from(ModeledFrameworkBuilder<M> frameworkBuilder, ModelSpecBuilder<M> modelSpecBuilder, String pathWithIds)
+    {
+        TypedModelSpec0<M> typedModelSpec = TypedModelSpec0.from(modelSpecBuilder, pathWithIds);
+        return (client) -> frameworkBuilder.withClient(client).withModelSpec(typedModelSpec.resolved()).build();
+    }
+}

http://git-wip-us.apache.org/repos/asf/curator/blob/f32a5fb4/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedZPath0.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedZPath0.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedZPath0.java
new file mode 100644
index 0000000..60576b2
--- /dev/null
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/typed/TypedZPath0.java
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.curator.x.async.modeled.typed;
+
+import org.apache.curator.x.async.modeled.ZPath;
+
+/**
+ * Same as {@link TypedZPath}, but with 0 parameters.
+ */
+@FunctionalInterface
+public interface TypedZPath0
+{
+    ZPath resolved();
+
+    /**
+     * Return a TypedZPath using {@link org.apache.curator.x.async.modeled.ZPath#parseWithIds}
+     *
+     * @param pathWithIds path to pass to {@link org.apache.curator.x.async.modeled.ZPath#parseWithIds}
+     * @return TypedZPath
+     */
+    static TypedZPath0 from(String pathWithIds)
+    {
+        return from(ZPath.parseWithIds(pathWithIds));
+    }
+
+    /**
+     * Return a TypedZPath
+     *
+     * @param path path to use
+     * @return TypedZPath
+     */
+    static TypedZPath0 from(ZPath path)
+    {
+        return path::resolved;
+    }
+}


[2/2] curator git commit: Added list()

Posted by ra...@apache.org.
Added list()


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

Branch: refs/heads/CURATOR-397
Commit: 55df07e6ab5417943d485e88f7efa89df0b6e52d
Parents: f32a5fb
Author: randgalt <ra...@apache.org>
Authored: Fri Jun 9 23:55:20 2017 -0500
Committer: randgalt <ra...@apache.org>
Committed: Fri Jun 9 23:55:20 2017 -0500

----------------------------------------------------------------------
 .../x/async/modeled/cached/CachedModeledFramework.java  |  8 ++++++++
 .../modeled/details/CachedModeledFrameworkImpl.java     | 12 ++++++++++++
 .../x/async/modeled/details/ModeledCacheImpl.java       |  9 ++++++++-
 3 files changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/55df07e6/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/CachedModeledFramework.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/CachedModeledFramework.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/CachedModeledFramework.java
index f0d1d1b..8ab5e8b 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/CachedModeledFramework.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/CachedModeledFramework.java
@@ -25,6 +25,7 @@ import org.apache.curator.x.async.modeled.ZNode;
 import org.apache.curator.x.async.modeled.ZPath;
 import org.apache.zookeeper.data.Stat;
 import java.io.Closeable;
+import java.util.List;
 
 public interface CachedModeledFramework<T> extends ModeledFramework<T>, Closeable
 {
@@ -103,4 +104,11 @@ public interface CachedModeledFramework<T> extends ModeledFramework<T>, Closeabl
      * @see org.apache.curator.x.async.AsyncStage
      */
     AsyncStage<ZNode<T>> readThroughAsZNode();
+
+    /**
+     * Return the instances of the base path of this cached framework
+     *
+     * @return listing of all models in the base path
+     */
+    AsyncStage<List<T>> list();
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/55df07e6/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/CachedModeledFrameworkImpl.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/CachedModeledFrameworkImpl.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/CachedModeledFrameworkImpl.java
index 3893f47..4884af4 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/CachedModeledFrameworkImpl.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/details/CachedModeledFrameworkImpl.java
@@ -42,6 +42,7 @@ import java.util.concurrent.Executor;
 import java.util.concurrent.ExecutorService;
 import java.util.function.Function;
 import java.util.function.Supplier;
+import java.util.stream.Collectors;
 
 class CachedModeledFrameworkImpl<T> implements CachedModeledFramework<T>
 {
@@ -208,6 +209,17 @@ class CachedModeledFrameworkImpl<T> implements CachedModeledFramework<T>
     }
 
     @Override
+    public AsyncStage<List<T>> list()
+    {
+        List<T> children = cache.currentChildren()
+            .values()
+            .stream()
+            .map(ZNode::model)
+            .collect(Collectors.toList());
+        return asyncDefaultMode ? ModelStage.asyncCompleted(children, executor) : ModelStage.completed(children);
+    }
+
+    @Override
     public AsyncStage<Stat> update(T model)
     {
         return client.update(model);

http://git-wip-us.apache.org/repos/asf/curator/blob/55df07e6/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 415e015..466c5e9 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
@@ -46,6 +46,7 @@ class ModeledCacheImpl<T> implements TreeCacheListener, ModeledCache<T>
     private final Map<ZPath, Entry<T>> entries = new ConcurrentHashMap<>();
     private final ModelSerializer<T> serializer;
     private final ListenerContainer<ModeledCacheListener<T>> listenerContainer = new ListenerContainer<>();
+    private final ZPath basePath;
 
     private static final class Entry<T>
     {
@@ -66,8 +67,9 @@ class ModeledCacheImpl<T> implements TreeCacheListener, ModeledCache<T>
             modelSpec = modelSpec.parent(); // i.e. the last item is a parameter
         }
 
+        basePath = modelSpec.path();
         this.serializer = modelSpec.serializer();
-        cache = TreeCache.newBuilder(client, modelSpec.path().fullPath())
+        cache = TreeCache.newBuilder(client, basePath.fullPath())
             .setCacheData(false)
             .setDataIsCompressed(modelSpec.createOptions().contains(CreateOption.compress))
             .setExecutor(executor)
@@ -106,6 +108,11 @@ class ModeledCacheImpl<T> implements TreeCacheListener, ModeledCache<T>
         return Optional.empty();
     }
 
+    Map<ZPath, ZNode<T>> currentChildren()
+    {
+        return currentChildren(basePath);
+    }
+
     @Override
     public Map<ZPath, ZNode<T>> currentChildren(ZPath path)
     {