Rice Pastry API

rice.scribe
Class Topic

java.lang.Object
  |
  +--rice.scribe.Topic

public class Topic
extends java.lang.Object

Version:
$Id: Topic.java,v 1.15 2003/06/12 21:56:13 atuls Exp $
Author:
Romer Gil, Eric Engineer, Atul Singh, Animesh Nandi

Field Summary
static int CREATED
          The two states in which Topic can be.
static int JOINING
           
protected  java.util.Set m_apps
          Set of IScribeApps that have subscribed to this Topic.
protected  java.util.Set m_children
          Set of NodeHandle objects for the local node's children in this topic's multicast subtree rooted at the local node.
 int m_heartBeatsMissed
          This keeps track of the number of heartbeat messages missed corresponding to this topic.
protected  rice.pastry.NodeHandle m_parent
          Local node's parent in this topic's multicast tree
 rice.scribe.Scribe m_scribe
          The scribe object on which this topic resides.
 int m_state
          Current state of Topic.
protected  rice.pastry.NodeId m_topicId
          This topic's identifier
protected  boolean m_topicManager
          Indicates whether this node is manager of this topic.
protected  boolean m_wantUnsubscribe
          Flag indicating if the local node is waiting to be unsubscribed (because it still does not know parent)
 
Constructor Summary
Topic(rice.pastry.NodeId topicId, rice.scribe.Scribe scribe)
          Constructs an empty Topic
 
Method Summary
 boolean addChild(rice.pastry.NodeHandle child, rice.scribe.messaging.ScribeMessage msg)
          Adds a node to the Set of children in this topic's multicast subtree rooted at this node
 boolean addChild(rice.pastry.NodeHandle child, rice.scribe.messaging.ScribeMessage msg, java.io.Serializable data)
          Adds a node to the Set of children in this topic's multicast subtree rooted at this node.
 void addToScribe()
          Creates a topic reference on the current Scribe node.
 rice.scribe.IScribeApp[] getApps()
          Gets all the applications that wish to receive events regarding this Topic.
 java.util.Vector getChildren()
          This returns the most current view of the children in this topic's multicast subtree rooted at the local node.
 rice.pastry.NodeHandle getParent()
          Returns the local node's parent in this topic's multicast tree.
 int getState()
          Gets the current state of topic.
 rice.pastry.NodeId getTopicId()
          Returns the topic's id
 boolean hasChildren()
          Indicates if the local node has children associated with this topic.
 boolean hasSubscribers()
          If this topic has any applications registered as subscribers.
 boolean isTopicManager()
          Return boolean indicating if the node is topic manager for the current topic.
 boolean isWaitingUnsubscribe()
          Returns true if the local node is waiting to be unsubscribed from this topic.
 void postponeParentHandler()
          Resets the number of heartbeat messages corresponding to this topic to zero.
 boolean removeChild(rice.pastry.NodeHandle child, rice.scribe.messaging.ScribeMessage msg)
          Removes a node from the Set of children in this topic's multicast subtree rooted at this node
 void removeFromScribe()
          Removes this topic reference on the current Scribe node.
 void setParent(rice.pastry.NodeHandle parent)
          Sets the local node's parent in this topic's multicast tree.
 void setState(int state)
          Set the state of topic to state
 void subscribe(rice.scribe.IScribeApp app)
          Register an application as a subscriber to this Topic, so that the application receives events related to the Topic.
 void topicManager(boolean topicMgr)
          Sets the flag indicating whether the current node is topic manager for this topic
 void unsubscribe(rice.scribe.IScribeApp app)
          Unregister an application as a Subscriber to this Topic, so that the application no longer receives events regarding this Topic.
 void waitUnsubscribe(boolean wait)
          Sets flag indicating if the local node is waiting to be unsubscribed from this topic (because it does not yet know its parent)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_topicId

protected rice.pastry.NodeId m_topicId
This topic's identifier


m_children

protected java.util.Set m_children
Set of NodeHandle objects for the local node's children in this topic's multicast subtree rooted at the local node.


m_parent

protected rice.pastry.NodeHandle m_parent
Local node's parent in this topic's multicast tree


m_wantUnsubscribe

protected boolean m_wantUnsubscribe
Flag indicating if the local node is waiting to be unsubscribed (because it still does not know parent)


m_topicManager

protected boolean m_topicManager
Indicates whether this node is manager of this topic.


m_apps

protected java.util.Set m_apps
Set of IScribeApps that have subscribed to this Topic.


m_heartBeatsMissed

public int m_heartBeatsMissed
This keeps track of the number of heartbeat messages missed corresponding to this topic. This value is INCREMENTED whenever a scheduleHB() method is invoked on the scribe object. The assumption is that simultaneously the scheduleHB() method is also being invoked on the other nodes including the parent for this topic. This value is RESET whenever the local node receives a heartbeat message, publish message or MessageAckOnSubscribe from the parent for the topic.


m_scribe

public rice.scribe.Scribe m_scribe
The scribe object on which this topic resides.


CREATED

