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/04 15:30:18 UTC

curator git commit: some refactoring and doc

Repository: curator
Updated Branches:
  refs/heads/CURATOR-397 1793675c1 -> 0bc3a9bd2


some refactoring and doc


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

Branch: refs/heads/CURATOR-397
Commit: 0bc3a9bd2e63bee511b0d78f584f862e875c8365
Parents: 1793675
Author: randgalt <ra...@apache.org>
Authored: Thu May 4 10:30:13 2017 -0500
Committer: randgalt <ra...@apache.org>
Committed: Thu May 4 10:30:13 2017 -0500

----------------------------------------------------------------------
 curator-examples/src/main/java/pubsub/README.md | 79 +++++++++-----------
 .../src/main/java/pubsub/SubPubTest.java        |  6 +-
 .../modeled/cached/CachedModeledFramework.java  |  8 ++
 .../x/async/modeled/cached/ModeledCache.java    |  8 --
 .../details/CachedModeledFrameworkImpl.java     |  8 ++
 .../async/modeled/details/ModeledCacheImpl.java |  1 -
 6 files changed, 54 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/0bc3a9bd/curator-examples/src/main/java/pubsub/README.md
----------------------------------------------------------------------
diff --git a/curator-examples/src/main/java/pubsub/README.md b/curator-examples/src/main/java/pubsub/README.md
index adea2ef..90ccfac 100644
--- a/curator-examples/src/main/java/pubsub/README.md
+++ b/curator-examples/src/main/java/pubsub/README.md
@@ -1,9 +1,13 @@
 # Pub-Sub Example
-This example models a publish and subscribe system (note: it is not meant for production) using the strongly typed modeled APIs in Apache Curator. 
+This example models a publish and subscribe system (note: it is not meant for production) using 
+the strongly typed modeled APIs in Apache Curator. 
 
 ## Design Notes
 
-In this example, there are three models that can be published: `Instance`, `LocationAvailable` and `UserCreated`. Instances have an `InstanceType`; LocationAvailable and UserCreated both have a `Priority` and are associated with a `Group`. (Note: these names/objects are meant for illustrative purposes only and are completely contrived)
+In this example, there are three models that can be published: `Instance`, `LocationAvailable` 
+and `UserCreated`. Instances have an `InstanceType`; LocationAvailable and UserCreated both have 
+a `Priority` and are associated with a `Group`. (Note: these names/objects are meant for 
+illustrative purposes only and are completely contrived)
 
 Each model is stored at a unique path in ZooKeeper:
 
@@ -13,62 +17,49 @@ Each model is stored at a unique path in ZooKeeper:
 
 All models are stored using a TTL so that they automatically get deleted after 10 minutes.
 
-## Clients, Models and Paths
+## Clients
 
-This example uses the "typed" models (`TypedModelSpec`, etc.). The typed paths, models and clients are meant to be created early in your application and re-used as needed. Thus, you can model your ZooKeeper usage and the rest of your application can use them without worrying about correct paths, types, etc.
+This example uses the "typed" models (`TypedModelSpec`, etc.). The typed paths, models and 
+clients are meant to be created early in your application and re-used as needed. Thus, you 
+can model your ZooKeeper usage and the rest of your application can use them without worrying 
+about correct paths, types, etc.
 
-In the Pub-Sub example, the paths are defined in `Paths.java`, the model specs are defined in `ModelSpecs.java` and the client templates are defined in `Clients.java`.
+`TypedModeledFramework` is a template that produces a `ModeledFramework` by applying 
+parameters to the `TypedZPath` in the contained `TypedModelSpec`. Curator provides variants 
+that accept from 1 to 10 parameters (`TypedModeledFramework`, `TypedModeledFramework2`, 
+`TypedModeledFramework3`, etc.).
 
