Database Reference
In-Depth Information
Working with znodes
The Curator framework uses a “fluent” style for most of its commands. In
this style of framework, most methods return an object that allows calls to
be chained together. The Builder object in the last section was an example
of this interface, and it is continued in all of Curator's znode manipulation
routines.
Using the fluent style, Curator directly supports all of the basic znode
operations as a series of chained method calls terminated by a call to
forPath . The forPath method takes a complete path and an optional
byte array containing any payload that should be associated with this
znode . This example creates a new path in a synchronous fashion, creating
parent znodes as needed:
client.create()
.creatingParentsIfNeeded()
.forPath("/a/test/path");
These methods can also be executed asynchronously by adding the
inBackground call to the method chain:
client.create()
.creatingParentsIfNeeded()
.inBackground( new BackgroundCallback() {
public void processResult(CuratorFramework arg0,
CuratorEvent arg1)
throws Exception {
System. out .println("Path Created: "+arg1);
}
})
.forPath("/a/test/path");
Note that the inBackground method returns a PathAndBytesable<T>
object rather than the original builder. This object only supports the
forPath method, so it must be last in the chain of calls. When executed,
as in the example provided by wiley.streaming.curator.PathTest ,
this command should have an output something like this:
Search WWH ::




Custom Search