Rice Pastry API

rice.pastry.leafset
Class LeafSet

java.lang.Object
  extended byjava.util.Observable
      extended byrice.pastry.leafset.LeafSet
All Implemented Interfaces:
java.io.Serializable

public class LeafSet
extends java.util.Observable
implements java.io.Serializable

A class for representing and manipulating the leaf set. The leafset is not strictly a set: when the ring is small, a node may appear in both the cw and the ccw half of the "set".

Version:
$Id: LeafSet.java 3274 2006-05-15 16:17:47Z jeffh $
Author:
Andrew Ladd, Peter Druschel
See Also:
Serialized Form

Constructor Summary
LeafSet(NodeHandle localNode, int size)
          Constructor.
LeafSet(NodeHandle localNode, int size, boolean observe)
          Constructor for LeafSet.
LeafSet(NodeHandle localNode, int size, boolean observe, NodeHandle[] cwTable, NodeHandle[] ccwTable)
          Constructor for LeafSet.
 
Method Summary
 void addNodeSetListener(NodeSetListener listener)
          Add observer method.
 void addObserver(java.util.Observer o)
          Deprecated. use addNodeSetListener
static LeafSet build(InputBuffer buf, NodeHandleFactory nhf)
          So that small LeafSets (who have overlapping nodes) don't waste bandwidth, leafset first defines the NodeHandles to be loaded into an array, then specifies their locations.
 int ccwSize()
          Gets the current counterclockwise size.
 LeafSet copy()
          DESCRIBE THE METHOD
 int cwSize()
          Gets the current clockwise size.
 void deleteNodeSetListener(NodeSetListener listener)
          Delete observer method.
 void deleteObserver(java.util.Observer o)
          Deprecated. use deleteNodeSetListener
 boolean directTest(NodeHandle handle)
          DESCRIBE THE METHOD
 NodeHandle get(int index)
          Finds the NodeHandle at a given index.
 int getIndex(NodeHandle nh)
          Gets the Index attribute of the LeafSet object
 int getUniqueCount()
          Returns the number of unique nodes in the leafset
 boolean isComplete()
          Gets the Complete attribute of the LeafSet object
protected  boolean isProperlyRemoved(NodeHandle handle)
          Gets the ProperlyRemoved attribute of the LeafSet object
 int maxSize()
          Gets the maximal size of the leaf set.
 boolean member(Id nid)
          Verifies if the set contains this particular id.
 boolean member(NodeHandle nid)
          Verifies if the set contains this particular handle.
 boolean merge(LeafSet remotels, NodeHandle from, RoutingTable routeTable, boolean testOnly, java.util.Set insertedHandles)
          Merge a remote leafset into this
 int mostSimilar(Id nid)
          Numerically closests node to a given a node in the leaf set.
 NodeSet neighborSet(int max)
          compute an ordered set of nodes that are neighbors of this local node, in order of numerical closeness to the local node
 boolean overlaps()
          Test if the leafset overlaps
 boolean put(NodeHandle handle)
          Puts a NodeHandle into the set.
 IdRange range(NodeHandle n, int r)
          range computes the range of keys for which node n is a i-root, 0<=i<=r a node is the r-root for a key of the node becomes the numerically closest node to the key when i-roots for the key fail, O<=i
 IdRange range(NodeHandle n, int r, boolean cw)
          range computes the ranges of keys for which node n is a r-root a node is the r-root for a key of the node becomes the numerically closest node to the key when i-roots for the key fail, O<=i
 NodeHandle remove(NodeHandle nh)
          Removes a node id and its handle from the set.
 NodeSet replicaSet(Id key, int max)
          compute an ordered set of nodes, in order of numerical closeness to a given key
 void serialize(OutputBuffer buf)
          So that small LeafSets (who have overlapping nodes) don't waste bandwidth, leafset first defines the NodeHandles to be loaded into an array, then specifies their locations.
 int size()
          Gets the current size of the leaf set.
 boolean test(NodeHandle handle)
          Test if a put of the given NodeHandle would succeed.
protected  boolean testOtherSet(SimilarSet set, NodeHandle handle)
          A unit test for JUnit
 java.lang.String toString()
          Returns a string representation of the leaf set
 
Methods inherited from class java.util.Observable
clearChanged, countObservers, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LeafSet

public LeafSet(NodeHandle localNode,
               int size)
Constructor.

Parameters:
size - the size of the leaf set.
localNode - DESCRIBE THE PARAMETER

