Rice Pastry API

rice.pastry.leafset
Class SimilarSet

java.lang.Object
  |
  +--java.util.Observable
        |
        +--rice.pastry.leafset.SimilarSet
All Implemented Interfaces:
NodeHandleSet, NodeSetI, java.util.Observer, java.io.Serializable

public class SimilarSet
extends java.util.Observable
implements NodeSetI, java.io.Serializable, java.util.Observer

A set of nodes, ordered by numerical distance of their nodeId from the local nodeId

Version:
$Id: SimilarSet.java,v 1.20 2003/05/09 22:47:47 amislove Exp $
Author:
Andrew Ladd, Peter Druschel
See Also:
Serialized Form

Constructor Summary
SimilarSet(rice.pastry.NodeHandle localNode, int size, boolean cw)
          Constructor.
 
Method Summary
 rice.pastry.NodeHandle get(int i)
          Gets the ith element in the set.
 rice.pastry.NodeHandle get(rice.pastry.NodeId nid)
          Finds the NodeHandle associated with the NodeId.
 rice.p2p.commonapi.NodeHandle getHandle(rice.p2p.commonapi.Id id)
          Finds the NodeHandle associated with the NodeId.
 rice.p2p.commonapi.NodeHandle getHandle(int i)
          Gets the ith element in the set.
 int getIndex(rice.pastry.NodeId nid)
          Gets the index of the element with the given node id.
 int getIndexHandle(rice.p2p.commonapi.Id id)
          Gets the index of the element with the given node id.
 boolean member(rice.pastry.NodeId nid)
          Verifies if the set contains this particular id.
 boolean memberHandle(rice.p2p.commonapi.Id id)
          Verifies if the set contains this particular id.
 int mostSimilar(rice.pastry.Id nid)
          Numerically closest node to a given a node.
 boolean put(rice.pastry.NodeHandle handle)
          Puts a NodeHandle into the set.
 boolean putHandle(rice.p2p.commonapi.NodeHandle handle)
          Puts a NodeHandle into the set.
 rice.pastry.NodeHandle remove(int i)
          Removes a node id and its handle from the set.
 rice.pastry.NodeHandle remove(rice.pastry.NodeId nid)
          Removes a node id and its handle from the set.
 rice.p2p.commonapi.NodeHandle removeHandle(rice.p2p.commonapi.Id id)
          Removes a node id and its handle from the set.
 int size()
          Gets the current size of this set.
protected  void swap(int i, int j)
          swap two elements
 boolean test(rice.pastry.NodeHandle handle)
          Test if a NodeHandle belongs into the set.
 void update(java.util.Observable o, java.lang.Object arg)
          Is called by the Observer pattern whenever the liveness or proximity of a registered node handle is changed.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimilarSet

public SimilarSet(rice.pastry.NodeHandle localNode,
                  int size,
                  boolean cw)
Constructor.

Parameters:
localNode - the local node
size - the size of the similar set.
cw - true if this is the clockwise leafset half
Method Detail

swap

protected void swap(int i,
                    int j)
swap two elements

Parameters:
i - the index of the first element
j - the indes of the second element

test

public boolean test(rice.pastry.NodeHandle handle)
Test if a NodeHandle belongs into the set. Predicts if a put would succeed.

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

put

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

Specified by:
put in interface NodeSetI
Parameters:
handle - the handle to put.
Returns:
true if the put succeeded, false otherwise.

update

public void update(java.util.Observable o,
                   java.lang.Object arg)
Is called by the Observer pattern whenever the liveness or proximity of a registered node handle is changed.

Specified by:
update in interface java.util.Observer
Parameters:
o - The node handle
arg - the event type (PROXIMITY_CHANGE, DECLARED_LIVE, DECLARED_DEAD)

get

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

Specified by:
get in interface NodeSetI
Parameters:
nid - a node id.
Returns:
the handle associated with that id or null if no such handle is found.

get

public rice.pastry.NodeHandle get(int i)
Gets the ith element in the set.

Specified by:
get in interface NodeSetI
Parameters:
i - an index. i == -1 refers to the local node
Returns:
the handle associated with that id or null if no such handle is found.

member

public boolean member(rice.pastry.NodeId nid)
Verifies if the set contains this particular id.

Specified by:
member in interface NodeSetI
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.

Specified by:
remove in interface NodeSetI
Parameters:
nid - the node to remove.
Returns:
the node handle removed or null if nothing.

remove

public rice.pastry.NodeHandle remove(int i)
Removes a node id and its handle from the set.

Parameters:
i - the index of the node to remove.
Returns:
the node handle removed or null if nothing.

getIndex

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

Specified by:
getIndex in interface NodeSetI
Parameters:
nid - the node id.
Returns:
the index or -1 if the element does not exist.

size

public int size()
Gets the current size of this set.

Specified by:
size in interface NodeSetI
Returns:
the size.

mostSimilar

public int mostSimilar(rice.pastry.Id nid)
Numerically closest node to a given a node. Returns -1 if the local nodeId is the most similar and returns an index otherwise.

Parameters:
nid - a node id.
Returns:
-1 if the local nodeId is most similar, else the index of the most similar node.

putHandle

public boolean putHandle(rice.p2p.commonapi.NodeHandle handle)
Puts a NodeHandle into the set.

Specified by:
putHandle in interface NodeHandleSet
Parameters:
handle - the handle to put.
Returns:
true if the put succeeded, false otherwise.

getHandle

public rice.p2p.commonapi.NodeHandle getHandle(rice.p2p.commonapi.Id id)
Finds the NodeHandle associated with the NodeId.

Specified by:
getHandle in interface NodeHandleSet
Parameters:
id - a node id.
Returns:
the handle associated with that id or null if no such handle is found.

getHandle

public rice.p2p.commonapi.NodeHandle getHandle(int i)
Gets the ith element in the set.

Specified by:
getHandle in interface NodeHandleSet
Parameters:
i - an index.
Returns:
the handle associated with that id or null if no such handle is found.

memberHandle

public boolean memberHandle(rice.p2p.commonapi.Id id)
Verifies if the set contains this particular id.

Specified by:
memberHandle in interface NodeHandleSet
Parameters:
id - a node id.
Returns:
true if that node id is in the set, false otherwise.

removeHandle

public rice.p2p.commonapi.NodeHandle removeHandle(rice.p2p.commonapi.Id id)
Removes a node id and its handle from the set.

Specified by:
removeHandle in interface NodeHandleSet
Returns:
the node handle removed or null if nothing.

getIndexHandle

public int getIndexHandle(rice.p2p.commonapi.Id id)
                   throws java.util.NoSuchElementException
Gets the index of the element with the given node id.

Specified by:
getIndexHandle in interface NodeHandleSet
Parameters:
id - the id.
Returns:
the index or throws a NoSuchElementException.
java.util.NoSuchElementException

Rice Pastry API

Copyright © 2001 - Rice Pastry.


Imprint-Dataprotection