-### TypedZPath
-
-`TypedZPath` is a template that produces a `ZPath` by applying parameters. Curator provides variants that accept from 1 to 10 parameters (`TypedZPath`, `TypedZPath2`, `TypedZPath3`, etc.).
-
-In this example, the TypedZPaths are defined in `Paths.java`. E.g.
-
-```
-public static final TypedZPath2<Group, Priority> locationAvailablePath = 
-    TypedZPath2.from(basePath + "/messages/locations/{id}/{id}");
-
-```
-
-This creates a TypedZPath that requires two parameters, a `Group` and a `Priority`. When the `resolved()` method is called with a group and priority, the "{id}" values are replaced in order.
-
-### TypedModelSpec
-
-`TypedModelSpec` is a template that produces a `ModelSpec` by applying parameters to the contained `TypedZPath`. Curator provides variants that accept from 1 to 10 parameters (`TypedModelSpec`, `TypedModelSpec2`, `TypedModelSpec3`, etc.).
-
-In this example, the TypedModelSpecs are defined in `ModelSpecs.java`. E.g.
-
-```
-public static final TypedModelSpec<Instance, InstanceType> instanceModelSpec = 
-    TypedModelSpec.from(builder(Instance.class), Paths.instancesPath);
-```
-
-The `builder()` method creates a ModelSpec builder. 
-
-### TypedModeledFramework
-
-`TypedModeledFramework` is a template that produces a `ModeledFramework` by applying parameters to the `TypedZPath` in the contained `TypedModelSpec`. Curator provides variants that accept from 1 to 10 parameters (`TypedModeledFramework`, `TypedModeledFramework2`, `TypedModeledFramework3`, etc.).
-
-In this example, the TypedModelSpecs are defined in `Clients.java`. E.g.
+In this example, the TypedModeledFrameworks are defined in `Clients.java`. E.g.
 
 ```
-public static final TypedModeledFramework<Instance, InstanceType> instanceClient = 
-   TypedModeledFramework.from(ModeledFramework.builder(), ModelSpecs.instanceModelSpec)
+public static final TypedModeledFramework2<LocationAvailable, Group, Priority> locationAvailableClient = 
+    TypedModeledFramework2.from(
+        ModeledFramework.builder(),
+        builder(LocationAvailable.class),
+        "/root/pubsub/messages/locations/{id}/{id}"
+    );
 ```
 
 ## Publisher
 
-`Publisher.java` shows how to use the ModeledFramework to write models. There are methods to write single instances and to write lists of instances in a transaction. Each publish method resolves the appropriate typed client and then calls its `set()` method with the given model.
+`Publisher.java` shows how to use the ModeledFramework to write models. There are methods to 
+write single instances and to write lists of instances in a transaction. Each publish method 
+resolves the appropriate typed client and then calls its `set()` method with the given model.
 
 ## Subscriber
 
-`Subscriber.java` uses CachedModeledFrameworks to listen for changes on the parent nodes for all of the models in this example. Each of the methods resolves the appropriate typed client and then starts the cache (via `cached()`).
+`Subscriber.java` uses CachedModeledFrameworks to listen for changes on the parent nodes for 
+all of the models in this example. Each of the methods resolves the appropriate typed client 
+and then starts the cache (via `cached()`).
 
 ## SubPubTest
 
 `SubPubTest.java` is a class that exercises this example. 
 
-* `start()` uses `Subscriber` to start a `CachedModeledFramework` for each combination of the Instance + InstanceType, LocationAvailable + Group + Priority, and UserCreated + Group + Priority. It then adds a simple listener to each cache that merely prints the class name and path whenever an update occurs (see `generalListener()`).
-* `start()` also starts a scheduled task that runs every second. This task calls `publishSomething()`
-* `publishSomething()` randomly publishes either a single Instance, LocationAvailable, UserCreated or a list of those.
\ No newline at end of file
+* `start()` uses `Subscriber` to start a `CachedModeledFramework` for each combination of 
+the Instance + InstanceType, LocationAvailable + Group + Priority, and UserCreated + Group + Priority. It then adds a simple listener to each cache that merely prints the class name 
+and path whenever an update occurs (see `generalListener()`).
+* `start()` also starts a scheduled task that runs every second. This task calls 
+`publishSomething()`
+* `publishSomething()` randomly publishes either a single Instance, LocationAvailable, 
+UserCreated or a list of those.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/curator/blob/0bc3a9bd/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 bddfe8e..79e8df6 100644
--- a/curator-examples/src/main/java/pubsub/SubPubTest.java
+++ b/curator-examples/src/main/java/pubsub/SubPubTest.java
@@ -108,9 +108,9 @@ public class SubPubTest implements Closeable
         );
 
         // add listeners for each of the caches