LeafSet

public LeafSet(NodeHandle localNode,
               int size,
               boolean observe)
Constructor for LeafSet.

Parameters:
localNode - DESCRIBE THE PARAMETER
size - DESCRIBE THE PARAMETER
observe - DESCRIBE THE PARAMETER

LeafSet

public LeafSet(NodeHandle localNode,
               int size,
               boolean observe,
               NodeHandle[] cwTable,
               NodeHandle[] ccwTable)
Constructor for LeafSet.

Parameters:
localNode - DESCRIBE THE PARAMETER
size - DESCRIBE THE PARAMETER
observe - DESCRIBE THE PARAMETER
cwTable - DESCRIBE THE PARAMETER
ccwTable - DESCRIBE THE PARAMETER
Method Detail

isComplete

public boolean isComplete()
Gets the Complete attribute of the LeafSet object

Returns:
The Complete value

getIndex

public int getIndex(NodeHandle nh)
             throws java.util.NoSuchElementException
Gets the Index attribute of the LeafSet object

Parameters:
nh - DESCRIBE THE PARAMETER
Returns:
The Index value
Throws:
java.util.NoSuchElementException - DESCRIBE THE EXCEPTION

get

public NodeHandle get(int index)
Finds the NodeHandle at a given index.

Parameters:
index - an index.
Returns:
the handle associated with that index.

getUniqueCount

public int getUniqueCount()
Returns the number of unique nodes in the leafset

Returns:
the number of unique nodes in the leafset

isProperlyRemoved

protected boolean isProperlyRemoved(NodeHandle handle)
Gets the ProperlyRemoved attribute of the LeafSet object

Parameters:
handle - DESCRIBE THE PARAMETER
Returns:
The ProperlyRemoved value

put

public boolean put(NodeHandle handle)
Puts a NodeHandle into the set.

Parameters:
handle - the handle to put.
Returns:
true if successful, false otherwise.

test

public boolean test(NodeHandle handle)
Test if a put of the given NodeHandle would succeed.

Parameters:
handle - the handle to test.
Returns:
true if a put would succeed, false otherwise.

overlaps

public boolean overlaps()
Test if the leafset overlaps

Returns:
true if the most distant cw member appears in the ccw set or vice versa, false otherwise

member

public boolean member(NodeHandle nid)
Verifies if the set contains this particular handle.

Parameters:
nid - a NodeHandle.
Returns:
true if that NodeHandle is in the set, false otherwise.

member

public boolean member(Id nid)
Verifies if the set contains this particular id.

Parameters:
nid - a node id.
Returns:
true if that node id is in the set, false otherwise.

remove

public NodeHandle remove(NodeHandle nh)
Removes a node id and its handle from the set.

Parameters:
nh - DESCRIBE THE PARAMETER
Returns:
the node handle removed or null if nothing.

maxSize

public int maxSize()
Gets the maximal size of the leaf set.

Returns:
the size.

size

public int size()
Gets the current size of the leaf set. Note that if the leafset overlaps, there will be duplicates. If you want the unique nodes, use getUniqueCount().

Returns:
the size.

cwSize

public int cwSize()
Gets the current clockwise size.

Returns:
the size.

ccwSize

public int ccwSize()
Gets the current counterclockwise size.

Returns:
the size.

mostSimilar

public int mostSimilar(Id nid)
Numerically closests node to a given a node in the leaf set.

Parameters:
nid - a node id.
Returns:
the index of the numerically closest node (0 if baseId is the closest).

neighborSet

public NodeSet neighborSet(int max)
compute an ordered set of nodes that are neighbors of this local node, in order of numerical closeness to the local node

Parameters:
max - the maximal size of the set requested
Returns:
the ordered set of nodehandles

replicaSet

public NodeSet replicaSet(Id key,
                          int max)
compute an ordered set of nodes, in order of numerical closeness to a given key

Parameters:
key - the key
max - the maximal size of the set requested
Returns:
the ordered set of nodehandles

range

public IdRange range(NodeHandle n,
                     int r)
range computes the range of keys for which node n is a i-root, 0<=i<=r a node is the r-root for a key of the node becomes the numerically closest node to the key when i-roots for the key fail, O<=i
Parameters:
n - the nodehandle
r -
Returns:
the range of keys, or null if n is not a member of the leafset, or if the range cannot be computed

range

public IdRange range(NodeHandle n,
                     int r,
                     boolean cw)
