Rice Pastry API

rice.pastry.leafset
Class LeafSet

java.lang.Object
  |
  +--java.util.Observable
        |
        +--rice.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,v 1.37 2003/07/24 11:54:02 amislove Exp $
Author:
Andrew Ladd, Peter Druschel
See Also:
Serialized Form

Constructor Summary
LeafSet(rice.pastry.NodeHandle localNode, int size)
          Constructor.
 
Method Summary
 void addObserver(java.util.Observer o)
          Add observer method.
 int ccwSize()
          Gets the current counterclockwise size.
 int cwSize()
          Gets the current clockwise size.
 void deleteObserver(java.util.Observer o)
          Delete observer method.
 rice.pastry.NodeHandle get(int index)
          Finds the NodeHandle at a given index.
 rice.pastry.NodeHandle get(rice.pastry.NodeId nid)
          Finds the NodeHandle associated with the NodeId.
 int getIndex(rice.pastry.NodeId nid)
          Gets the index of the element with the given node id.
 int maxSize()
          Gets the maximal size of the leaf set.
 boolean member(rice.pastry.NodeId nid)
          Verifies if the set contains this particular id.
 boolean merge(rice.pastry.leafset.LeafSet remotels, rice.pastry.NodeHandle from, rice.pastry.routing.RoutingTable routeTable, rice.pastry.security.PastrySecurityManager security, boolean testOnly, java.util.Set insertedHandles)
          Merge a remote leafset into this
 int mostSimilar(rice.pastry.Id nid)
          Numerically closests node to a given a node in the leaf set.
 rice.pastry.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(rice.pastry.NodeHandle handle)
          Puts a NodeHandle into the set.
 rice.pastry.IdRange range(rice.pastry.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
 rice.pastry.IdRange range(rice.pastry.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
 rice.pastry.NodeHandle remove(rice.pastry.NodeId nid)
          Removes a node id and its handle from the set.
 rice.pastry.NodeSet replicaSet(rice.pastry.Id key, int max)
          compute an ordered set of nodes, in order of numerical closeness to a given key
 int size()
          Gets the current size of the leaf set.
 boolean test(rice.pastry.NodeHandle handle)
          Test if a put of the given NodeHandle would succeed.
 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(rice.pastry.NodeHandle localNode,
               int size)
Constructor.

Parameters:
size - the size of the leaf set.
Method Detail

put

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

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

test

public boolean test(rice.pastry.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

get

public rice.pastry.NodeHandle get(rice.pastry.NodeId nid)
Finds the NodeHandle associated with the NodeId.

Parameters:
nid - a node id.
Returns:
the handle associated with that id or null if no such handle is found.

getIndex

public int getIndex(rice.pastry.NodeId nid)
             throws java.util.NoSuchElementException
Gets the index of the element with the given node id.

Parameters:
nid - the node id.
Returns:
the index or throws a NoSuchElementException
java.util.NoSuchElementException

get

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

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

member

public boolean member(rice.pastry.NodeId 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 rice.pastry.NodeHandle remove(rice.pastry.NodeId nid)
Removes a node id and its handle from the set.

Parameters:
nid - the node to remove.
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.

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(rice.pastry.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 rice.pastry.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 rice.pastry.NodeSet replicaSet(rice.pastry.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 rice.pastry.IdRange range(rice.pastry.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 rice.pastry.IdRange range(rice.pastry.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(rice.pastry.leafset.LeafSet remotels,
                     rice.pastry.NodeHandle from,
                     rice.pastry.routing.RoutingTable routeTable,
                     rice.pastry.security.PastrySecurityManager security,
                     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
security - the security manager
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)
Add observer method.

Overrides:
addObserver in class java.util.Observable
Parameters:
o - the observer to add.

deleteObserver

public void deleteObserver(java.util.Observer o)
Delete observer method.

Overrides:
deleteObserver in class java.util.Observable
Parameters:
o - the observer to delete.

toString

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

Overrides:
toString in class java.lang.Object

Rice Pastry API

Copyright © 2001 - Rice Pastry.


Imprint-Dataprotection