-        instanceSubscribers.forEach(s -> s.getCache().listenable().addListener(generalListener()));
-        locationAvailableSubscribers.forEach(s -> s.getCache().listenable().addListener(generalListener()));
-        userCreatedSubscribers.forEach(s -> s.getCache().listenable().addListener(generalListener()));
+        instanceSubscribers.forEach(s -> s.listenable().addListener(generalListener()));
+        locationAvailableSubscribers.forEach(s -> s.listenable().addListener(generalListener()));
+        userCreatedSubscribers.forEach(s -> s.listenable().addListener(generalListener()));
 
         // schedule the publisher task once a second
         executorService.scheduleAtFixedRate(() -> publishSomething(publisher), 1, 1, TimeUnit.SECONDS);

http://git-wip-us.apache.org/repos/asf/curator/blob/0bc3a9bd/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 48e0a10..9e1fb68 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
@@ -18,6 +18,7 @@
  */
 package org.apache.curator.x.async.modeled.cached;
 
+import org.apache.curator.framework.listen.Listenable;
 import org.apache.curator.x.async.modeled.ModeledFramework;
 import org.apache.curator.x.async.modeled.ZPath;
 import java.io.Closeable;
@@ -43,6 +44,13 @@ public interface CachedModeledFramework<T> extends ModeledFramework<T>, Closeabl
     void close();
 
     /**
+     * Return the listener container so that you can add/remove listeners
+     *
+     * @return listener container
+     */
+    Listenable<ModeledCacheListener<T>> listenable();
+
+    /**
      * {@inheritDoc}
      */
     @Override

http://git-wip-us.apache.org/repos/asf/curator/blob/0bc3a9bd/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCache.java
----------------------------------------------------------------------
diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCache.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCache.java
index 75e4ad9..9289988 100644
--- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCache.java
+++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/ModeledCache.java
@@ -18,7 +18,6 @@
  */
 package org.apache.curator.x.async.modeled.cached;
 
-import org.apache.curator.framework.listen.Listenable;
 import org.apache.curator.x.async.modeled.ZPath;
 import java.util.Map;
 import java.util.Optional;
@@ -43,11 +42,4 @@ public interface ModeledCache<T>
      * @return a possibly-empty map of children if the node is alive
      */
     Map<ZPath, ZNode<T>> currentChildren(ZPath path);
-
-    /**
-     * Return the listener container so that you can add/remove listeners
-     *
-     * @return listener container
-     */
-    Listenable<ModeledCacheListener<T>> listenable();
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/0bc3a9bd/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 a88c5ca..ba11bc2 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
@@ -21,6 +21,7 @@ package org.apache.curator.x.async.modeled.details;
 import com.google.common.collect.Lists;
 import org.apache.curator.framework.api.transaction.CuratorOp;
 import org.apache.curator.framework.api.transaction.CuratorTransactionResult;
+import org.apache.curator.framework.listen.Listenable;
 import org.apache.curator.x.async.AsyncCuratorFramework;
 import org.apache.curator.x.async.AsyncStage;
 import org.apache.curator.x.async.modeled.ModelSpec;
@@ -28,6 +29,7 @@ import org.apache.curator.x.async.modeled.ModeledFramework;
 import org.apache.curator.x.async.modeled.ZPath;
 import org.apache.curator.x.async.modeled.cached.CachedModeledFramework;
 import org.apache.curator.x.async.modeled.cached.ModeledCache;
+import org.apache.curator.x.async.modeled.cached.ModeledCacheListener;
 import org.apache.curator.x.async.modeled.cached.ZNode;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.data.Stat;
@@ -71,6 +73,12 @@ class CachedModeledFrameworkImpl<T> implements CachedModeledFramework<T>
     }
 
     @Override
+    public Listenable<ModeledCacheListener<T>> listenable()
+    {
+        return cache.listenable();
+    }
+
+    @Override
     public CachedModeledFramework<T> cached()
     {
         return this;

http://git-wip-us.apache.org/repos/asf/curator/blob/0bc3a9bd/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 472b1d4..061ea17 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
@@ -108,7 +108,6 @@ class ModeledCacheImpl<T> implements TreeCacheListener, ModeledCache<T>
             .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
     }
 
-    @Override
     public Listenable<ModeledCacheListener<T>> listenable()
     {
         return listenerContainer;