sg.edu.nus.peer.event
Class SPGeneralAction

java.lang.Object
  extended by sg.edu.nus.peer.event.SPGeneralAction

public class SPGeneralAction
extends java.lang.Object

Implement general methods, which may be used by a variety of listeners

Version:
1.0 2006-2-22
Author:
Vu Quang Hieu

Constructor Summary
SPGeneralAction()
           
 
Method Summary
static boolean checkRotationPull(TreeNode treeNode)
          Check if pulling or deleting of a node affects balance of the tree structure
static boolean checkRotationPush(TreeNode treeNode)
          Check if pushing or adding a node as a child affects balance of the tree structure
static void deleteAllData()
           
static void deleteTreeNode(ServerPeer serverpeer, TreeNode treeNode)
          Delete a node from the system/tree structure
static RoutingItemInfo doAccept(ServerPeer serverpeer, TreeNode treeNode, PhysicalInfo newNodePhysicalInfo, LogicalInfo newNodeLogicalInfo, ContentInfo content, int numOfExpectedRTReply, boolean isFake, boolean direction)
          Accept the new node as a child
static void doFindReplacement(ServerPeer serverpeer, PhysicalInfo physicalInfo, TreeNode treeNode)
          FIND A replacement node for the LEAVING node
static void doLeave(ServerPeer serverpeer, PhysicalInfo physicalInfo, TreeNode treeNode)
          Perform a LEAVE without FINDING a replacement node
static void doLoadBalance(ServerPeer serverpeer, TreeNode treeNode, boolean canLeft, boolean canRight)
          Do local load balancing with adjacent nodes
static int getDataIndexSize()
          implemented by Quang Hieu get the data index size
static java.util.Vector<java.lang.String> getTransferWorkList(TreeNode treeNode, java.lang.String replaceString)
          Transfer remaining work of a leaving node to its parent, may not be necessary later if we remove worklist
static java.util.Vector<IndexValue> loadData()
          implemented by Quang Hieu load data from database to content
static void saveData(java.util.Vector<IndexValue> data)
          implemented by Quang Hieu save data to database from content
static ContentInfo splitData(TreeNode treeNode, boolean direction, int initialOrder)
          Split data to the new node from the current node
static void startRecoveryProcess(ServerPeer serverpeer, TreeNode treeNode, LogicalInfo failedNodeInfo)
          Send requests to lookup information of the failed node to other nodes
static boolean transferFakeNode(ServerPeer serverpeer, TreeNode treeNode, boolean direction, boolean isAccept, PhysicalInfo physicalSender)
          transfer fake node to other physical peer node
static void updateRangeValues(ServerPeer serverpeer, TreeNode treeNode)
          Send messages to update range of values to neighbor nodes
static void updateRotateRoutingTable(ServerPeer serverpeer, TreeNode treeNode)
          Update routing table of a node whose position is changed due to network restructuring
static void updateRoutingTable(ServerPeer serverpeer, TreeNode treeNode, RoutingItemInfo nodeInfo)
          Send update routing table to neighbor nodes
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SPGeneralAction

public SPGeneralAction()
Method Detail

doLoadBalance

public static void doLoadBalance(ServerPeer serverpeer,
                                 TreeNode treeNode,
                                 boolean canLeft,
                                 boolean canRight)
Do local load balancing with adjacent nodes

Parameters:
serverpeer - the handler of ServerPeer
treeNode - information of the current node in the tree structure
canLeft - true can do load balancing with the left adjacent node, false cannot do
canRight - true can do load balancing with the right adjacent node, false cannot do

updateRangeValues

public static void updateRangeValues(ServerPeer serverpeer,
                                     TreeNode treeNode)
Send messages to update range of values to neighbor nodes

Parameters:
serverpeer - the handler of ServerPeer
treeNode - information of the node in the tree structure

updateRotateRoutingTable

public static void updateRotateRoutingTable(ServerPeer serverpeer,
                                            TreeNode treeNode)
Update routing table of a node whose position is changed due to network restructuring

Parameters:
serverpeer - the handler of ServerPeer
treeNode - information of the node in the tree structure

checkRotationPull

public static boolean checkRotationPull(TreeNode treeNode)
Check if pulling or deleting of a node affects balance of the tree structure

Parameters:
treeNode - information of the node in the tree structure
Returns:
true absence of the node doesn't affect the balance of the tree, false absence of the node may cause imbalance of the tree

checkRotationPush

