hypercast.SPT
Class SPT_Node

java.lang.Object
  |
  +--hypercast.SPT.SPT_Node
All Implemented Interfaces:
I_AdapterCallback, I_Node, I_Stats

public class SPT_Node
extends java.lang.Object
implements I_AdapterCallback, I_Node

This class is a Spanning Tree node.


Field Summary
 hypercast.I_MulticastAdapter m_adapter
          Multicast adapter (used to transfer protocol message to neighbors)
 
Fields inherited from interface hypercast.I_Node
DEFAULT_CONFIG_FILE, PROTOSUB_BUDDYLIST, PROTOSUB_MULTICAST, PROTOSUB_NOSPEC, PROTOSUB_SERVER
 
Constructor Summary
SPT_Node(hypercast.HyperCastConfig c, hypercast.I_MulticastAdapter m, hypercast.SPT.SPT_LogicalAddress la, java.lang.String prefix)
          Constructor
SPT_Node(hypercast.HyperCastConfig c, hypercast.I_MulticastAdapter m, java.lang.String prefix)
          Constructor.
 
Method Summary
 hypercast.I_LogicalAddress createLogicalAddress(byte[] array, int offset)
          Constructs a SPT_LogicalAddress from a byte array.
 hypercast.I_LogicalAddress createLogicalAddress(byte[] laddr, int offset, int index)
           
 hypercast.I_LogicalAddress createLogicalAddress(java.lang.String laStr)
          Creates a logical address object from a String.
 hypercast.I_AddressPair getAddressPair()
          Returns this logical and physical addresses of this node.
 hypercast.I_AddressPair[] getAllNeighbors()
          Returns the node's neighbors' physical/logical address pairs.
 hypercast.I_AddressPair[] getAllNeighbors(hypercast.I_LogicalAddress root)
           
 hypercast.I_AddressPair[] getAllNeighbors(int index)
           
 hypercast.I_AddressPair[] getChildren(hypercast.I_LogicalAddress root)
          Returns the node's children's physical/logical address pairs, with respect to the spanning tree rooted at root.
 hypercast.I_AddressPair[] getChildren(hypercast.I_LogicalAddress root, int index)
           
 hypercast.I_LogicalAddress getLogicalAddress()
           
 hypercast.I_LogicalAddress getLogicalAddress(int index)
           
 hypercast.I_AddressPair getMyAddressPair(hypercast.I_LogicalAddress root)
           
 hypercast.I_AddressPair getMyAddressPair(int index)
           
 hypercast.I_AddressPair[] getParent(hypercast.I_LogicalAddress root)
          Returns the addresspair of the next hop for a message routed by this node towards the root.
 hypercast.I_AddressPair[] getParent(hypercast.I_LogicalAddress root, int index)
           
 hypercast.I_PhysicalAddress getPhysicalAddress()
          all these API are added by jianping 3/20/04
 hypercast.I_PhysicalAddress getPhysicalAddress(int index)
           
 org.w3c.dom.Element[] getReadSchema(org.w3c.dom.Document doc, org.apache.xpath.XPath xpath)
          Return the schema element which represents the root of the sub-tree, specified by the given xpath, in read schema tree.
 hypercast.SPT.SPT_LogicalAddress getSPTLogicalAddress()
           
 org.w3c.dom.Element[] getStats(org.w3c.dom.Document doc, org.apache.xpath.XPath xpath)
          Return the result of query for the statistics specified by the given xpath.
 java.lang.String getStatsName()
          Gets the element name of this I_Stats instance.
 org.w3c.dom.Element[] getWriteSchema(org.w3c.dom.Document doc, org.apache.xpath.XPath xpath)
          Return the schema element which represents the root of the sub-tree, specified by the given xpath, in write schema tree.
 boolean isRoot()
           
 void joinOverlay()
          Joins the overlay multicast group.
 void leaveOverlay()
          Leaves the overlay multicast group.
 void messageArrivedFromAdapter(hypercast.I_Message a)
          This function, a member of I_AdapterCallback, is called whenever a protocol message arrives.
 boolean previousHopCheck(hypercast.I_LogicalAddress src, hypercast.I_LogicalAddress dst, hypercast.I_LogicalAddress prehop)
          Verify the previous hop of the message.
 hypercast.I_Message restoreMessage(byte[] buffer, int[] startValidBytes, int endValidBytes)
          Creates a protocol message from a byte[].
 void setLogicalAddress(hypercast.I_LogicalAddress la)
          Sets the logical address of this node to the specified one.
 void setNotificationHandler(hypercast.NotificationHandler nh)
          Set notification handler.
 org.w3c.dom.Element[] setStats(org.w3c.dom.Document doc, org.apache.xpath.XPath xpath, org.w3c.dom.Element newValue)
          Set the statistics specified by the given xpath.
 void setStatsName(java.lang.String name)
          Assigns a name to this I_Stats instance.
 void timerExpired(int timerIndex)
          This function, a member of I_AdapterCallback, is called for the heartbeat timer.
 void timerExpired(java.lang.Object timerID)
          Handles the arrival of a timer
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_adapter

