Working on strongly typed parameters plus an example that uses it
Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/1fcb63a5 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/1fcb63a5 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/1fcb63a5 Branch: refs/heads/CURATOR-397 Commit: 1fcb63a5c7f29ddbfaedfdd18273ccabff21990e Parents: 26c7adb Author: randgalt <randg...@apache.org> Authored: Tue May 2 17:32:38 2017 -0500 Committer: randgalt <randg...@apache.org> Committed: Tue May 2 17:32:38 2017 -0500 ---------------------------------------------------------------------- .../java/modeled/ModeledCuratorExamples.java | 18 +- .../java/modeled/ModeledCuratorExamplesAlt.java | 8 +- .../src/main/java/modeled/PersonModelSpec.java | 8 +- .../src/main/java/modeledRegistry/Clients.java | 35 -- .../main/java/modeledRegistry/ModelSpecs.java | 37 -- .../src/main/java/modeledRegistry/Paths.java | 17 - .../java/modeledRegistry/RegistryExamples.java | 20 -- .../main/java/modeledRegistry/models/Cache.java | 24 -- .../java/modeledRegistry/models/Database.java | 32 -- .../java/modeledRegistry/models/InstanceId.java | 24 -- .../java/modeledRegistry/models/Server.java | 25 -- .../java/modeledRegistry/models/Session.java | 24 -- .../main/java/modeledRegistry/models/Zone.java | 36 -- .../main/java/pubsub/InstanceSubscriber.java | 36 ++ .../src/main/java/pubsub/MessageSubscriber.java | 37 ++ .../src/main/java/pubsub/Publisher.java | 80 +++++ .../src/main/java/pubsub/SubPubTest.java | 18 + .../src/main/java/pubsub/Subscriber.java | 15 + .../src/main/java/pubsub/builders/Clients.java | 27 ++ .../main/java/pubsub/builders/ModelSpecs.java | 28 ++ .../src/main/java/pubsub/builders/Paths.java | 19 ++ .../java/pubsub/messages/LocationAvailable.java | 26 ++ .../main/java/pubsub/messages/UserCreated.java | 35 ++ .../src/main/java/pubsub/models/Group.java | 29 ++ .../src/main/java/pubsub/models/Instance.java | 52 +++ .../main/java/pubsub/models/InstanceType.java | 9 + .../src/main/java/pubsub/models/Message.java | 38 +++ .../src/main/java/pubsub/models/Priority.java | 8 + .../org/apache/curator/x/async/AsyncStage.java | 6 +- .../x/async/modeled/ModelSpecBuilder.java | 17 +- .../async/modeled/ModeledCuratorFramework.java | 271 --------------- .../modeled/ModeledCuratorFrameworkBuilder.java | 126 ------- .../x/async/modeled/ModeledFramework.java | 283 ++++++++++++++++ .../async/modeled/ModeledFrameworkBuilder.java | 154 +++++++++ .../curator/x/async/modeled/NodeName.java | 16 + .../cached/CachedModeledCuratorFramework.java | 62 ---- .../modeled/cached/CachedModeledFramework.java | 62 ++++ .../CachedModeledCuratorFrameworkImpl.java | 228 ------------- .../details/CachedModeledFrameworkImpl.java | 228 +++++++++++++ .../x/async/modeled/details/ModelSpecImpl.java | 12 +- .../details/ModeledCuratorFrameworkImpl.java | 335 ------------------- .../modeled/details/ModeledFrameworkImpl.java | 335 +++++++++++++++++++ .../x/async/modeled/typed/TypedModelSpec.java | 1 + .../x/async/modeled/typed/TypedModelSpec10.java | 1 + .../x/async/modeled/typed/TypedModelSpec2.java | 1 + .../x/async/modeled/typed/TypedModelSpec3.java | 1 + .../x/async/modeled/typed/TypedModelSpec4.java | 1 + .../x/async/modeled/typed/TypedModelSpec5.java | 1 + .../x/async/modeled/typed/TypedModelSpec6.java | 1 + .../x/async/modeled/typed/TypedModelSpec7.java | 1 + .../x/async/modeled/typed/TypedModelSpec8.java | 1 + .../x/async/modeled/typed/TypedModelSpec9.java | 1 + .../modeled/typed/TypedModeledFramework.java | 32 ++ .../modeled/typed/TypedModeledFramework10.java | 25 ++ .../modeled/typed/TypedModeledFramework2.java | 25 ++ .../modeled/typed/TypedModeledFramework3.java | 25 ++ .../modeled/typed/TypedModeledFramework4.java | 25 ++ .../modeled/typed/TypedModeledFramework5.java | 25 ++ .../modeled/typed/TypedModeledFramework6.java | 25 ++ .../modeled/typed/TypedModeledFramework7.java | 25 ++ .../modeled/typed/TypedModeledFramework8.java | 25 ++ .../modeled/typed/TypedModeledFramework9.java | 25 ++ .../x/async/modeled/typed/TypedZPath.java | 4 +- .../x/async/modeled/typed/TypedZPath10.java | 4 +- .../x/async/modeled/typed/TypedZPath2.java | 4 +- .../x/async/modeled/typed/TypedZPath3.java | 4 +- .../x/async/modeled/typed/TypedZPath4.java | 4 +- .../x/async/modeled/typed/TypedZPath5.java | 4 +- .../x/async/modeled/typed/TypedZPath6.java | 4 +- .../x/async/modeled/typed/TypedZPath7.java | 4 +- .../x/async/modeled/typed/TypedZPath8.java | 4 +- .../x/async/modeled/typed/TypedZPath9.java | 4 +- .../src/site/confluence/index.confluence | 2 +- .../src/site/confluence/modeled.confluence | 8 +- .../modeled/TestModeledCuratorFramework.java | 122 ------- .../x/async/modeled/TestModeledFramework.java | 122 +++++++ .../TestCachedModeledCuratorFramework.java | 96 ------ .../details/TestCachedModeledFramework.java | 96 ++++++ 78 files changed, 2081 insertions(+), 1572 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/modeled/ModeledCuratorExamples.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/modeled/ModeledCuratorExamples.java b/curator-examples/src/main/java/modeled/ModeledCuratorExamples.java index 3e0d140..7bfc131 100644 --- a/curator-examples/src/main/java/modeled/ModeledCuratorExamples.java +++ b/curator-examples/src/main/java/modeled/ModeledCuratorExamples.java @@ -21,13 +21,13 @@ package modeled; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.x.async.modeled.ModelSpec; import org.apache.curator.x.async.modeled.JacksonModelSerializer; -import org.apache.curator.x.async.modeled.ModeledCuratorFramework; +import org.apache.curator.x.async.modeled.ModeledFramework; import org.apache.curator.x.async.modeled.ZPath; import java.util.function.Consumer; public class ModeledCuratorExamples { - public static ModeledCuratorFramework<PersonModel> wrap(CuratorFramework client) + public static ModeledFramework<PersonModel> wrap(CuratorFramework client) { JacksonModelSerializer<PersonModel> serializer = JacksonModelSerializer.build(PersonModel.class); @@ -35,22 +35,22 @@ public class ModeledCuratorExamples ModelSpec<PersonModel> modelSpec = ModelSpec.builder(ZPath.parse("/example/path"), serializer).build(); // wrap a CuratorFramework instance so that it can be used "modeled". - // do this once and re-use the returned ModeledCuratorFramework instance. - // ModeledCuratorFramework instances are tied to a given path - return ModeledCuratorFramework.wrap(client, modelSpec); + // do this once and re-use the returned ModeledFramework instance. + // ModeledFramework instances are tied to a given path + return ModeledFramework.wrap(client, modelSpec); } - public static void createOrUpdate(ModeledCuratorFramework<PersonModel> modeled, PersonModel model) + public static void createOrUpdate(ModeledFramework<PersonModel> modeled, PersonModel model) { // change the affected path to be modeled's base path plus id: i.e. "/example/path/{id}" - ModeledCuratorFramework<PersonModel> atId = modeled.at(model.getId().getId()); + ModeledFramework<PersonModel> atId = modeled.at(model.getId().getId()); - // by default ModeledCuratorFramework instances update the node if it already exists + // by default ModeledFramework instances update the node if it already exists // so this will either create or update the node atId.set(model); // note - this is async } - public static void readPerson(ModeledCuratorFramework<PersonModel> modeled, String id, Consumer<PersonModel> receiver) + public static void readPerson(ModeledFramework<PersonModel> modeled, String id, Consumer<PersonModel> receiver) { // read the person with the given ID and asynchronously call the receiver after it is read modeled.at(id).read().whenComplete((person, exception) -> { http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/modeled/ModeledCuratorExamplesAlt.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/modeled/ModeledCuratorExamplesAlt.java b/curator-examples/src/main/java/modeled/ModeledCuratorExamplesAlt.java index a8d9bcf..859a1f1 100644 --- a/curator-examples/src/main/java/modeled/ModeledCuratorExamplesAlt.java +++ b/curator-examples/src/main/java/modeled/ModeledCuratorExamplesAlt.java @@ -18,7 +18,7 @@ */ package modeled; -import org.apache.curator.x.async.modeled.ModeledCuratorFramework; +import org.apache.curator.x.async.modeled.ModeledFramework; import java.util.function.Consumer; public class ModeledCuratorExamplesAlt @@ -26,16 +26,16 @@ public class ModeledCuratorExamplesAlt public static void createOrUpdate(PersonModelSpec modelSpec, PersonModel model) { // change the affected path to be modeled's base path plus id: i.e. "/example/path/{id}" - ModeledCuratorFramework<PersonModel> resolved = modelSpec.resolved(model.getContainerType(), model.getId()); + ModeledFramework<PersonModel> resolved = modelSpec.resolved(model.getContainerType(), model.getId()); - // by default ModeledCuratorFramework instances update the node if it already exists + // by default ModeledFramework instances update the node if it already exists // so this will either create or update the node resolved.set(model); // note - this is async } public static void readPerson(PersonModelSpec modelSpec, ContainerType containerType, PersonId id, Consumer<PersonModel> receiver) { - ModeledCuratorFramework<PersonModel> resolved = modelSpec.resolved(containerType, id); + ModeledFramework<PersonModel> resolved = modelSpec.resolved(containerType, id); // read the person with the given ID and asynchronously call the receiver after it is read resolved.read().whenComplete((person, exception) -> { http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/modeled/PersonModelSpec.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/modeled/PersonModelSpec.java b/curator-examples/src/main/java/modeled/PersonModelSpec.java index 7e0d821..8230f6e 100644 --- a/curator-examples/src/main/java/modeled/PersonModelSpec.java +++ b/curator-examples/src/main/java/modeled/PersonModelSpec.java @@ -21,7 +21,7 @@ package modeled; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.x.async.modeled.ModelSpec; import org.apache.curator.x.async.modeled.JacksonModelSerializer; -import org.apache.curator.x.async.modeled.ModeledCuratorFramework; +import org.apache.curator.x.async.modeled.ModeledFramework; import org.apache.curator.x.async.modeled.ZPath; public class PersonModelSpec @@ -34,13 +34,13 @@ public class PersonModelSpec this.client = client; JacksonModelSerializer<PersonModel> serializer = JacksonModelSerializer.build(PersonModel.class); - ZPath path = ZPath.from("example", ZPath.parameterNodeName(), "path", ZPath.parameterNodeName()); + ZPath path = ZPath.from("example", ZPath.parameterNodeName, "path", ZPath.parameterNodeName); modelSpec = ModelSpec.builder(path, serializer).build(); } - public ModeledCuratorFramework<PersonModel> resolved(ContainerType containerType, PersonId personId) + public ModeledFramework<PersonModel> resolved(ContainerType containerType, PersonId personId) { ModelSpec<PersonModel> resolved = null;// TODO modelSpec.resolved(containerType.getTypeId(), personId.getId()); - return ModeledCuratorFramework.wrap(client, resolved); + return ModeledFramework.wrap(client, resolved); } } http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/modeledRegistry/Clients.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/modeledRegistry/Clients.java b/curator-examples/src/main/java/modeledRegistry/Clients.java deleted file mode 100644 index e9071e7..0000000 --- a/curator-examples/src/main/java/modeledRegistry/Clients.java +++ /dev/null @@ -1,35 +0,0 @@ -package modeledRegistry; - -import modeledRegistry.models.Cache; -import modeledRegistry.models.Database; -import modeledRegistry.models.InstanceId; -import modeledRegistry.models.Session; -import modeledRegistry.models.Zone; -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.x.async.modeled.ModeledCuratorFramework; - -import static modeledRegistry.ModelSpecs.cacheModelSpec; -import static modeledRegistry.ModelSpecs.databaseModelSpec; -import static modeledRegistry.ModelSpecs.sessionModelSpec; - -public class Clients -{ - public static ModeledCuratorFramework<Cache> cacheClient(CuratorFramework client, Zone zone, InstanceId id) - { - return ModeledCuratorFramework.wrap(client, cacheModelSpec.resolved(zone, id)); - } - - public static ModeledCuratorFramework<Session> sessionClient(CuratorFramework client, Zone zone, InstanceId id) - { - return ModeledCuratorFramework.wrap(client, sessionModelSpec.resolved(zone, id)); - } - - public static ModeledCuratorFramework<Database> databaseClient(CuratorFramework client, Zone zone) - { - return ModeledCuratorFramework.wrap(client, databaseModelSpec.resolved(zone)); - } - - private Clients() - { - } -} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/modeledRegistry/ModelSpecs.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/modeledRegistry/ModelSpecs.java b/curator-examples/src/main/java/modeledRegistry/ModelSpecs.java deleted file mode 100644 index 96469cc..0000000 --- a/curator-examples/src/main/java/modeledRegistry/ModelSpecs.java +++ /dev/null @@ -1,37 +0,0 @@ -package modeledRegistry; - -import modeledRegistry.models.Cache; -import modeledRegistry.models.Database; -import modeledRegistry.models.InstanceId; -import modeledRegistry.models.Session; -import modeledRegistry.models.Zone; -import org.apache.curator.x.async.modeled.JacksonModelSerializer; -import org.apache.curator.x.async.modeled.ModelSpec; -import org.apache.curator.x.async.modeled.typed.TypedModelSpec; -import org.apache.curator.x.async.modeled.typed.TypedModelSpec2; - -import static modeledRegistry.Paths.cachePath; -import static modeledRegistry.Paths.databasePath; -import static modeledRegistry.Paths.sessionPath; - -public class ModelSpecs -{ - public static final TypedModelSpec2<Cache, Zone, InstanceId> cacheModelSpec = TypedModelSpec2.from( - ModelSpec.builder(JacksonModelSerializer.build(Cache.class)).withNodeName(Cache::getId), - cachePath - ); - - public static final TypedModelSpec2<Session, Zone, InstanceId> sessionModelSpec = TypedModelSpec2.from( - ModelSpec.builder(JacksonModelSerializer.build(Session.class)).withNodeName(Session::getId), - sessionPath - ); - - public static final TypedModelSpec<Database, Zone> databaseModelSpec = TypedModelSpec.from( - ModelSpec.builder(JacksonModelSerializer.build(Database.class)).withNodeName(Database::getServerName), - databasePath - ); - - private ModelSpecs() - { - } -} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/modeledRegistry/Paths.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/modeledRegistry/Paths.java b/curator-examples/src/main/java/modeledRegistry/Paths.java deleted file mode 100644 index de23aa4..0000000 --- a/curator-examples/src/main/java/modeledRegistry/Paths.java +++ /dev/null @@ -1,17 +0,0 @@ -package modeledRegistry; - -import modeledRegistry.models.InstanceId; -import modeledRegistry.models.Zone; -import org.apache.curator.x.async.modeled.typed.TypedZPath; -import org.apache.curator.x.async.modeled.typed.TypedZPath2; - -public class Paths -{ - public static final TypedZPath2<Zone, InstanceId> cachePath = TypedZPath2.from("/root/registry/{id}/{id}/caches"); - public static final TypedZPath2<Zone, InstanceId> sessionPath = TypedZPath2.from("/root/registry/{id}/{id}/sessions"); - public static final TypedZPath<Zone> databasePath = TypedZPath.from("/root/registry/{id}/dbs"); - - private Paths() - { - } -} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/modeledRegistry/RegistryExamples.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/modeledRegistry/RegistryExamples.java b/curator-examples/src/main/java/modeledRegistry/RegistryExamples.java deleted file mode 100644 index c344dd9..0000000 --- a/curator-examples/src/main/java/modeledRegistry/RegistryExamples.java +++ /dev/null @@ -1,20 +0,0 @@ -package modeledRegistry; - -import modeledRegistry.models.Database; -import org.apache.curator.x.async.modeled.ModeledCuratorFramework; -import java.util.List; -import java.util.function.Consumer; - -public class RegistryExamples -{ - public static void addDatabase(ModeledCuratorFramework<Database> client, Database database) - { - ModeledCuratorFramework<Database> resolved = client.resolved(database); - resolved.set(database); - } - - public static void getDatabases(ModeledCuratorFramework<Database> client, Consumer<List<Database>> consumer) - { -// client.children().thenCombine(); - } -} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/modeledRegistry/models/Cache.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/modeledRegistry/models/Cache.java b/curator-examples/src/main/java/modeledRegistry/models/Cache.java deleted file mode 100644 index a148a5f..0000000 --- a/curator-examples/src/main/java/modeledRegistry/models/Cache.java +++ /dev/null @@ -1,24 +0,0 @@ -package modeledRegistry.models; - -import java.util.UUID; - -public class Cache extends Server -{ - private final int maxObjects; - - public Cache() - { - this(UUID.randomUUID().toString(), "localhost", Integer.MAX_VALUE); - } - - public Cache(String id, String ipAddress, int maxObjects) - { - super(id, ipAddress); - this.maxObjects = maxObjects; - } - - public int getMaxObjects() - { - return maxObjects; - } -} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/modeledRegistry/models/Database.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/modeledRegistry/models/Database.java b/curator-examples/src/main/java/modeledRegistry/models/Database.java deleted file mode 100644 index 681ed34..0000000 --- a/curator-examples/src/main/java/modeledRegistry/models/Database.java +++ /dev/null @@ -1,32 +0,0 @@ -package modeledRegistry.models; - -import java.util.Objects; -import java.util.UUID; - -public class Database extends Server -{ - private final String connectionString; - private final String serverName; - - public Database() - { - this(UUID.randomUUID().toString(), "localhost", "", ""); - } - - public Database(String id, String ipAddress, String serverName, String connectionString) - { - super(id, ipAddress); - this.serverName = Objects.requireNonNull(serverName, "serverName cannot be null"); - this.connectionString = Objects.requireNonNull(connectionString, "connectionString cannot be null"); - } - - public String getConnectionString() - { - return connectionString; - } - - public String getServerName() - { - return serverName; - } -} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/modeledRegistry/models/InstanceId.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/modeledRegistry/models/InstanceId.java b/curator-examples/src/main/java/modeledRegistry/models/InstanceId.java deleted file mode 100644 index 24ab98e..0000000 --- a/curator-examples/src/main/java/modeledRegistry/models/InstanceId.java +++ /dev/null @@ -1,24 +0,0 @@ -package modeledRegistry.models; - -import java.util.Objects; -import java.util.UUID; - -public class InstanceId -{ - private final String id; - - public InstanceId() - { - this(UUID.randomUUID().toString()); - } - - public InstanceId(String id) - { - this.id = Objects.requireNonNull(id, "id cannot be null"); - } - - public String getId() - { - return id; - } -} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/modeledRegistry/models/Server.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/modeledRegistry/models/Server.java b/curator-examples/src/main/java/modeledRegistry/models/Server.java deleted file mode 100644 index 9085b0f..0000000 --- a/curator-examples/src/main/java/modeledRegistry/models/Server.java +++ /dev/null @@ -1,25 +0,0 @@ -package modeledRegistry.models; - -import java.util.Objects; - -public abstract class Server -{ - private final String id; - private final String ipAddress; - - protected Server(String id, String ipAddress) - { - this.id = Objects.requireNonNull(id, "id cannot be null"); - this.ipAddress = Objects.requireNonNull(ipAddress, "ipAddress cannot be null"); - } - - public String getId() - { - return id; - } - - public String getIpAddress() - { - return ipAddress; - } -} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/modeledRegistry/models/Session.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/modeledRegistry/models/Session.java b/curator-examples/src/main/java/modeledRegistry/models/Session.java deleted file mode 100644 index 230dec2..0000000 --- a/curator-examples/src/main/java/modeledRegistry/models/Session.java +++ /dev/null @@ -1,24 +0,0 @@ -package modeledRegistry.models; - -import java.util.UUID; - -public class Session extends Server -{ - private final long ttl; - - public Session() - { - this(UUID.randomUUID().toString(), "localhost", Long.MAX_VALUE); - } - - public Session(String id, String ipAddress, long ttl) - { - super(id, ipAddress); - this.ttl = ttl; - } - - public long getTtl() - { - return ttl; - } -} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/modeledRegistry/models/Zone.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/modeledRegistry/models/Zone.java b/curator-examples/src/main/java/modeledRegistry/models/Zone.java deleted file mode 100644 index c0f094e..0000000 --- a/curator-examples/src/main/java/modeledRegistry/models/Zone.java +++ /dev/null @@ -1,36 +0,0 @@ -package modeledRegistry.models; - -import java.util.Objects; -import java.util.UUID; - -public class Zone -{ - private final String id; - private final String name; - - public Zone() - { - this(UUID.randomUUID().toString(), ""); - } - - public Zone(String name) - { - this(UUID.randomUUID().toString(), name); - } - - public Zone(String id, String name) - { - this.id = Objects.requireNonNull(id, "id cannot be null"); - this.name = Objects.requireNonNull(name, "name cannot be null"); - } - - public String getId() - { - return id; - } - - public String getName() - { - return name; - } -} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/pubsub/InstanceSubscriber.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/pubsub/InstanceSubscriber.java b/curator-examples/src/main/java/pubsub/InstanceSubscriber.java new file mode 100644 index 0000000..d820014 --- /dev/null +++ b/curator-examples/src/main/java/pubsub/InstanceSubscriber.java @@ -0,0 +1,36 @@ +package pubsub; + +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.listen.Listenable; +import org.apache.curator.x.async.modeled.cached.CachedModeledFramework; +import org.apache.curator.x.async.modeled.cached.ModeledCacheListener; +import pubsub.builders.Clients; +import pubsub.models.Instance; +import pubsub.models.InstanceType; +import java.io.Closeable; + +public class InstanceSubscriber implements Closeable +{ + private final CachedModeledFramework<Instance> client; + + public InstanceSubscriber(CuratorFramework client, InstanceType instanceType) + { + this.client = Clients.instanceClient.resolved(client, instanceType).cached(); + } + + public Listenable<ModeledCacheListener<Instance>> listenable() + { + return client.getCache().listenable(); + } + + public void start() + { + client.start(); + } + + @Override + public void close() + { + client.close(); + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/pubsub/MessageSubscriber.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/pubsub/MessageSubscriber.java b/curator-examples/src/main/java/pubsub/MessageSubscriber.java new file mode 100644 index 0000000..64ba867 --- /dev/null +++ b/curator-examples/src/main/java/pubsub/MessageSubscriber.java @@ -0,0 +1,37 @@ +package pubsub; + +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.listen.Listenable; +import org.apache.curator.x.async.modeled.cached.CachedModeledFramework; +import org.apache.curator.x.async.modeled.cached.ModeledCacheListener; +import pubsub.builders.Clients; +import pubsub.models.Group; +import pubsub.models.Message; +import pubsub.models.Priority; +import java.io.Closeable; + +public class MessageSubscriber implements Closeable +{ + private final CachedModeledFramework<Message> client; + + public MessageSubscriber(CuratorFramework client, Group group, Priority priority) + { + this.client = Clients.messageClient.resolved(client, group, priority).cached(); + } + + public Listenable<ModeledCacheListener<Message>> listenable() + { + return client.getCache().listenable(); + } + + public void start() + { + client.start(); + } + + @Override + public void close() + { + client.close(); + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/pubsub/Publisher.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/pubsub/Publisher.java b/curator-examples/src/main/java/pubsub/Publisher.java new file mode 100644 index 0000000..b86d2a2 --- /dev/null +++ b/curator-examples/src/main/java/pubsub/Publisher.java @@ -0,0 +1,80 @@ +package pubsub; + +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.api.transaction.CuratorOp; +import org.apache.curator.x.async.AsyncCuratorFramework; +import org.apache.curator.x.async.modeled.ModeledFramework; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import pubsub.models.Group; +import pubsub.models.Instance; +import pubsub.models.Message; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +import static pubsub.builders.Clients.instanceClient; +import static pubsub.builders.Clients.messageClient; + +public class Publisher +{ + private final Logger log = LoggerFactory.getLogger(getClass()); + private final AsyncCuratorFramework client; + + public Publisher(CuratorFramework client) + { + this.client = AsyncCuratorFramework.wrap(Objects.requireNonNull(client, "client cannot be null")); + } + + public void publishInstance(Instance instance) + { + ModeledFramework<Instance> resolvedClient = instanceClient + .resolved(client.unwrap(), instance.getType()) + .resolved(instance); + resolvedClient.set(instance).exceptionally(e -> { + log.error("Could not publish instance: " + instance, e); + return null; + }); + } + + public void publishInstances(List<Instance> instances) + { + List<CuratorOp> operations = instances.stream() + .map(instance -> instanceClient + .resolved(client.unwrap(), instance.getType()) + .resolved(instance) + .createOp(instance) + ) + .collect(Collectors.toList()); + client.transaction().forOperations(operations).exceptionally(e -> { + log.error("Could not publish instances: " + instances, e); + return null; + }); + } + + public void publishMessage(Message message, Group group) + { + ModeledFramework<Message> resolvedClient = messageClient + .resolved(client.unwrap(), group, message.getPriority()) + .resolved(message); + resolvedClient.set(message).exceptionally(e -> { + log.error("Could not publish message: " + message, e); + return null; + }); + } + + public void publishMessages(List<Message> messages, Group group) + { + List<CuratorOp> operations = messages.stream() + .map(message -> messageClient + .resolved(client.unwrap(), group, message.getPriority()) + .resolved(message) + .createOp(message) + ) + .collect(Collectors.toList()); + client.transaction().forOperations(operations).exceptionally(e -> { + log.error("Could not publish messages: " + messages, e); + return null; + }); + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/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 new file mode 100644 index 0000000..0ba638f --- /dev/null +++ b/curator-examples/src/main/java/pubsub/SubPubTest.java @@ -0,0 +1,18 @@ +package pubsub; + +import org.apache.curator.test.TestingServer; + +public class SubPubTest +{ + private final TestingServer testingServer; + + public static void main(String[] args) + { + + } + + public SubPubTest() throws Exception + { + this.testingServer = new TestingServer(); + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/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 new file mode 100644 index 0000000..ea6de01 --- /dev/null +++ b/curator-examples/src/main/java/pubsub/Subscriber.java @@ -0,0 +1,15 @@ +package pubsub; + +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.x.async.modeled.cached.CachedModeledFramework; +import pubsub.messages.LocationAvailable; + +public class Subscriber +{ + private final CuratorFramework client; + + public Subscriber(CuratorFramework client) + { + this.client = client; + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/pubsub/builders/Clients.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/pubsub/builders/Clients.java b/curator-examples/src/main/java/pubsub/builders/Clients.java new file mode 100644 index 0000000..e2b1c89 --- /dev/null +++ b/curator-examples/src/main/java/pubsub/builders/Clients.java @@ -0,0 +1,27 @@ +package pubsub.builders; + +import org.apache.curator.x.async.modeled.ModeledFramework; +import org.apache.curator.x.async.modeled.typed.TypedModeledFramework; +import org.apache.curator.x.async.modeled.typed.TypedModeledFramework2; +import pubsub.models.Group; +import pubsub.models.Instance; +import pubsub.models.InstanceType; +import pubsub.models.Message; +import pubsub.models.Priority; + +public class Clients +{ + public static final TypedModeledFramework2<Message, Group, Priority> messageClient = TypedModeledFramework2.from( + ModeledFramework.builder(), + ModelSpecs.messageModelSpec + ); + + public static final TypedModeledFramework<Instance, InstanceType> instanceClient = TypedModeledFramework.from( + ModeledFramework.builder(), + ModelSpecs.instanceModelSpec + ); + + private Clients() + { + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/pubsub/builders/ModelSpecs.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/pubsub/builders/ModelSpecs.java b/curator-examples/src/main/java/pubsub/builders/ModelSpecs.java new file mode 100644 index 0000000..83cdfe4 --- /dev/null +++ b/curator-examples/src/main/java/pubsub/builders/ModelSpecs.java @@ -0,0 +1,28 @@ +package pubsub.builders; + +import org.apache.curator.x.async.modeled.JacksonModelSerializer; +import org.apache.curator.x.async.modeled.ModelSpec; +import org.apache.curator.x.async.modeled.typed.TypedModelSpec; +import org.apache.curator.x.async.modeled.typed.TypedModelSpec2; +import pubsub.models.Group; +import pubsub.models.Instance; +import pubsub.models.InstanceType; +import pubsub.models.Message; +import pubsub.models.Priority; + +public class ModelSpecs +{ + public static final TypedModelSpec2<Message, Group, Priority> messageModelSpec = TypedModelSpec2.from( + ModelSpec.builder(JacksonModelSerializer.build(Message.class)), + Paths.messagesPath + ); + + public static final TypedModelSpec<Instance, InstanceType> instanceModelSpec = TypedModelSpec.from( + ModelSpec.builder(JacksonModelSerializer.build(Instance.class)), + Paths.instancesPath + ); + + private ModelSpecs() + { + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/pubsub/builders/Paths.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/pubsub/builders/Paths.java b/curator-examples/src/main/java/pubsub/builders/Paths.java new file mode 100644 index 0000000..0db5138 --- /dev/null +++ b/curator-examples/src/main/java/pubsub/builders/Paths.java @@ -0,0 +1,19 @@ +package pubsub.builders; + +import org.apache.curator.x.async.modeled.typed.TypedZPath; +import org.apache.curator.x.async.modeled.typed.TypedZPath2; +import pubsub.models.Group; +import pubsub.models.InstanceType; +import pubsub.models.Priority; + +public class Paths +{ + private static final String basePath = "/root/pubsub"; + + public static final TypedZPath2<Group, Priority> messagesPath = TypedZPath2.from(basePath + "/messages/{id}/{id}"); + public static final TypedZPath<InstanceType> instancesPath = TypedZPath.from(basePath + "/instances/{id}"); + + private Paths() + { + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/pubsub/messages/LocationAvailable.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/pubsub/messages/LocationAvailable.java b/curator-examples/src/main/java/pubsub/messages/LocationAvailable.java new file mode 100644 index 0000000..503e4ed --- /dev/null +++ b/curator-examples/src/main/java/pubsub/messages/LocationAvailable.java @@ -0,0 +1,26 @@ +package pubsub.messages; + +import pubsub.models.Message; +import pubsub.models.Priority; +import java.time.Duration; +import java.util.Objects; + +public class LocationAvailable extends Message +{ + private final String name; + private final Duration availableUntil; + + public LocationAvailable(Priority priority, String name, Duration availableUntil) + { + super(priority); + this.name = Objects.requireNonNull(name, "name cannot be null"); + this.availableUntil = Objects.requireNonNull(availableUntil, "availableUntil cannot be null"); + } + + public LocationAvailable(String id, Priority priority, String name, Duration availableUntil) + { + super(id, priority); + this.name = Objects.requireNonNull(name, "name cannot be null"); + this.availableUntil = Objects.requireNonNull(availableUntil, "availableUntil cannot be null"); + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/pubsub/messages/UserCreated.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/pubsub/messages/UserCreated.java b/curator-examples/src/main/java/pubsub/messages/UserCreated.java new file mode 100644 index 0000000..da7e639 --- /dev/null +++ b/curator-examples/src/main/java/pubsub/messages/UserCreated.java @@ -0,0 +1,35 @@ +package pubsub.messages; + +import pubsub.models.Message; +import pubsub.models.Priority; +import java.util.Objects; + +public class UserCreated extends Message +{ + private final String name; + private final String position; + + public UserCreated(Priority priority, String name, String position) + { + super(priority); + this.name = Objects.requireNonNull(name, "name cannot be null"); + this.position = Objects.requireNonNull(position, "position cannot be null"); + } + + public UserCreated(String id, Priority priority, String name, String position) + { + super(id, priority); + this.name = Objects.requireNonNull(name, "name cannot be null"); + this.position = Objects.requireNonNull(position, "position cannot be null"); + } + + public String getName() + { + return name; + } + + public String getPosition() + { + return position; + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/pubsub/models/Group.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/pubsub/models/Group.java b/curator-examples/src/main/java/pubsub/models/Group.java new file mode 100644 index 0000000..a9636a4 --- /dev/null +++ b/curator-examples/src/main/java/pubsub/models/Group.java @@ -0,0 +1,29 @@ +package pubsub.models; + +import org.apache.curator.x.async.modeled.NodeName; + +public class Group implements NodeName +{ + private final String groupName; + + public Group() + { + this(""); + } + + public Group(String groupName) + { + this.groupName = groupName; + } + + public String getGroupName() + { + return groupName; + } + + @Override + public String nodeName() + { + return groupName; + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/pubsub/models/Instance.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/pubsub/models/Instance.java b/curator-examples/src/main/java/pubsub/models/Instance.java new file mode 100644 index 0000000..d674317 --- /dev/null +++ b/curator-examples/src/main/java/pubsub/models/Instance.java @@ -0,0 +1,52 @@ +package pubsub.models; + +import org.apache.curator.x.async.modeled.NodeName; +import java.util.Objects; +import java.util.UUID; + +public class Instance implements NodeName +{ + private final String id; + private final InstanceType type; + private final String hostname; + private final int port; + + public Instance() + { + this(UUID.randomUUID().toString(), InstanceType.proxy, "", 0); + } + + public Instance(String id, InstanceType type, String hostname, int port) + { + this.id = Objects.requireNonNull(id, "id cannot be null"); + this.type = Objects.requireNonNull(type, "type cannot be null"); + this.hostname = Objects.requireNonNull(hostname, "hostname cannot be null"); + this.port = port; + } + + public String getId() + { + return id; + } + + public InstanceType getType() + { + return type; + } + + public String getHostname() + { + return hostname; + } + + public int getPort() + { + return port; + } + + @Override + public String nodeName() + { + return id; + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/pubsub/models/InstanceType.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/pubsub/models/InstanceType.java b/curator-examples/src/main/java/pubsub/models/InstanceType.java new file mode 100644 index 0000000..f1daea0 --- /dev/null +++ b/curator-examples/src/main/java/pubsub/models/InstanceType.java @@ -0,0 +1,9 @@ +package pubsub.models; + +public enum InstanceType +{ + database, + cache, + web, + proxy +} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/pubsub/models/Message.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/pubsub/models/Message.java b/curator-examples/src/main/java/pubsub/models/Message.java new file mode 100644 index 0000000..27a0268 --- /dev/null +++ b/curator-examples/src/main/java/pubsub/models/Message.java @@ -0,0 +1,38 @@ +package pubsub.models; + +import org.apache.curator.x.async.modeled.NodeName; +import java.util.Objects; +import java.util.UUID; + +public abstract class Message implements NodeName +{ + private final String id; + private final Priority priority; + + protected Message(Priority priority) + { + this(UUID.randomUUID().toString(), priority); + } + + protected Message(String id, Priority priority) + { + this.id = Objects.requireNonNull(id, "id cannot be null"); + this.priority = Objects.requireNonNull(priority, "messageType cannot be null"); + } + + public String getId() + { + return id; + } + + public Priority getPriority() + { + return priority; + } + + @Override + public String nodeName() + { + return id; + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-examples/src/main/java/pubsub/models/Priority.java ---------------------------------------------------------------------- diff --git a/curator-examples/src/main/java/pubsub/models/Priority.java b/curator-examples/src/main/java/pubsub/models/Priority.java new file mode 100644 index 0000000..ea8051e --- /dev/null +++ b/curator-examples/src/main/java/pubsub/models/Priority.java @@ -0,0 +1,8 @@ +package pubsub.models; + +public enum Priority +{ + low, + medium, + high +} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-x-async/src/main/java/org/apache/curator/x/async/AsyncStage.java ---------------------------------------------------------------------- diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/AsyncStage.java b/curator-x-async/src/main/java/org/apache/curator/x/async/AsyncStage.java index 331cd16..ad7547b 100644 --- a/curator-x-async/src/main/java/org/apache/curator/x/async/AsyncStage.java +++ b/curator-x-async/src/main/java/org/apache/curator/x/async/AsyncStage.java @@ -34,9 +34,9 @@ public interface AsyncStage<T> extends CompletionStage<T> * </p> * * <p> - * Also, applies to {@link org.apache.curator.x.async.modeled.ModeledCuratorFramework} - * when {@link org.apache.curator.x.async.modeled.ModeledCuratorFrameworkBuilder#watched(WatchMode)} - * or {@link org.apache.curator.x.async.modeled.ModeledCuratorFrameworkBuilder#watched(WatchMode, java.util.function.UnaryOperator)} + * Also, applies to {@link org.apache.curator.x.async.modeled.ModeledFramework} + * when {@link org.apache.curator.x.async.modeled.ModeledFrameworkBuilder#watched(WatchMode)} + * or {@link org.apache.curator.x.async.modeled.ModeledFrameworkBuilder#watched(WatchMode, java.util.function.UnaryOperator)} * is used. * </p> * http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModelSpecBuilder.java ---------------------------------------------------------------------- diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModelSpecBuilder.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModelSpecBuilder.java index 16e7696..2ac2501 100644 --- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModelSpecBuilder.java +++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModelSpecBuilder.java @@ -28,7 +28,6 @@ import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Set; -import java.util.function.Function; public class ModelSpecBuilder<T> { @@ -38,7 +37,6 @@ public class ModelSpecBuilder<T> private List<ACL> aclList = Collections.emptyList(); private Set<CreateOption> createOptions = Collections.emptySet(); private Set<DeleteOption> deleteOptions = Collections.emptySet(); - private Function<T, String> nodeName = Object::toString; /** * Build a new ModelSpec instance @@ -47,7 +45,7 @@ public class ModelSpecBuilder<T> */ public ModelSpec<T> build() { - return new ModelSpecImpl<>(path, serializer, createMode, aclList, createOptions, deleteOptions, nodeName); + return new ModelSpecImpl<>(path, serializer, createMode, aclList, createOptions, deleteOptions); } /** @@ -99,19 +97,6 @@ public class ModelSpecBuilder<T> } /** - * Functor that returns the node name to use for a model instance. Default is to call - * <code>toString()</code> on the model instance. - * - * @param nodeName naming functor - * @return this for chaining - */ - public ModelSpecBuilder<T> withNodeName(Function<T, String> nodeName) - { - this.nodeName = Objects.requireNonNull(nodeName, "nodeName cannot be null"); - return this; - } - - /** * Change the model spec's path * * @param path new path http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFramework.java ---------------------------------------------------------------------- diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFramework.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFramework.java deleted file mode 100644 index 85d0e30..0000000 --- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFramework.java +++ /dev/null @@ -1,271 +0,0 @@ -/** - * 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; - -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.api.transaction.CuratorOp; -import org.apache.curator.framework.api.transaction.CuratorTransactionResult; -import org.apache.curator.x.async.AsyncStage; -import org.apache.curator.x.async.modeled.cached.CachedModeledCuratorFramework; -import org.apache.zookeeper.data.Stat; -import java.util.List; - -public interface ModeledCuratorFramework<T> -{ - /** - * Return a new ModeledCuratorFramework for the given model - * - * @param client Curator client - * @param model the model - * @return new Modeled Curator instance - */ - static <T> ModeledCuratorFramework<T> wrap(CuratorFramework client, ModelSpec<T> model) - { - return builder(client, model).build(); - } - - /** - * Start a new ModeledCuratorFrameworkBuilder for the given model - * - * @param client Curator client - * @param model the model - * @return builder - */ - static <T> ModeledCuratorFrameworkBuilder<T> builder(CuratorFramework client, ModelSpec<T> model) - { - return new ModeledCuratorFrameworkBuilder<>(client, model); - } - - /** - * Use an internally created cache as a front for this modeled instance. All read APIs check the cache - * first and, if available, return the values from the cache. Note: you must call - * {@link org.apache.curator.x.async.modeled.cached.CachedModeledCuratorFramework#start()} and - * {@link CachedModeledCuratorFramework#close()} to start/stop - * - * @return wrapped instance - */ - CachedModeledCuratorFramework<T> cached(); - - /** - * Returns the client that was originally passed to {@link #wrap(org.apache.curator.framework.CuratorFramework, ModelSpec)} or - * the builder. - * - * @return original client - */ - CuratorFramework unwrap(); - - /** - * Return the model being used - * - * @return model - */ - ModelSpec<T> modelSpec(); - - /** - * Return a new Modeled Curator instance with all the same options but applying to the given child node of this Modeled Curator's - * path. E.g. if this Modeled Curator instance applies to "/a/b", calling <code>modeled.at("c")</code> returns an instance that applies to - * "/a/b/c". - * - * @param child child node. - * @return new Modeled Curator instance - */ - ModeledCuratorFramework<T> at(String child); - - /** - * Return a Modeled Curator instance with all the same options but using the given path. - * - * @param path new path - * @return new Modeled Curator instance - */ - ModeledCuratorFramework<T> at(ZPath path); - - /** - * Return a new Modeled Curator instance with all the same options but using the - * {@link ModelSpecBuilder#nodeName} functor - * to generate the child node's name - * - * @param model model to use to generate the name - * @return new Modeled Curator instance - */ - ModeledCuratorFramework<T> resolved(T model); - - /** - * Create (or update depending on build options) a ZNode at this instance's path with a serialized - * version of the given model - * - * @param model model to write - * @return AsyncStage - * @see org.apache.curator.x.async.AsyncStage - */ - AsyncStage<String> set(T model); - - /** - * Create (or update depending on build options) a ZNode at this instance's path with a serialized - * form of the given model - * - * @param model model to write - * @param storingStatIn the stat for the new ZNode is stored here - * @return AsyncStage - * @see org.apache.curator.x.async.AsyncStage - */ - AsyncStage<String> set(T model, Stat storingStatIn); - - /** - * Read the ZNode at this instance's path and deserialize into a model - * - * @return AsyncStage - * @see org.apache.curator.x.async.AsyncStage - */ - AsyncStage<T> read(); - - /** - * Read the ZNode at this instance's path and deserialize into a model - * - * @param storingStatIn the stat for the new ZNode is stored here - * @return AsyncStage - * @see org.apache.curator.x.async.AsyncStage - */ - AsyncStage<T> read(Stat storingStatIn); - - /** - * Update the ZNode at this instance's path with a serialized - * form of the given model passing "-1" for the update version - * - * @param model model to write - * @return AsyncStage - * @see org.apache.curator.x.async.AsyncStage - */ - AsyncStage<Stat> update(T model); - - /** - * Update the ZNode at this instance's path with a serialized - * form of the given model passing the given update version - * - * @param model model to write - * @param version update version to use - * @return AsyncStage - * @see org.apache.curator.x.async.AsyncStage - */ - AsyncStage<Stat> update(T model, int version); - - /** - * Delete the ZNode at this instance's path passing -1 for the delete version - * - * @return AsyncStage - * @see org.apache.curator.x.async.AsyncStage - */ - AsyncStage<Void> delete(); - - /** - * Delete the ZNode at this instance's path passing the given delete version - * - * @param version update version to use - * @return AsyncStage - * @see org.apache.curator.x.async.AsyncStage - */ - AsyncStage<Void> delete(int version); - - /** - * Check to see if the ZNode at this instance's path exists - * - * @return AsyncStage - * @see org.apache.curator.x.async.AsyncStage - */ - AsyncStage<Stat> checkExists(); - - /** - * Return the child paths of this instance's path (in no particular order) - * - * @return AsyncStage - * @see org.apache.curator.x.async.AsyncStage - */ - AsyncStage<List<ZPath>> children(); - - /** - * Create operation instance that can be passed among other operations to - * {@link #inTransaction(java.util.List)} to be executed as a single transaction. Note: - * due to ZooKeeper transaction limits, this is a _not_ a "set or update" operation but only - * a create operation and will generate an error if the node already exists. - * - * @param model the model - * @return operation - */ - CuratorOp createOp(T model); - - /** - * Update operation instance that can be passed among other operations to - * {@link #inTransaction(java.util.List)} to be executed as a single transaction. - * - * @param model the model - * @return operation - */ - CuratorOp updateOp(T model); - - /** - * Create operation instance that can be passed among other operations to - * {@link #inTransaction(java.util.List)} to be executed as a single transaction. - * - * @param model the model - * @param version update version to use - * @return operation - */ - CuratorOp updateOp(T model, int version); - - /** - * Delete operation instance that can be passed among other operations to - * {@link #inTransaction(java.util.List)} to be executed as a single transaction. - * - * @return operation - */ - CuratorOp deleteOp(); - - /** - * Delete operation instance that can be passed among other operations to - * {@link #inTransaction(java.util.List)} to be executed as a single transaction. - * - * @param version delete version to use - * @return operation - */ - CuratorOp deleteOp(int version); - - /** - * Check exists operation instance that can be passed among other operations to - * {@link #inTransaction(java.util.List)} to be executed as a single transaction. - * - * @return operation - */ - CuratorOp checkExistsOp(); - - /** - * Check exists operation instance that can be passed among other operations to - * {@link #inTransaction(java.util.List)} to be executed as a single transaction. - * - * @param version version to use - * @return operation - */ - CuratorOp checkExistsOp(int version); - - /** - * Invoke ZooKeeper to commit the given operations as a single transaction. - * - * @param operations operations that make up the transaction. - * @return AsyncStage instance for managing the completion - */ - AsyncStage<List<CuratorTransactionResult>> inTransaction(List<CuratorOp> operations); -} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFrameworkBuilder.java ---------------------------------------------------------------------- diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFrameworkBuilder.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFrameworkBuilder.java deleted file mode 100644 index 37224ff..0000000 --- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledCuratorFrameworkBuilder.java +++ /dev/null @@ -1,126 +0,0 @@ -/** - * 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; - -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.api.CuratorEvent; -import org.apache.curator.framework.api.UnhandledErrorListener; -import org.apache.curator.x.async.WatchMode; -import org.apache.curator.x.async.modeled.details.ModeledCuratorFrameworkImpl; -import org.apache.zookeeper.WatchedEvent; -import java.util.Objects; -import java.util.function.UnaryOperator; - -public class ModeledCuratorFrameworkBuilder<T> -{ - private final CuratorFramework client; - private final ModelSpec<T> model; - private WatchMode watchMode; - private UnaryOperator<WatchedEvent> watcherFilter; - private UnhandledErrorListener unhandledErrorListener; - private UnaryOperator<CuratorEvent> resultFilter; - - /** - * Build a new ModeledCuratorFramework instance - * - * @return new ModeledCuratorFramework instance - */ - public ModeledCuratorFramework<T> build() - { - return ModeledCuratorFrameworkImpl.build( - client, - model, - watchMode, - watcherFilter, - unhandledErrorListener, - resultFilter - ); - } - - /** - * Add watchers as appropriate to the Modeled Curator's ZNode using - * {@link org.apache.curator.x.async.WatchMode#stateChangeAndSuccess} - * - * @return this for chaining - * @see org.apache.curator.x.async.AsyncStage#event() - */ - public ModeledCuratorFrameworkBuilder<T> watched() - { - this.watchMode = WatchMode.stateChangeAndSuccess; - return this; - } - - /** - * Add watchers as appropriate using the given watchMode to the Modeled Curator's ZNode - * - * @param watchMode watcher style - * @return this for chaining - * @see org.apache.curator.x.async.AsyncStage#event() - */ - public ModeledCuratorFrameworkBuilder<T> watched(WatchMode watchMode) - { - this.watchMode = watchMode; - return this; - } - - /** - * Add watchers as appropriate using the given watchMode and filter to the Modeled Curator's ZNode - * - * @param watchMode watcher style - * @param watcherFilter filter - * @return this for chaining - * @see org.apache.curator.x.async.AsyncStage#event() - */ - public ModeledCuratorFrameworkBuilder<T> watched(WatchMode watchMode, UnaryOperator<WatchedEvent> watcherFilter) - { - this.watchMode = watchMode; - this.watcherFilter = watcherFilter; - return this; - } - - /** - * Use the given unhandledErrorListener for operations on the Modeled Curator's ZNode - * - * @param unhandledErrorListener listener - * @return this for chaining - */ - public ModeledCuratorFrameworkBuilder<T> withUnhandledErrorListener(UnhandledErrorListener unhandledErrorListener) - { - this.unhandledErrorListener = unhandledErrorListener; - return this; - } - - /** - * Use the given result filter for operations on the Modeled Curator's ZNode - * - * @param resultFilter filter - * @return this for chaining - */ - public ModeledCuratorFrameworkBuilder<T> withResultFilter(UnaryOperator<CuratorEvent> resultFilter) - { - this.resultFilter = resultFilter; - return this; - } - - ModeledCuratorFrameworkBuilder(CuratorFramework client, ModelSpec<T> model) - { - this.client = Objects.requireNonNull(client, "client cannot be null"); - this.model = Objects.requireNonNull(model, "model cannot be null"); - } -} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledFramework.java ---------------------------------------------------------------------- diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledFramework.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledFramework.java new file mode 100644 index 0000000..7b88625 --- /dev/null +++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledFramework.java @@ -0,0 +1,283 @@ +/** + * 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; + +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.api.transaction.CuratorOp; +import org.apache.curator.framework.api.transaction.CuratorTransactionResult; +import org.apache.curator.x.async.AsyncStage; +import org.apache.curator.x.async.modeled.cached.CachedModeledFramework; +import org.apache.zookeeper.data.Stat; +import java.util.List; + +public interface ModeledFramework<T> +{ + /** + * Return a new ModeledFramework for the given model + * + * @param client Curator client + * @param model the model + * @return new Modeled Curator instance + */ + static <T> ModeledFramework<T> wrap(CuratorFramework client, ModelSpec<T> model) + { + return builder(client, model).build(); + } + + /** + * Start a new ModeledFrameworkBuilder for the given model + * + * @param client Curator client + * @param model the model + * @return builder + */ + static <T> ModeledFrameworkBuilder<T> builder(CuratorFramework client, ModelSpec<T> model) + { + return new ModeledFrameworkBuilder<>(client, model); + } + + /** + * Start a new ModeledFrameworkBuilder. A client and model must be provided prior to the instance + * being built via {@link org.apache.curator.x.async.modeled.ModeledFrameworkBuilder#withClient(org.apache.curator.framework.CuratorFramework)} + * and {@link org.apache.curator.x.async.modeled.ModeledFrameworkBuilder#withModelSpec(ModelSpec)} + * + * @return builder + */ + static <T> ModeledFrameworkBuilder<T> builder() + { + return new ModeledFrameworkBuilder<>(); + } + + /** + * Use an internally created cache as a front for this modeled instance. All read APIs check the cache + * first and, if available, return the values from the cache. Note: you must call + * {@link org.apache.curator.x.async.modeled.cached.CachedModeledFramework#start()} and + * {@link org.apache.curator.x.async.modeled.cached.CachedModeledFramework#close()} to start/stop + * + * @return wrapped instance + */ + CachedModeledFramework<T> cached(); + + /** + * Returns the client that was originally passed to {@link #wrap(org.apache.curator.framework.CuratorFramework, ModelSpec)} or + * the builder. + * + * @return original client + */ + CuratorFramework unwrap(); + + /** + * Return the model being used + * + * @return model + */ + ModelSpec<T> modelSpec(); + + /** + * Return a new Modeled Curator instance with all the same options but applying to the given child node of this Modeled Curator's + * path. E.g. if this Modeled Curator instance applies to "/a/b", calling <code>modeled.at("c")</code> returns an instance that applies to + * "/a/b/c". + * + * @param child child node. + * @return new Modeled Curator instance + */ + ModeledFramework<T> at(String child); + + /** + * Return a Modeled Curator instance with all the same options but using the given path. + * + * @param path new path + * @return new Modeled Curator instance + */ + ModeledFramework<T> at(ZPath path); + + /** + * Return a new Modeled Curator instance with all the same options but using the + * {@link ModelSpecBuilder#nodeName} functor + * to generate the child node's name + * + * @param model model to use to generate the name + * @return new Modeled Curator instance + */ + ModeledFramework<T> resolved(T model); + + /** + * Create (or update depending on build options) a ZNode at this instance's path with a serialized + * version of the given model + * + * @param model model to write + * @return AsyncStage + * @see org.apache.curator.x.async.AsyncStage + */ + AsyncStage<String> set(T model); + + /** + * Create (or update depending on build options) a ZNode at this instance's path with a serialized + * form of the given model + * + * @param model model to write + * @param storingStatIn the stat for the new ZNode is stored here + * @return AsyncStage + * @see org.apache.curator.x.async.AsyncStage + */ + AsyncStage<String> set(T model, Stat storingStatIn); + + /** + * Read the ZNode at this instance's path and deserialize into a model + * + * @return AsyncStage + * @see org.apache.curator.x.async.AsyncStage + */ + AsyncStage<T> read(); + + /** + * Read the ZNode at this instance's path and deserialize into a model + * + * @param storingStatIn the stat for the new ZNode is stored here + * @return AsyncStage + * @see org.apache.curator.x.async.AsyncStage + */ + AsyncStage<T> read(Stat storingStatIn); + + /** + * Update the ZNode at this instance's path with a serialized + * form of the given model passing "-1" for the update version + * + * @param model model to write + * @return AsyncStage + * @see org.apache.curator.x.async.AsyncStage + */ + AsyncStage<Stat> update(T model); + + /** + * Update the ZNode at this instance's path with a serialized + * form of the given model passing the given update version + * + * @param model model to write + * @param version update version to use + * @return AsyncStage + * @see org.apache.curator.x.async.AsyncStage + */ + AsyncStage<Stat> update(T model, int version); + + /** + * Delete the ZNode at this instance's path passing -1 for the delete version + * + * @return AsyncStage + * @see org.apache.curator.x.async.AsyncStage + */ + AsyncStage<Void> delete(); + + /** + * Delete the ZNode at this instance's path passing the given delete version + * + * @param version update version to use + * @return AsyncStage + * @see org.apache.curator.x.async.AsyncStage + */ + AsyncStage<Void> delete(int version); + + /** + * Check to see if the ZNode at this instance's path exists + * + * @return AsyncStage + * @see org.apache.curator.x.async.AsyncStage + */ + AsyncStage<Stat> checkExists(); + + /** + * Return the child paths of this instance's path (in no particular order) + * + * @return AsyncStage + * @see org.apache.curator.x.async.AsyncStage + */ + AsyncStage<List<ZPath>> children(); + + /** + * Create operation instance that can be passed among other operations to + * {@link #inTransaction(java.util.List)} to be executed as a single transaction. Note: + * due to ZooKeeper transaction limits, this is a _not_ a "set or update" operation but only + * a create operation and will generate an error if the node already exists. + * + * @param model the model + * @return operation + */ + CuratorOp createOp(T model); + + /** + * Update operation instance that can be passed among other operations to + * {@link #inTransaction(java.util.List)} to be executed as a single transaction. + * + * @param model the model + * @return operation + */ + CuratorOp updateOp(T model); + + /** + * Create operation instance that can be passed among other operations to + * {@link #inTransaction(java.util.List)} to be executed as a single transaction. + * + * @param model the model + * @param version update version to use + * @return operation + */ + CuratorOp updateOp(T model, int version); + + /** + * Delete operation instance that can be passed among other operations to + * {@link #inTransaction(java.util.List)} to be executed as a single transaction. + * + * @return operation + */ + CuratorOp deleteOp(); + + /** + * Delete operation instance that can be passed among other operations to + * {@link #inTransaction(java.util.List)} to be executed as a single transaction. + * + * @param version delete version to use + * @return operation + */ + CuratorOp deleteOp(int version); + + /** + * Check exists operation instance that can be passed among other operations to + * {@link #inTransaction(java.util.List)} to be executed as a single transaction. + * + * @return operation + */ + CuratorOp checkExistsOp(); + + /** + * Check exists operation instance that can be passed among other operations to + * {@link #inTransaction(java.util.List)} to be executed as a single transaction. + * + * @param version version to use + * @return operation + */ + CuratorOp checkExistsOp(int version); + + /** + * Invoke ZooKeeper to commit the given operations as a single transaction. + * + * @param operations operations that make up the transaction. + * @return AsyncStage instance for managing the completion + */ + AsyncStage<List<CuratorTransactionResult>> inTransaction(List<CuratorOp> operations); +} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledFrameworkBuilder.java ---------------------------------------------------------------------- diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledFrameworkBuilder.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledFrameworkBuilder.java new file mode 100644 index 0000000..d2c31b6 --- /dev/null +++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/ModeledFrameworkBuilder.java @@ -0,0 +1,154 @@ +/** + * 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; + +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.api.CuratorEvent; +import org.apache.curator.framework.api.UnhandledErrorListener; +import org.apache.curator.x.async.WatchMode; +import org.apache.curator.x.async.modeled.details.ModeledFrameworkImpl; +import org.apache.zookeeper.WatchedEvent; +import java.util.Objects; +import java.util.function.UnaryOperator; + +public class ModeledFrameworkBuilder<T> +{ + private CuratorFramework client; + private ModelSpec<T> modelSpec; + private WatchMode watchMode; + private UnaryOperator<WatchedEvent> watcherFilter; + private UnhandledErrorListener unhandledErrorListener; + private UnaryOperator<CuratorEvent> resultFilter; + + /** + * Build a new ModeledFramework instance + * + * @return new ModeledFramework instance + */ + public ModeledFramework<T> build() + { + return ModeledFrameworkImpl.build( + client, + modelSpec, + watchMode, + watcherFilter, + unhandledErrorListener, + resultFilter + ); + } + + /** + * Add watchers as appropriate to the Modeled Curator's ZNode using + * {@link org.apache.curator.x.async.WatchMode#stateChangeAndSuccess} + * + * @return this for chaining + * @see org.apache.curator.x.async.AsyncStage#event() + */ + public ModeledFrameworkBuilder<T> watched() + { + this.watchMode = WatchMode.stateChangeAndSuccess; + return this; + } + + /** + * Add watchers as appropriate using the given watchMode to the Modeled Curator's ZNode + * + * @param watchMode watcher style + * @return this for chaining + * @see org.apache.curator.x.async.AsyncStage#event() + */ + public ModeledFrameworkBuilder<T> watched(WatchMode watchMode) + { + this.watchMode = watchMode; + return this; + } + + /** + * Add watchers as appropriate using the given watchMode and filter to the Modeled Curator's ZNode + * + * @param watchMode watcher style + * @param watcherFilter filter + * @return this for chaining + * @see org.apache.curator.x.async.AsyncStage#event() + */ + public ModeledFrameworkBuilder<T> watched(WatchMode watchMode, UnaryOperator<WatchedEvent> watcherFilter) + { + this.watchMode = watchMode; + this.watcherFilter = watcherFilter; + return this; + } + + /** + * Use the given unhandledErrorListener for operations on the Modeled Curator's ZNode + * + * @param unhandledErrorListener listener + * @return this for chaining + */ + public ModeledFrameworkBuilder<T> withUnhandledErrorListener(UnhandledErrorListener unhandledErrorListener) + { + this.unhandledErrorListener = unhandledErrorListener; + return this; + } + + /** + * Use the given result filter for operations on the Modeled Curator's ZNode + * + * @param resultFilter filter + * @return this for chaining + */ + public ModeledFrameworkBuilder<T> withResultFilter(UnaryOperator<CuratorEvent> resultFilter) + { + this.resultFilter = resultFilter; + return this; + } + + /** + * Change the model spec to use + * + * @param modelSpec model spec + * @return this for chaining + */ + public ModeledFrameworkBuilder<T> withModelSpec(ModelSpec<T> modelSpec) + { + this.modelSpec = Objects.requireNonNull(modelSpec, "modelSpec cannot be null"); + return this; + } + + /** + * Change the client to use + * + * @param client new client + * @return this for chaining + */ + public ModeledFrameworkBuilder<T> withClient(CuratorFramework client) + { + this.client = Objects.requireNonNull(client, "client cannot be null"); + return this; + } + + ModeledFrameworkBuilder() + { + } + + ModeledFrameworkBuilder(CuratorFramework client, ModelSpec<T> modelSpec) + { + this.client = Objects.requireNonNull(client, "client cannot be null"); + this.modelSpec = Objects.requireNonNull(modelSpec, "modelSpec cannot be null"); + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/NodeName.java ---------------------------------------------------------------------- diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/NodeName.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/NodeName.java new file mode 100644 index 0000000..7dc8340 --- /dev/null +++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/NodeName.java @@ -0,0 +1,16 @@ +package org.apache.curator.x.async.modeled; + +@FunctionalInterface +public interface NodeName +{ + String nodeName(); + + static String nameFrom(Object obj) + { + if ( obj instanceof NodeName ) + { + return ((NodeName)obj).nodeName(); + } + return String.valueOf(obj); + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/CachedModeledCuratorFramework.java ---------------------------------------------------------------------- diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/CachedModeledCuratorFramework.java b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/CachedModeledCuratorFramework.java deleted file mode 100644 index 9f417dd..0000000 --- a/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/CachedModeledCuratorFramework.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * 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.cached; - -import org.apache.curator.x.async.modeled.ModeledCuratorFramework; -import org.apache.curator.x.async.modeled.ZPath; -import java.io.Closeable; - -public interface CachedModeledCuratorFramework<T> extends ModeledCuratorFramework<T>, Closeable -{ - /** - * Return the cache instance - * - * @return cache - */ - ModeledCache<T> getCache(); - - /** - * Start the internally created via {@link #cached()} - */ - void start(); - - /** - * Close the internally created via {@link #cached()} - */ - @Override - void close(); - - /** - * {@inheritDoc} - */ - @Override - CachedModeledCuratorFramework<T> at(String child); - - /** - * {@inheritDoc} - */ - @Override - CachedModeledCuratorFramework<T> at(ZPath path); - - /** - * {@inheritDoc} - */ - @Override - CachedModeledCuratorFramework<T> resolved(T model); -} http://git-wip-us.apache.org/repos/asf/curator/blob/1fcb63a5/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 new file mode 100644 index 0000000..a73b0c5 --- /dev/null +++ b/curator-x-async/src/main/java/org/apache/curator/x/async/modeled/cached/CachedModeledFramework.java @@ -0,0 +1,62 @@ +/** + * 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.cached; + +import org.apache.curator.x.async.modeled.ModeledFramework; +import org.apache.curator.x.async.modeled.ZPath; +import java.io.Closeable; + +public interface CachedModeledFramework<T> extends ModeledFramework<T>, Closeable +{ + /** + * Return the cache instance + * + * @return cache + */ + ModeledCache<T> getCache(); + + /** + * Start the internally created via {@link #cached()} + */ + void start(); + + /** + * Close the internally created via {@link #cached()} + */ + @Override + void close(); + + /** + * {@inheritDoc} + */ + @Override + CachedModeledFramework<T> at(String child); + + /** + * {@inheritDoc} + */ + @Override + CachedModeledFramework<T> at(ZPath path); + + /** + * {@inheritDoc} + */ + @Override + CachedModeledFramework<T> resolved(T model); +}