public static boolean checkRotationPush(TreeNode treeNode)
Check if pushing or adding a node as a child affects balance of the tree structure

Parameters:
treeNode - information of the node in the tree structure
Returns:
true adding of a node as a child doesn't affect the balance of the tree, false adding of a node as a child affects the balance of the tree

doAccept

public static RoutingItemInfo doAccept(ServerPeer serverpeer,
                                       TreeNode treeNode,
                                       PhysicalInfo newNodePhysicalInfo,
                                       LogicalInfo newNodeLogicalInfo,
                                       ContentInfo content,
                                       int numOfExpectedRTReply,
                                       boolean isFake,
                                       boolean direction)
Accept the new node as a child

Parameters:
treeNode - information of the node in the tree structure
newNodePhysicalInfo - physical address of the new node
newNodeLogicalInfo - logical address of the new node
content - range of values, data in charge by the new node
numOfExpectedRTReply - number of routing table replies expected to receive
isFake - true: the new node is a fake node, which is created for network restructuring purpose and will be transfered to another node, false: the new node is a real new joining node
direction - direction of doing rotation, only has meaning if isFake is true
Returns:
information of the new node

splitData

public static ContentInfo splitData(TreeNode treeNode,
                                    boolean direction,
                                    int initialOrder)
Split data to the new node from the current node

Parameters:
treeNode - information of the node in the tree structure
direction - splitting direction
initialOrder - predefined order of the system
Returns:
range of values and data in charged by the new node

updateRoutingTable

public static void updateRoutingTable(ServerPeer serverpeer,
                                      TreeNode treeNode,
                                      RoutingItemInfo nodeInfo)
Send update routing table to neighbor nodes

Parameters:
treeNode - information of the node in the tree structure
nodeInfo - information of the updated/changed node

deleteTreeNode

public static void deleteTreeNode(ServerPeer serverpeer,
                                  TreeNode treeNode)
Delete a node from the system/tree structure

Parameters:
treeNode - information of the node in the tree structure

getTransferWorkList

public static java.util.Vector<java.lang.String> getTransferWorkList(TreeNode treeNode,
                                                                     java.lang.String replaceString)
Transfer remaining work of a leaving node to its parent, may not be necessary later if we remove worklist

Parameters:
treeNode - information of the node in the tree structure
replaceString - identifier of the node taking charge of the remaining work (parent of the leaving node)
Returns:
list of remaining work

transferFakeNode

public static boolean transferFakeNode(ServerPeer serverpeer,
                                       TreeNode treeNode,
                                       boolean direction,
                                       boolean isAccept,
                                       PhysicalInfo physicalSender)
transfer fake node to other physical peer node

Parameters:
treeNode - TreeNode
direction - boolean

startRecoveryProcess

public static void startRecoveryProcess(ServerPeer serverpeer,
                                        TreeNode treeNode,
                                        LogicalInfo failedNodeInfo)
Send requests to lookup information of the failed node to other nodes

Parameters:
treeNode - information of the node in the tree structure
nodeInfo - information of the failed node Algorithm: if it is a parent node, starts recovery process Otherwise, notify the parent of the failed node Messages: SPLINeighbor, SPLIChild, SPLIAdjacent SPLINeighborReply, SPLIChildReply, SPLIAdjacentReply... First step: only a parent node pings it children Failed node has no child. Do nothing, load balancing can be triggered automatically later If the failed node has a child, it should have a sibling The sibling node takes responsible for report child info

doLeave

public static void doLeave(ServerPeer serverpeer,
                           PhysicalInfo physicalInfo,
                           TreeNode treeNode)
                    throws java.lang.Exception
Perform a LEAVE without FINDING a replacement node

Parameters:
treeNode -
Throws:
java.lang.Exception

doFindReplacement

public static void doFindReplacement(ServerPeer serverpeer,
                                     PhysicalInfo physicalInfo,
                                     TreeNode treeNode)
                              throws java.lang.Exception
FIND A replacement node for the LEAVING node

Parameters:
treeNode -
Throws:
java.lang.Exception

getDataIndexSize

public static int getDataIndexSize()
implemented by Quang Hieu get the data index size

Returns:

loadData

public static java.util.Vector<IndexValue> loadData()
implemented by Quang Hieu load data from database to content


deleteAllData

public static void deleteAllData()

saveData

public static void saveData(java.util.Vector<IndexValue> data)
implemented by Quang Hieu save data to database from content