Database Reference
In-Depth Information
When used immediately, the getData command returns a byte array,
which can be deserialized into whatever format the application desires. For
example,ifthedatawereasimpletextstring,itcanbesetandthenretrieved
as follows (assuming the znode already exists):
client.setData()
.forPath("test/string", "A Test String".getBytes());
System. out .println(
new String(
client.getData()
.forPath("test/string")
)
);
Like the create command, getData can be executed in the background. In
the background case, the forPath method returns null and the data is
returned in the background callback. For example, the same code as the
previous example implemented as a background callback would look like
this:
client.getData().inBackground( new BackgroundCallback()
{
public void processResult(CuratorFramework arg0,
CuratorEvent arg1)
throws Exception {
System. out .println( new String(arg1.getData()));
}
}).forPath("test/string");
The
previous
two
examples
are
implemented
in
wiley.streaming.curator .DataTest .
The getChildren command works essentially the same way as the
getData command. Instead of returning a byte array, this command
returns a list of String objects giving the names of the child znode s of the
parent object. This example shows this command in action by first adding
several jobs to an imaginary queue znode and then calling getChildren
on the node to retrieve the list of children, as demonstrated in
wiley.streaming.curator.QueueTest :
Search WWH ::




Custom Search