Hey folks,
I have a new feature PR that needs review:
https://github.com/apache/curator/pull/211
<https://github.com/apache/curator/pull/211>
This new feature allows code like this:
// let "client" be a CuratorFramework instance
ZPath path = ZPath.parse(...); // whatever path you need
JacksonModelSerializer<Person> serializer =
JacksonModelSerializer.build(Person.class);
ModeledAsyncCuratorFramework<MyModel> modeled =
ModeledAsyncCuratorFramework.wrap(client, path, serializer);
...
public void writePerson(String id, Person p) {
modeled.at(id).create(p); // note this is an async operation
}
public void readPerson(String id, Consumer<Person> receiver) {
modeled.at(id).read().whenComplete((person, exception) -> {
if ( exception != null ) {
...
} else {
receiver.accept(person);
}
});
}
I've also added wrappers so that NodeCache, PathChildrenCache and TreeCache can
have modeled usages.
E.g.
// given a model class "Person"
ModeledTreeCache<Person> cache = ModeledTreeCache.wrap(makeTreeCache(),
serializer);
ModeledCacheListener<Person> listener = event -> {
switch ( event.getType() ) {
case ModeledCacheEventType.NODE_ADDED:
Person person = event.getNode().getModel();
handleNewPerson(person);
break;
...
}
};
cache.getListenable().addListener(listener);