public hypercast.I_MulticastAdapter m_adapter
Multicast adapter (used to transfer protocol message to neighbors)

Constructor Detail

SPT_Node

public SPT_Node(hypercast.HyperCastConfig c,
                hypercast.I_MulticastAdapter m,
                java.lang.String prefix)
Constructor. Read configuration from the property file

Parameters:
c - overlay socket config object
m - node adapter
prefix - the property name prefix
Throws:
java.lang.IllegalArgumentException - if properties are incorrectly formatted.

SPT_Node

public SPT_Node(hypercast.HyperCastConfig c,
                hypercast.I_MulticastAdapter m,
                hypercast.SPT.SPT_LogicalAddress la,
                java.lang.String prefix)
Constructor

Parameters:
c - overlay socket config object
m - node adapter
la - logical address
prefix - property name prefix
Throws:
java.lang.IllegalArgumentException - if properties are incorrectly formatted.
Method Detail

joinOverlay

public void joinOverlay()
Joins the overlay multicast group.

Specified by:
joinOverlay in interface I_Node
See Also:
I_Node.joinOverlay()

leaveOverlay

public void leaveOverlay()
Leaves the overlay multicast group.

Specified by:
leaveOverlay in interface I_Node
See Also:
I_Node.leaveOverlay()

restoreMessage

public hypercast.I_Message restoreMessage(byte[] buffer,
                                          int[] startValidBytes,
                                          int endValidBytes)
Creates a protocol message from a byte[]. Required in order to implement I_AdapterCallback.

Specified by:
restoreMessage in interface I_AdapterCallback
Parameters:
buffer - the byte array buffer of a incoming stream
startValidBytes - the start index to create a message from
endValidBytes - the total length of bytes in this buffer
Returns:
null if buffer does not contain a complete message.
See Also:
I_AdapterCallback.restoreMessage(byte[], int[], int)

getAddressPair

public hypercast.I_AddressPair getAddressPair()
Description copied from interface: I_Node
Returns this logical and physical addresses of this node. This can never be null. (Neither can either the LA or PA part of it.)

Specified by:
getAddressPair in interface I_Node
Returns:
the physical address/logical address pair of this node.

getLogicalAddress

public hypercast.I_LogicalAddress getLogicalAddress()
Returns:
the current logical address

getSPTLogicalAddress

public hypercast.SPT.SPT_LogicalAddress getSPTLogicalAddress()
Returns:
the current SPT logical address

getParent

public hypercast.I_AddressPair[] getParent(hypercast.I_LogicalAddress root)
Description copied from interface: I_Node
Returns the addresspair of the next hop for a message routed by this node towards the root. The next hop would be the node's parent in the spanning tree rooted at root.

Specified by:
getParent in interface I_Node
See Also:
I_Node.getParent(I_LogicalAddress)

getChildren

public hypercast.I_AddressPair[] getChildren(hypercast.I_LogicalAddress root)
Description copied from interface: I_Node
Returns the node's children's physical/logical address pairs, with respect to the spanning tree rooted at root.

Specified by:
getChildren in interface I_Node
See Also:
I_Node.getChildren(I_LogicalAddress)

getAllNeighbors

public hypercast.I_AddressPair[] getAllNeighbors()
Description copied from interface: I_Node
Returns the node's neighbors' physical/logical address pairs.

Specified by:
getAllNeighbors in interface I_Node
Returns:
the AddressPairs of all the neighbors
See Also:
I_Node.getAllNeighbors()

createLogicalAddress

public hypercast.I_LogicalAddress createLogicalAddress(byte[] array,
                                                       int offset)
Constructs a SPT_LogicalAddress from a byte array.

Specified by:
createLogicalAddress in interface I_Node
See Also:
I_Node.createLogicalAddress(byte[], int)

timerExpired

public void timerExpired(int timerIndex)
This function, a member of I_AdapterCallback, is called for the heartbeat timer. When the timer occurs, the node sends Hello messages to all of its neighbors. At the same time, the node checks if any of its neighbors has timed out.

See Also:
I_AdapterCallback.timerExpired(java.lang.Object)

messageArrivedFromAdapter

public void messageArrivedFromAdapter(hypercast.I_Message a)
This function, a member of I_AdapterCallback, is called whenever a protocol message arrives. The function determines the proper reaction to each message type.

Specified by:
messageArrivedFromAdapter in interface I_AdapterCallback
See Also:
I_AdapterCallback.messageArrivedFromAdapter(hypercast.I_Message)

getStatsName

public java.lang.String getStatsName()
Description copied from interface: I_Stats
Gets the element name of this I_Stats instance. The element name is originally assigned from the attribute StstsName in the configuration file, and can be changed by this method.

Specified by:
getStatsName in interface I_Stats
See Also:
I_Stats.getStatsName()

setStatsName

public void setStatsName(java.lang.String name)
Description copied from interface: I_Stats
Assigns a name to this I_Stats instance. The assigned name becomes the tag of the element associated to this I_Stats instance on the statistics tree.

Specified by:
setStatsName in interface I_Stats
Parameters:
name - the name assigned to the I_Stats instance.
See Also:
I_Stats.setStatsName(String)

