org.planx.xmlstore.routing
Class Space

java.lang.Object
  extended by org.planx.xmlstore.routing.Space

public class Space
extends Object

Represents a space (or subspace) containing nodes. The spaces are organized in a binary tree where only the leaf spaces have buckets containing nodes. The internal spaces each contain exactly two child spaces (never one).

All identifiers are transformed from the real identifier space to the "distance from the local node"-space using the XOR metric. In other words, the local node has id 0 and the ids increase as the distance from the local node increases. Note that this is a loss-free transformation in that the original id can be recovered by the XOR of the id in this space and the id of the local node in the real space.

Space is synchronized.


Constructor Summary
Space(Node local, Configuration conf)
          Construct an empty top level space that covers the complete range of identifiers.
Space(Node local, Configuration conf, KademliaNeighbourhoodListener listener)
          Construct an empty top level space that covers the complete range of identifiers.
 
Method Summary
 void addNeighbourhoodListener(NeighbourhoodListener listener)
           
 List getAll()
          Returns all nodes in the tree of spaces rooted at this space.
 List getClosestNodes(Identifier id)
          Returns the K nodes known by this space closest to the specified id.
 List getNeighbourhood()
          Returns all nodes in the neighbourhood of the local node.
 List getRefreshList()
          Returns a list containing random Identifiers in bucket ranges that needs to be refreshed.
 void insertNode(Node newNode)
          Inserts the specified node into this space.
 int nodeCount()
          Returns the number of nodes in the range covered by this space.
 void removeNeighbourhoodListener(NeighbourhoodListener listener)
           
 boolean removeNode(Node node)
          Marks a node as unresponsive and removes it from the tree of spaces rooted at this space if it has been marked in this way STALE times.
 String toString()
          For debugging purposes, returns a string containing an XML document representing the binary tree of spaces rooted at this space.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Space

public Space(Node local,
             Configuration conf)
Construct an empty top level space that covers the complete range of identifiers. The local node is inserted into the space and this will call the listener.


Space

public Space(Node local,
             Configuration conf,
             KademliaNeighbourhoodListener listener)
Construct an empty top level space that covers the complete range of identifiers. The local node is inserted into the space and this will call the listener.

Parameters:
local - The local node
conf - Configuration parameters
listener - A listener for arriving nodes in the neighbourhood of the local node
Method Detail

addNeighbourhoodListener

public void addNeighbourhoodListener(NeighbourhoodListener listener)

removeNeighbourhoodListener

public void removeNeighbourhoodListener(NeighbourhoodListener listener)

getClosestNodes

public List getClosestNodes(Identifier id)
Returns the K nodes known by this space closest to the specified id. The order of the nodes is not specified.


removeNode

public boolean removeNode(Node node)
Marks a node as unresponsive and removes it from the tree of spaces rooted at this space if it has been marked in this way STALE times. Returns true if the node was actually removed.


insertNode

public void insertNode(Node newNode)
Inserts the specified node into this space. Depending on the distance from the local node the new node is either dropped or inserted. The node is inserted if the bucket to which it should belong is not full (i.e. contains less than K nodes) or in some cases a full bucket is split in order to make room for the node. A bucket is split if either the space contains the local node or the split is needed because of an unbalanced tree.


getRefreshList

public List getRefreshList()
Returns a list containing random Identifiers in bucket ranges that needs to be refreshed. Currently all "buckets" are refreshed. This is "buckets" in the sense of possible buckets in a fully populated tree of spaces. Thus, there are IDSIZE buckets in this interpretation. The first bucket containing only the local node is skipped.


getAll

public List getAll()
Returns all nodes in the tree of spaces rooted at this space. The nodes' order is not specified.


getNeighbourhood

public List getNeighbourhood()
Returns all nodes in the neighbourhood of the local node. The neighbourhood is the smallest subspace around the local node with at least K nodes.


nodeCount

public int nodeCount()
Returns the number of nodes in the range covered by this space.


toString

public String toString()
For debugging purposes, returns a string containing an XML document representing the binary tree of spaces rooted at this space.

Overrides:
toString in class Object


Copyright © 2010. All Rights Reserved.