org.jgroups.blocks

Class ReplicatedTree

public class ReplicatedTree extends Object implements Runnable, MessageListener, MembershipListener

A tree-like structure that is replicated across several members. Updates will be multicast to all group members reliably and in the same order.

Author: Bela Ban Jan 17 2002 Alfonso Olias-Sanz

Nested Class Summary
static classReplicatedTree.Node
interfaceReplicatedTree.ReplicatedTreeListener
Field Summary
protected Loglog
static StringSEPARATOR
Constructor Summary
ReplicatedTree(String groupname, String props, long state_fetch_timeout)
Creates a channel with the given properties.
ReplicatedTree(String groupname, String props, long state_fetch_timeout, boolean jmx)
ReplicatedTree()
ReplicatedTree(JChannel channel)
Expects an already connected channel.
Method Summary
voidaddReplicatedTreeListener(ReplicatedTree.ReplicatedTreeListener listener)
voidblock()
Block sending and receiving of messages until viewAccepted() is called
booleanexists(String fqn)
Checks whether a given node exists in the tree
voidfetchState(long timeout)
Fetch the group state from the current coordinator.
Objectget(String fqn, String key)
Finds a node given its name and returns the value associated with a given key in its data map.
ChannelgetChannel()
Returns the Channel the DistributedTree is connected to
SetgetChildrenNames(String fqn)
Returns all children of a given node
intgetGroupMembersNumber()
Returns the number of current members joined to the group
StringgetGroupName()
Returns the name of the group that the DistributedTree is connected to
SetgetKeys(String fqn)
Gets the keys of the data map.
AddressgetLocalAddress()
VectorgetMembers()
byte[]getState()
Return a copy of the current cache (tree)
static voidmain(String[] args)
Stringprint(String fqn)
Prints a representation of the node defined by fqn.
voidput(String fqn, HashMap data)
Adds a new node to the tree and sets its data.
voidput(String fqn, String key, Object value)
Adds a key and value to a given node.
voidreceive(Message msg)
Callback.
voidremove(String fqn)
Removes the node from the tree.
voidremove(String fqn, String key)
Removes key from the node's hashmap
voidremoveReplicatedTreeListener(ReplicatedTree.ReplicatedTreeListener listener)
voidrun()
Request handler thread
voidsetRemoteCalls(boolean flag)
voidsetRootNode(ReplicatedTree.Node n)
voidsetState(byte[] new_state)
Set the cache (tree) to this value
voidstart()
voidstop()
voidsuspect(Address suspected_mbr)
Called when a member is suspected
StringtoString()
voidviewAccepted(View new_view)
void_put(String fqn, HashMap data)
void_put(String fqn, String key, Object value)
void_remove(String fqn)
void_remove(String fqn, String key)
void_removeData(String fqn)

Field Detail

log

protected final Log log

SEPARATOR

public static final String SEPARATOR

Constructor Detail

ReplicatedTree

public ReplicatedTree(String groupname, String props, long state_fetch_timeout)
Creates a channel with the given properties. Connects to the channel, then creates a PullPushAdapter and starts it

ReplicatedTree

public ReplicatedTree(String groupname, String props, long state_fetch_timeout, boolean jmx)

ReplicatedTree

public ReplicatedTree()

ReplicatedTree

public ReplicatedTree(JChannel channel)
Expects an already connected channel. Creates a PullPushAdapter and starts it

Method Detail

addReplicatedTreeListener

public void addReplicatedTreeListener(ReplicatedTree.ReplicatedTreeListener listener)

block

public void block()
Block sending and receiving of messages until viewAccepted() is called

exists

public boolean exists(String fqn)
Checks whether a given node exists in the tree

Parameters: fqn The fully qualified name of the node

Returns: boolean Whether or not the node exists

fetchState

public void fetchState(long timeout)
Fetch the group state from the current coordinator. If successful, this will trigger setState().

get

public Object get(String fqn, String key)
Finds a node given its name and returns the value associated with a given key in its data map. Returns null if the node was not found in the tree or the key was not found in the hashmap.

Parameters: fqn The fully qualified name of the node. key The key.

getChannel

public Channel getChannel()
Returns the Channel the DistributedTree is connected to

Returns: Channel

getChildrenNames

public Set getChildrenNames(String fqn)
Returns all children of a given node

Parameters: fqn The fully qualified name of the node

Returns: Set A list of child names (as Strings)

getGroupMembersNumber

public int getGroupMembersNumber()
Returns the number of current members joined to the group

Returns: int

getGroupName

public String getGroupName()
Returns the name of the group that the DistributedTree is connected to

Returns: String

getKeys

public Set getKeys(String fqn)
Gets the keys of the data map. Returns all keys as Strings. Returns null if node does not exist.

Parameters: fqn The fully qualified name of the node

Returns: Set A set of keys (as Strings)

getLocalAddress

public Address getLocalAddress()

getMembers

public Vector getMembers()

getState

public byte[] getState()
Return a copy of the current cache (tree)

main

public static void main(String[] args)

print

public String print(String fqn)
Prints a representation of the node defined by fqn. Output includes name, fqn and data.

put

public void put(String fqn, HashMap data)
Adds a new node to the tree and sets its data. If the node doesn not yet exist, it will be created. Also, parent nodes will be created if not existent. If the node already has data, then the new data will override the old one. If the node already existed, a nodeModified() notification will be generated. Otherwise a nodeCreated() motification will be emitted.

Parameters: fqn The fully qualified name of the new node data The new data. May be null if no data should be set in the node.

put

public void put(String fqn, String key, Object value)
Adds a key and value to a given node. If the node doesn't exist, it will be created. If the node already existed, a nodeModified() notification will be generated. Otherwise a nodeCreated() motification will be emitted.

Parameters: fqn The fully qualified name of the node key The key value The value

receive

public void receive(Message msg)
Callback. Process the contents of the message; typically an _add() or _set() request

remove

public void remove(String fqn)
Removes the node from the tree.

Parameters: fqn The fully qualified name of the node.

remove

public void remove(String fqn, String key)
Removes key from the node's hashmap

Parameters: fqn The fullly qualified name of the node key The key to be removed

removeReplicatedTreeListener

public void removeReplicatedTreeListener(ReplicatedTree.ReplicatedTreeListener listener)

run

public void run()
Request handler thread

setRemoteCalls

public void setRemoteCalls(boolean flag)

setRootNode

public void setRootNode(ReplicatedTree.Node n)

setState

public void setState(byte[] new_state)
Set the cache (tree) to this value

start

public void start()

stop

public void stop()

suspect

public void suspect(Address suspected_mbr)
Called when a member is suspected

toString

public String toString()

viewAccepted

public void viewAccepted(View new_view)

_put

public void _put(String fqn, HashMap data)

_put

public void _put(String fqn, String key, Object value)

_remove

public void _remove(String fqn)

_remove

public void _remove(String fqn, String key)

_removeData

public void _removeData(String fqn)
Copyright ? 1998-2005 Bela Ban. All Rights Reserved.