Package org.jgroups.blocks
Class DistributedTree
- java.lang.Object
-
- org.jgroups.blocks.DistributedTree
-
- All Implemented Interfaces:
MembershipListener,MessageListener
public class DistributedTree extends java.lang.Object implements 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, Alfonso Olias-Sanz
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceDistributedTree.DistributedTreeListenerstatic interfaceDistributedTree.ViewListener
-
Field Summary
Fields Modifier and Type Field Description protected Channelchannelprotected RpcDispatcherdispprotected static org.apache.commons.logging.Loglogprotected booleanrcprotected booleansend_messageDetermines when the updates have to be sent across the network, avoids sending unnecessary messages when there are no member in the group
-
Constructor Summary
Constructors Constructor Description DistributedTree()DistributedTree(java.lang.String groupname, java.lang.String channel_properties)DistributedTree(PullPushAdapter adapter, java.io.Serializable id, long state_timeout)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void_add(java.lang.String fqn)void_add(java.lang.String fqn, java.io.Serializable element)void_remove(java.lang.String fqn)void_reset(java.lang.String fqn, java.io.Serializable element)similar to set, but does not error if node does not exist, but rather does an add insteadvoid_set(java.lang.String fqn, java.io.Serializable element)voidadd(java.lang.String fqn)voidadd(java.lang.String fqn, java.io.Serializable element)voidadd(java.lang.String fqn, java.io.Serializable element, int timeout)voidaddDistributedTreeListener(DistributedTree.DistributedTreeListener listener)voidaddViewListener(DistributedTree.ViewListener listener)voidblock()Block sending and receiving of messages until ViewAccepted is calledbooleanexists(java.lang.String fqn)java.io.Serializableget(java.lang.String fqn)ChannelgetChannel()Returns the Channel the DistributedTree is connected tojava.util.VectorgetChildrenNames(java.lang.String fqn)Returns all children of a Node as stringsintgetGroupMembersNumber()Returns the number of current members joined to the groupjava.lang.StringgetGroupName()Returns the name of the group that the DistributedTree is connected tojava.lang.ObjectgetLocalAddress()byte[]getState()Return a copy of the treejava.lang.Stringprint()voidreceive(Message msg)Called when a message is received.voidremove(java.lang.String fqn)voidremove(java.lang.String fqn, int timeout)voidremoveDistributedTreeListener(DistributedTree.DistributedTreeListener listener)voidremoveViewListener(DistributedTree.ViewListener listener)voidreset(java.lang.String fqn, java.io.Serializable element)resets an existing node, useful after a merge when you want to tell other members of your state, but do not wish to remove and then add as two separate callsvoidreset(java.lang.String fqn, java.io.Serializable element, int timeout)resets an existing node, useful after a merge when you want to tell other members of your state, but do not wish to remove and then add as two separate callsvoidset(java.lang.String fqn, java.io.Serializable element)voidset(java.lang.String fqn, java.io.Serializable element, int timeout)voidsetDeadlockDetection(boolean flag)voidsetState(byte[] data)Sets the group state; e.g., when joining.voidstart()voidstart(long timeout)voidstop()voidsuspect(Address suspected_mbr)Called when a member is suspectedvoidviewAccepted(View new_view)Called when a change in membership has occurred.
-
-
-
Field Detail
-
channel
protected Channel channel
-
disp
protected RpcDispatcher disp
-
rc
protected boolean rc
-
send_message
protected boolean send_message
Determines when the updates have to be sent across the network, avoids sending unnecessary messages when there are no member in the group
-
log
protected static final org.apache.commons.logging.Log log
-
-
Constructor Detail
-
DistributedTree
public DistributedTree()
-
DistributedTree
public DistributedTree(java.lang.String groupname, java.lang.String channel_properties)
-
DistributedTree
public DistributedTree(PullPushAdapter adapter, java.io.Serializable id, long state_timeout) throws ChannelException
- Throws:
ChannelException
-
-
Method Detail
-
getLocalAddress
public java.lang.Object getLocalAddress()
-
setDeadlockDetection
public void setDeadlockDetection(boolean flag)
-
start
public void start() throws java.lang.Exception- Throws:
java.lang.Exception
-
start
public void start(long timeout) throws java.lang.Exception- Throws:
java.lang.Exception
-
stop
public void stop()
-
addDistributedTreeListener
public void addDistributedTreeListener(DistributedTree.DistributedTreeListener listener)
-
removeDistributedTreeListener
public void removeDistributedTreeListener(DistributedTree.DistributedTreeListener listener)
-
addViewListener
public void addViewListener(DistributedTree.ViewListener listener)
-
removeViewListener
public void removeViewListener(DistributedTree.ViewListener listener)
-
add
public void add(java.lang.String fqn)
-
add
public void add(java.lang.String fqn, java.io.Serializable element)
-
reset
public void reset(java.lang.String fqn, java.io.Serializable element)resets an existing node, useful after a merge when you want to tell other members of your state, but do not wish to remove and then add as two separate calls
-
remove
public void remove(java.lang.String fqn)
-
add
public void add(java.lang.String fqn, java.io.Serializable element, int timeout)
-
reset
public void reset(java.lang.String fqn, java.io.Serializable element, int timeout)resets an existing node, useful after a merge when you want to tell other members of your state, but do not wish to remove and then add as two separate calls
-
remove
public void remove(java.lang.String fqn, int timeout)
-
exists
public boolean exists(java.lang.String fqn)
-
get
public java.io.Serializable get(java.lang.String fqn)
-
set
public void set(java.lang.String fqn, java.io.Serializable element)
-
set
public void set(java.lang.String fqn, java.io.Serializable element, int timeout)
-
getChildrenNames
public java.util.Vector getChildrenNames(java.lang.String fqn)
Returns all children of a Node as strings
-
print
public java.lang.String print()
-
getGroupName
public java.lang.String getGroupName()
Returns the name of the group that the DistributedTree is connected to- Returns:
- String
-
getChannel
public Channel 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
-
_add
public void _add(java.lang.String fqn)
-
_add
public void _add(java.lang.String fqn, java.io.Serializable element)
-
_remove
public void _remove(java.lang.String fqn)
-
_set
public void _set(java.lang.String fqn, java.io.Serializable element)
-
_reset
public void _reset(java.lang.String fqn, java.io.Serializable element)similar to set, but does not error if node does not exist, but rather does an add instead
-
receive
public void receive(Message msg)
Description copied from interface:MessageListenerCalled when a message is received.- Specified by:
receivein interfaceMessageListener
-
getState
public byte[] getState()
Return a copy of the tree- Specified by:
getStatein interfaceMessageListener- Returns:
- byte[]
-
setState
public void setState(byte[] data)
Description copied from interface:MessageListenerSets the group state; e.g., when joining.- Specified by:
setStatein interfaceMessageListener
-
viewAccepted
public void viewAccepted(View new_view)
Description copied from interface:MembershipListenerCalled 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:
viewAcceptedin interfaceMembershipListener
-
suspect
public void suspect(Address suspected_mbr)
Called when a member is suspected- Specified by:
suspectin interfaceMembershipListener
-
block
public void block()
Block sending and receiving of messages until ViewAccepted is called- Specified by:
blockin interfaceMembershipListener
-
-