getStats

public org.w3c.dom.Element[] getStats(org.w3c.dom.Document doc,
                                      org.apache.xpath.XPath xpath)
                               throws HyperCastStatsException
Return the result of query for the statistics specified by the given xpath.

Specified by:
getStats in interface I_Stats
Parameters:
doc - Document used for create new elements or nodes.
xpath - XPath instance represents the statistics to be queried.
Throws:
HyperCastStatsException - If the xpath does not specify a valid subtree.
See Also:
I_Stats.getStats(org.w3c.dom.Document, org.apache.xpath.XPath)

setStats

public org.w3c.dom.Element[] setStats(org.w3c.dom.Document doc,
                                      org.apache.xpath.XPath xpath,
                                      org.w3c.dom.Element newValue)
                               throws HyperCastStatsException
Set the statistics specified by the given xpath. The value actually set is returned.

Specified by:
setStats in interface I_Stats
Parameters:
doc - Document used for create new elements or nodes.
xpath - XPath instance represents the statistics to be queried.
newValue - Element representing the value or sub-tree to be set.
Throws:
HyperCastStatsException - If the xpath does not specify a valid subtree or if any part of the the subtree is read-only, or if the newValue does not conform with the expected format.
See Also:
I_Stats.setStats(org.w3c.dom.Document, org.apache.xpath.XPath, org.w3c.dom.Element)

getReadSchema

public org.w3c.dom.Element[] getReadSchema(org.w3c.dom.Document doc,
                                           org.apache.xpath.XPath xpath)
                                    throws HyperCastStatsException
Return the schema element which represents the root of the sub-tree, specified by the given xpath, in read schema tree.

Specified by:
getReadSchema in interface I_Stats
Parameters:
doc - Document used for create new elements or nodes.
xpath - XPath instance representing the statistics which is the root of the sub-tree to be queried.
Throws:
HyperCastStatsException - If some part of the specified subtree does not correctly implement this interface method.
See Also:
I_Stats.getReadSchema(Document, XPath)

getWriteSchema

public org.w3c.dom.Element[] getWriteSchema(org.w3c.dom.Document doc,
                                            org.apache.xpath.XPath xpath)
                                     throws HyperCastStatsException
Return the schema element which represents the root of the sub-tree, specified by the given xpath, in write schema tree.

Specified by:
getWriteSchema in interface I_Stats
Parameters:
doc - Document used for create new elements or nodes.
xpath - XPath instance representing the statistics which is the root of the sub-tree to be queried.
Throws:
HyperCastStatsException - If some part of the specified subtree does not correctly implement this interface method.
See Also:
I_Stats.getWriteSchema(Document, XPath)

timerExpired

public void timerExpired(java.lang.Object timerID)
Description copied from interface: I_AdapterCallback
Handles the arrival of a timer

Specified by:
timerExpired in interface I_AdapterCallback

getParent

public hypercast.I_AddressPair[] getParent(hypercast.I_LogicalAddress root,
                                           int index)

getChildren

public hypercast.I_AddressPair[] getChildren(hypercast.I_LogicalAddress root,
                                             int index)

getAllNeighbors

public hypercast.I_AddressPair[] getAllNeighbors(int index)

getMyAddressPair

public hypercast.I_AddressPair getMyAddressPair(int index)

createLogicalAddress

public hypercast.I_LogicalAddress createLogicalAddress(byte[] laddr,
                                                       int offset,
                                                       int index)

getPhysicalAddress

public hypercast.I_PhysicalAddress getPhysicalAddress()
all these API are added by jianping 3/20/04


getAllNeighbors

public hypercast.I_AddressPair[] getAllNeighbors(hypercast.I_LogicalAddress root)

getMyAddressPair

public hypercast.I_AddressPair getMyAddressPair(hypercast.I_LogicalAddress root)

getPhysicalAddress

public hypercast.I_PhysicalAddress getPhysicalAddress(int index)

getLogicalAddress

public hypercast.I_LogicalAddress getLogicalAddress(int index)

previousHopCheck

public boolean previousHopCheck(hypercast.I_LogicalAddress src,
                                hypercast.I_LogicalAddress dst,
                                hypercast.I_LogicalAddress prehop)
Verify the previous hop of the message. If checkmode is set to "neighborCheck", this method checks if the previous hop is a neighbor; otherwise this method checks if the previous hop is a valid sender of OL messages.

Specified by:
previousHopCheck in interface I_Node

setNotificationHandler

public void setNotificationHandler(hypercast.NotificationHandler nh)
Set notification handler.

Specified by:
setNotificationHandler in interface I_Node

createLogicalAddress

public hypercast.I_LogicalAddress createLogicalAddress(java.lang.String laStr)
Description copied from interface: I_Node
Creates a logical address object from a String.

Specified by:
createLogicalAddress in interface I_Node

setLogicalAddress

public void setLogicalAddress(hypercast.I_LogicalAddress la)
Sets the logical address of this node to the specified one.

Specified by:
setLogicalAddress in interface I_Node

isRoot

public boolean isRoot()