range computes the ranges of keys for which node n is a r-root a node is the r-root for a key of the node becomes the numerically closest node to the key when i-roots for the key fail, O<=i
Parameters:
n - the nodehandle
r -
cw - if true returns the clockwise range, else the counterclockwise range
Returns:
the range of keys, or null if n is not a member of the leafset, or if the range cannot be computed

merge

public boolean merge(LeafSet remotels,
                     NodeHandle from,
                     RoutingTable routeTable,
                     boolean testOnly,
                     java.util.Set insertedHandles)
Merge a remote leafset into this

Parameters:
remotels - the remote leafset
from - the node from which we received the leafset
routeTable - the routing table
testOnly - if true, do not change the leafset
insertedHandles - if not null, a Set that contains, upon return of this method, the nodeHandles that would be inserted into this LeafSet if testOnly is true
Returns:
true if the local leafset changed

addObserver

public void addObserver(java.util.Observer o)
Deprecated. use addNodeSetListener

Add observer method.

Parameters:
o - the observer to add.

deleteObserver

public void deleteObserver(java.util.Observer o)
Deprecated. use deleteNodeSetListener

Delete observer method.

Parameters:
o - the observer to delete.

addNodeSetListener

public void addNodeSetListener(NodeSetListener listener)
Add observer method.

Parameters:
listener - The feature to be added to the NodeSetListener attribute

deleteNodeSetListener

public void deleteNodeSetListener(NodeSetListener listener)
Delete observer method.

Parameters:
listener - DESCRIBE THE PARAMETER

toString

public java.lang.String toString()
Returns a string representation of the leaf set

Returns:
DESCRIBE THE RETURN VALUE

testOtherSet

protected boolean testOtherSet(SimilarSet set,
                               NodeHandle handle)
A unit test for JUnit

Parameters:
set - DESCRIBE THE PARAMETER
handle - DESCRIBE THE PARAMETER
Returns:
DESCRIBE THE RETURN VALUE

directTest

public boolean directTest(NodeHandle handle)
DESCRIBE THE METHOD

Parameters:
handle - DESCRIBE THE PARAMETER
Returns:
DESCRIBE THE RETURN VALUE

copy

public LeafSet copy()
DESCRIBE THE METHOD

Returns:
DESCRIBE THE RETURN VALUE

serialize

public void serialize(OutputBuffer buf)
               throws java.io.IOException
So that small LeafSets (who have overlapping nodes) don't waste bandwidth, leafset first defines the NodeHandles to be loaded into an array, then specifies their locations. We do this because a NodeHandle takes up a lot more space than the index in the leafset, and it may be in the leafset 1 or 2 times. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + byte theSize +numUniqueHandls+ byte cwSize + byte ccwSize + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + NodeHandle baseHandle + ... + + + + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + NodeHandle 1st + ... + + + + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + NodeHandle numUniqueHandls-th + ... + + + + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + byte cw 1st + cw 2nd + ... + ccw 1st + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + ccw 2nd + ... + ... + ccw Nth + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ TODO 2.23.2006 the synchronization of LeafSet is nonexistent and it's difficult to add because the listeneer interface should not be called while holding a lock, but the lock should be acquired once while making the change

Parameters:
buf - DESCRIBE THE PARAMETER
Throws:
java.io.IOException - DESCRIBE THE EXCEPTION

build

public static LeafSet build(InputBuffer buf,
                            NodeHandleFactory nhf)
                     throws java.io.IOException
So that small LeafSets (who have overlapping nodes) don't waste bandwidth, leafset first defines the NodeHandles to be loaded into an array, then specifies their locations. We do this because a NodeHandle takes up a lot more space than the index in the leafset, and it may be in the leafset 1 or 2 times. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + byte theSize +numUniqueHandls+ byte cwSize + byte ccwSize + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + NodeHandle baseHandle + ... + + + + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + NodeHandle 1st + ... + + + + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + NodeHandle numUniqueHandls-th + ... + + + + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + byte cw 1st + cw 2nd + ... + ccw 1st + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + ccw 2nd + ... + ... + ccw Nth + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Parameters:
buf - DESCRIBE THE PARAMETER
nhf - DESCRIBE THE PARAMETER
Returns:
DESCRIBE THE RETURN VALUE
Throws:
java.io.IOException - DESCRIBE THE EXCEPTION

Rice Pastry API

Copyright © 2001-2005 - Rice Pastry.


Imprint-Dataprotection