Package org.jgroups.blocks
Class ReplicatedTree
java.lang.Object
org.jgroups.blocks.ReplicatedTree
- All Implemented Interfaces:
Runnable
,MembershipListener
,MessageListener
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
Nested ClassesModifier and TypeClassDescriptionstatic class
static interface
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionReplicatedTree
(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
(JChannel channel) Expects an already connected channel. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
void
void
void
_removeData
(String fqn) void
void
block()
Block sending and receiving of messages until viewAccepted() is calledboolean
Checks whether a given node exists in the treevoid
fetchState
(long timeout) Fetch the group state from the current coordinator.Finds a node given its name and returns the value associated with a given key in itsdata
map.Returns the Channel the DistributedTree is connected togetChildrenNames
(String fqn) Returns all children of a given nodeint
Returns the number of current members joined to the groupReturns the name of the group that the DistributedTree is connected toGets the keys of thedata
map.byte[]
getState()
Return a copy of the current cache (tree)static void
Prints a representation of the node defined byfqn
.void
Adds a key and value to a given node.void
Adds a new node to the tree and sets its data.void
Callback.void
Removes the node from the tree.void
Removeskey
from the node's hashmapvoid
void
run()
Request handler threadvoid
setRemoteCalls
(boolean flag) void
void
setState
(byte[] new_state) Set the cache (tree) to this valuefinal void
start()
void
stop()
void
Called when a member is suspectedtoString()
void
viewAccepted
(View new_view) Called when a change in membership has occurred.
-
Field Details
-
SEPARATOR
- See Also:
-
log
protected final org.apache.commons.logging.Log log
-
-
Constructor Details
-
ReplicatedTree
Creates a channel with the given properties. Connects to the channel, then creates a PullPushAdapter and starts it- Throws:
Exception
-
ReplicatedTree
public ReplicatedTree(String groupname, String props, long state_fetch_timeout, boolean jmx) throws Exception - Throws:
Exception
-
ReplicatedTree
public ReplicatedTree() -
ReplicatedTree
Expects an already connected channel. Creates a PullPushAdapter and starts it- Throws:
Exception
-
-
Method Details
-
setRemoteCalls
public void setRemoteCalls(boolean flag) -
setRootNode
-
getLocalAddress
-
getMembers
-
fetchState
Fetch the group state from the current coordinator. If successful, this will trigger setState(). -
addReplicatedTreeListener
-
removeReplicatedTreeListener
-
start
- Throws:
Exception
-
stop
public void stop() -
put
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 nodedata
- The new data. May be null if no data should be set in the node.
-
put
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 nodekey
- The keyvalue
- The value
-
remove
Removes the node from the tree.- Parameters:
fqn
- The fully qualified name of the node.
-
remove
Removeskey
from the node's hashmap- Parameters:
fqn
- The fullly qualified name of the nodekey
- The key to be removed
-
exists
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
-
getKeys
Gets the keys of thedata
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)
-
get
Finds a node given its name and returns the value associated with a given key in itsdata
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.
-
print
Prints a representation of the node defined byfqn
. Output includes name, fqn and data. -
getChildrenNames
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)
-
toString
-
getGroupName
Returns the name of the group that the DistributedTree is connected to- Returns:
- String
-
getChannel
Returns the Channel the DistributedTree is connected to- Returns:
- Channel
-
getGroupMembersNumber
public int getGroupMembersNumber()Returns the number of current members joined to the group- Returns:
- int
-
_put
-
_put
-
_remove
-
_remove
-
_removeData
-
receive
Callback. Process the contents of the message; typically an _add() or _set() request- Specified by:
receive
in interfaceMessageListener
- Parameters:
msg
-
-
getState
public byte[] getState()Return a copy of the current cache (tree)- Specified by:
getState
in interfaceMessageListener
- Returns:
- byte[]
-
setState
public void setState(byte[] new_state) Set the cache (tree) to this value- Specified by:
setState
in interfaceMessageListener
- Parameters:
new_state
-
-
viewAccepted
Description copied from interface:MembershipListener
Called when a change in membership has occurred. No long running actions or sending of messages should be done in this callback. If some long running action needs to be performed, it should be done in a separate thread. Note that on reception of the first view (a new member just joined), the channel will not yet be in the connected state. This only happens whenChannel.connect(String)
returns.- Specified by:
viewAccepted
in interfaceMembershipListener
-
suspect
Called when a member is suspected- Specified by:
suspect
in interfaceMembershipListener
-
block
public void block()Block sending and receiving of messages until viewAccepted() is called- Specified by:
block
in interfaceMembershipListener
-
run
public void run()Request handler thread -
main
-