public class DistributedTreeAdapter extends Object implements DistributedTree
DistributedTree.Listener, DistributedTree.ListenerAdapter| Constructor and Description |
|---|
DistributedTreeAdapter(DistributedTree tree) |
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(String node,
DistributedTree.Listener listener)
Adds a
listener listening for modifications on the given node. |
void |
create(String node,
boolean ephemeral)
Creates a new node in the tree.
|
void |
createEphemeralOrdered(String node)
Creates an ephemeral node that, when returned by
getChildren(), will be placed in the list in relation to other ordered ephemeral nodes by the relative order of its creation. |
void |
delete(String node)
Deletes a node and all its descendents from the tree.
|
boolean |
exists(String node)
Returns
true if the given node exists in the tree. |
void |
flush()
Ensures that all updates to the tree done by this cluster node will have been seen by all nodes in the cluster when this method returns.
|
byte[] |
get(String node)
Returns the contents of a given node.
|
List<String> |
getChildren(String node)
Returns all child-nodes (direct descendents) of a given node, with ephemeral ordered nodes returned in the order they were created.
|
void |
print(String node,
PrintStream out)
Prints the tree's structure, starting at a given node, to the given stream.
|
void |
removeListener(String node,
DistributedTree.Listener listener)
Removes a listener.
|
void |
set(String node,
byte[] data)
Associates data with (sets the contents of) a given node.
|
public DistributedTreeAdapter(DistributedTree tree)
public void addListener(String node, DistributedTree.Listener listener)
DistributedTreelistener listening for modifications on the given node.
As soon as the listener is added, nodeAdded is called for each child of node.addListener in interface DistributedTreenode - The full path of the node to observe.listener - The listener.public void removeListener(String node, DistributedTree.Listener listener)
DistributedTreeremoveListener in interface DistributedTreenode - The full path of the node the listener is currently observing.listener - The listener to remove.public void create(String node, boolean ephemeral)
DistributedTree
The node can be ephemeral in which case, it and all its descendents will be deleted automatically when the creating cluster-node (this machine) goes offline, i.e. disconnected from the
cluster for whatever reason - intentional or due to some fault. Non-ephemeral (permanent) nodes persist in the tree until the entire cluster is taken down.
If the node is marked as ephemeral, all nonexistent ancestors that will be created in the process will be ephemeral as well.
create in interface DistributedTreenode - The full path of the node to create.ephemeral - true if the node is to be ephemeral; false if it's to be permanent.public void createEphemeralOrdered(String node)
DistributedTreegetChildren(), will be placed in the list in relation to other ordered ephemeral nodes by the relative order of its creation.
The node's ancestors are not created.createEphemeralOrdered in interface DistributedTreenode - The full path of the node to create.public void set(String node, byte[] data)
DistributedTreeset in interface DistributedTreenode - The full path name of the node.data - The data to be associated with the node.DistributedTree.get(java.lang.String)public void delete(String node)
DistributedTreedelete in interface DistributedTreenode - The full path of the node to be removed.public void flush()
DistributedTreeflush in interface DistributedTreepublic boolean exists(String node)
DistributedTreetrue if the given node exists in the tree.exists in interface DistributedTreenode - The full path of the node to test.true if the given node exists in the tree; false otherwise.public byte[] get(String node)
DistributedTreeget in interface DistributedTreenode - The full path of the node.DistributedTree.set(java.lang.String, byte[])public List<String> getChildren(String node)
DistributedTreegetChildren in interface DistributedTreenode - The full path of the node.public void print(String node, PrintStream out)
DistributedTreeprint in interface DistributedTreenode - The node that will serve as the root of the dump.out - The output stream to which the tree structure is to be sent.