public static final int CREATED
The two states in which Topic can be. CREATED means that topic object is just created, and a subscription message was not sent to subscribe to the topicId. JOINING means topic object is created and also a subscribe message was also sent to subscribe to the topicId.

See Also:
Constant Field Values

JOINING

public static final int JOINING
See Also:
Constant Field Values

m_state

public int m_state
Current state of Topic. Can be either of these: 1) Created 2) Joining

Constructor Detail

Topic

public Topic(rice.pastry.NodeId topicId,
             rice.scribe.Scribe scribe)
Constructs an empty Topic

Parameters:
topicId - unique id for this topic.
scribe - the scribe system in which the topic resides.
Method Detail

getTopicId

public rice.pastry.NodeId getTopicId()
Returns the topic's id

Returns:
topic's unique identifier

setState

public void setState(int state)
Set the state of topic to state

Parameters:
state - The state to which current topic should be set to.

getState

public int getState()
Gets the current state of topic.


addChild

public boolean addChild(rice.pastry.NodeHandle child,
                        rice.scribe.messaging.ScribeMessage msg)
Adds a node to the Set of children in this topic's multicast subtree rooted at this node

Parameters:
child - the node to be added as a child.
msg - the ScribeMessage which triggered this action, it can be SUBSCRIBE msg, or null if application on top of Scribe called addChild()
Returns:
true if the child was NOT already in the Set of children.

addChild

public boolean addChild(rice.pastry.NodeHandle child,
                        rice.scribe.messaging.ScribeMessage msg,
                        java.io.Serializable data)
Adds a node to the Set of children in this topic's multicast subtree rooted at this node. Also takes in a serializable data which will be sent along with the ACK to the child.

Parameters:
child - the node to be added as a child.
msg - the ScribeMessage which triggered this action, it can be SUBSCRIBE msg, or null if application on top of Scribe called addChild()
data - The serializable data.
Returns:
true if the child was NOT already in the Set of children.

removeChild

public boolean removeChild(rice.pastry.NodeHandle child,
                           rice.scribe.messaging.ScribeMessage msg)
Removes a node from the Set of children in this topic's multicast subtree rooted at this node

Parameters:
child - the child node to be removed from the multicast tree.
msg - the ScribeMessage which triggered this action, it can be UNSUBSCRIBE msg, or null if application on top of Scribe called removeChild() or this child became dead
Returns:
true if the child node was in the Set of children.

hasChildren

public boolean hasChildren()
Indicates if the local node has children associated with this topic.

Returns:
true if the local node has children associated with this topic.

getChildren

public java.util.Vector getChildren()
This returns the most current view of the children in this topic's multicast subtree rooted at the local node. Note that additions and deletions to the returned vector do not affect the actual children set maintained by the node.

Returns:
vector of nodeHandle objects.

setParent

public void setParent(rice.pastry.NodeHandle parent)
Sets the local node's parent in this topic's multicast tree.

Parameters:
parent - the node to be the parent.

getParent

public rice.pastry.NodeHandle getParent()
Returns the local node's parent in this topic's multicast tree.

Returns:
the parent node.

subscribe

public void subscribe(rice.scribe.IScribeApp app)
Register an application as a subscriber to this Topic, so that the application receives events related to the Topic.

Parameters:
app - The application to be registered.

unsubscribe

public void unsubscribe(rice.scribe.IScribeApp app)
Unregister an application as a Subscriber to this Topic, so that the application no longer receives events regarding this Topic.

Parameters:
app - The application to be unregistered.

hasSubscribers

public boolean hasSubscribers()
If this topic has any applications registered as subscribers.

Returns:
true if there is at least one application subscribed to this topic.

waitUnsubscribe

public void waitUnsubscribe(boolean wait)
Sets flag indicating if the local node is waiting to be unsubscribed from this topic (because it does not yet know its parent)

Parameters:
wait - value to set flag

isWaitingUnsubscribe

public boolean isWaitingUnsubscribe()
Returns true if the local node is waiting to be unsubscribed from this topic.

Returns:
true if local node is waiting to be unsubscribed from this topic.

topicManager

public void topicManager(boolean topicMgr)
Sets the flag indicating whether the current node is topic manager for this topic

Parameters:
topicMgr - value of the flag

isTopicManager

public boolean isTopicManager()
Return boolean indicating if the node is topic manager for the current topic.

Returns:
true if topic manager, false otherwise

postponeParentHandler

public void postponeParentHandler()
Resets the number of heartbeat messages corresponding to this topic to zero. This method is called when you get a heartbeat message or a publish message or a MessageAckOnSubscribe.


addToScribe

public void addToScribe()
Creates a topic reference on the current Scribe node. This method is called by ScribeMessage objects.


removeFromScribe

public void removeFromScribe()
Removes this topic reference on the current Scribe node. This method is called by ScribeMessage objects.


getApps

public rice.scribe.IScribeApp[] getApps()
Gets all the applications that wish to receive events regarding this Topic.

Returns:
The applications currently registered with this Topic

Rice Pastry API

Copyright © 2001 - Rice Pastry.


Imprint-Dataprotection