org.javagroups.blocks
Class ReplicatedTree

java.lang.Object
  |
  +--org.javagroups.blocks.ReplicatedTree
All Implemented Interfaces:
java.lang.Cloneable, MembershipListener, MessageListener, java.lang.Runnable

public class ReplicatedTree
extends java.lang.Object
implements java.lang.Runnable, java.lang.Cloneable, 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

Inner Class Summary
static class ReplicatedTree.Node
           
static interface ReplicatedTree.ReplicatedTreeListener
           
 
Field Summary
static java.lang.String SEPARATOR
           
 
Constructor Summary
ReplicatedTree()
           
ReplicatedTree(JChannel channel)
          Expects an already connected channel.
ReplicatedTree(java.lang.String groupname, java.lang.String props, long state_fetch_timeout)
          Creates a channel with the given properties.
 
Method Summary
 void _put(java.lang.String fqn, java.util.HashMap data)
           
 void _put(java.lang.String fqn, java.lang.String key, java.lang.Object value)
           
 void _remove(java.lang.String fqn)
           
 void _remove(java.lang.String fqn, java.lang.String key)
           
 void _removeData(java.lang.String fqn)
           
 void addReplicatedTreeListener(ReplicatedTree.ReplicatedTreeListener listener)
           
 void block()
          Block sending and receiving of messages until viewAccepted() is called
 boolean exists(java.lang.String fqn)
          Checks whether a given node exists in the tree
 void fetchState(long timeout)
          Fetch the group state from the current coordinator.
 java.lang.Object get(java.lang.String fqn, java.lang.String key)
          Finds a node given its name and returns the value associated with a given key in its data map.
 java.util.Set getChildrenNames(java.lang.String fqn)
          Returns all children of a given node
 java.util.Set getKeys(java.lang.String fqn)
          Gets the keys of the data map.
 Address getLocalAddress()
           
 java.util.Vector getMembers()
           
 java.lang.Object getState()
          Return a copy of the current cache (tree)
static void main(java.lang.String[] args)
           
 java.lang.String print(java.lang.String fqn)
          Prints a representation of the node defined by fqn.
 void put(java.lang.String fqn, java.util.HashMap data)
          Adds a new node to the tree and sets its data.
 void put(java.lang.String fqn, java.lang.String key, java.lang.Object value)
          Adds a key and value to a given node.
 void receive(Message msg)
          Callback.
 void remove(java.lang.String fqn)
          Removes the node from the tree.
 void remove(java.lang.String fqn, java.lang.String key)
          Removes key from the node's hashmap
 void removeReplicatedTreeListener(ReplicatedTree.ReplicatedTreeListener listener)
           
 void run()
          Request handler thread
 void setRemoteCalls(boolean flag)
           
 void setRootNode(ReplicatedTree.Node n)
           
 void setState(java.lang.Object new_state)
          Set the cache (tree) to this value
 void start()
           
 void stop()
           
 void suspect(Address suspected_mbr)
          Called when a member is suspected
 java.lang.String toString()
           
 void viewAccepted(View new_view)
          Called by JavaGroups to notify the target object of a change of membership.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SEPARATOR

public static final java.lang.String SEPARATOR
Constructor Detail

ReplicatedTree

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

ReplicatedTree

public ReplicatedTree()

ReplicatedTree

public ReplicatedTree(JChannel channel)
               throws java.lang.Exception
Expects an already connected channel. Creates a PullPushAdapter and starts it
Method Detail

setRemoteCalls

public void setRemoteCalls(boolean flag)

setRootNode

public void setRootNode(ReplicatedTree.Node n)

getLocalAddress

public Address getLocalAddress()

getMembers

public java.util.Vector getMembers()

fetchState

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

addReplicatedTreeListener

public void addReplicatedTreeListener(ReplicatedTree.ReplicatedTreeListener listener)

removeReplicatedTreeListener

public void removeReplicatedTreeListener(ReplicatedTree.ReplicatedTreeListener listener)

start

public void start()
           throws java.lang.Exception

stop

public void stop()

put

public void put(java.lang.String fqn,
                java.util.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 nodeAdded() 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(java.lang.String fqn,
                java.lang.String key,
                java.lang.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 nodeAdded() motification will be emitted.
Parameters:
fqn - The fully qualified name of the node
key - The key
value - The value

remove

public void remove(java.lang.String fqn)
Removes the node from the tree.
Parameters:
fqn - The fully qualified name of the node.

remove

public void remove(java.lang.String fqn,
                   java.lang.String key)
Removes key from the node's hashmap
Parameters:
fqn - The fullly qualified name of the node
key - The key to be removed

exists

public boolean exists(java.lang.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

getKeys

public java.util.Set getKeys(java.lang.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)

get

public java.lang.Object get(java.lang.String fqn,
                            java.lang.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.

print

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

getChildrenNames

public java.util.Set getChildrenNames(java.lang.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)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

_put

public void _put(java.lang.String fqn,
                 java.util.HashMap data)

_put

public void _put(java.lang.String fqn,
                 java.lang.String key,
                 java.lang.Object value)

_remove

public void _remove(java.lang.String fqn)

_remove

public void _remove(java.lang.String fqn,
                    java.lang.String key)

_removeData

public void _removeData(java.lang.String fqn)

receive

public void receive(Message msg)
Callback. Process the contents of the message; typically an _add() or _set() request
Specified by:
receive in interface MessageListener

getState

public java.lang.Object getState()
Return a copy of the current cache (tree)
Specified by:
getState in interface MessageListener

setState

public void setState(java.lang.Object new_state)
Set the cache (tree) to this value
Specified by:
setState in interface MessageListener

viewAccepted

public void viewAccepted(View new_view)
Description copied from interface: MembershipListener
Called by JavaGroups to notify the target object of a change of membership. No long running actions should be done in this callback in the case of Ensemble, as this would block Ensemble. If some long running action needs to be performed, it should be done in a separate thread (cf. ../Tests/QuoteServer.java).
Specified by:
viewAccepted in interface MembershipListener

suspect

public void suspect(Address suspected_mbr)
Called when a member is suspected
Specified by:
suspect in interface MembershipListener

block

public void block()
Block sending and receiving of messages until viewAccepted() is called
Specified by:
block in interface MembershipListener

run

public void run()
Request handler thread
Specified by:
run in interface java.lang.Runnable

main

public static void main(java.lang.String[] args)


Copyright © 2001,2002 www.javagroups.com . All Rights Reserved.