Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.ubermq.chord
Class AbstractChordNode  view AbstractChordNode download AbstractChordNode.java

java.lang.Object
  extended bycom.ubermq.chord.AbstractChordNode
All Implemented Interfaces:
ChordNode

public abstract class AbstractChordNode
extends java.lang.Object
implements ChordNode


Field Summary
private  java.util.List fingers
           
private  ChordIdentifier identifier
           
private  ChordInfrastructure infrastructure
           
private  ChordNode predecessor
           
private static java.util.Random random
           
 
Constructor Summary
protected AbstractChordNode(ChordIdentifier ident, int m, ChordNode fingerInitialValue)
          Creates an abstract chord node with the given identifier.
 
Method Summary
 ChordNode closestPrecedingFinger(ChordIdentifier id)
          Returns the element of the finger table that most closely precedes the given identifier.
 boolean equals(java.lang.Object o)
          Tests for equality based exclusively on the identifier value.
 ChordNode[] fingers()
          Returns the finger table for this node.
 void fixFingers()
          Fixes the finger table.
 int hashCode()
          Get a value that represents this Object, as uniquely as possible within the confines of an int.
 ChordIdentifier identifier()
          Returns the identifier for this node.
 void join(ChordInfrastructure i)
          The default implementation of join relies on the stabilize protocol to setup finger table entries over time.
protected abstract  java.util.Collection keys()
          Returns a collection of keys that are stored locally at this node.
 void leave(ChordInfrastructure i)
          Leaves the infrastructure, by notifying the immediate predecessor that we are going away.
protected abstract  void moveItem(java.lang.Object key, ChordNode destination)
          Moves an item from the local data store to another node as specified.
 void notify(ChordNode x)
          Notifies us that x is our predecessor.
 void notifyGoingAway(ChordNode x)
          Instructs the node that the specified node is leaving the infrastructure.
 ChordNode predecessor()
          Returns the predecessor of this node, defined as the node n such that n.successor() == this.
 void stabilize()
          Stabilizes this node by verifying the immediate successor node is correct.
 ChordNode successor()
          Returns the successor of this node.
 java.lang.String toHtml()
          Returns an in-depth HTML description of this chord node.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.ubermq.chord.ChordNode
close, query, store
 

Field Detail

infrastructure

private ChordInfrastructure infrastructure

identifier

private final ChordIdentifier identifier

predecessor

private ChordNode predecessor

fingers

private final java.util.List fingers

random

private static final java.util.Random random
Constructor Detail

AbstractChordNode

protected AbstractChordNode(ChordIdentifier ident,
                            int m,
                            ChordNode fingerInitialValue)
Creates an abstract chord node with the given identifier. The successor, predecessor and finger tables will be null until the node joins an infrastructure.

Method Detail

identifier

public final ChordIdentifier identifier()
Description copied from interface: ChordNode
Returns the identifier for this node.

Specified by:
identifier in interface ChordNode

successor

public final ChordNode successor()
Description copied from interface: ChordNode
Returns the successor of this node.

Specified by:
successor in interface ChordNode

predecessor

public final ChordNode predecessor()
Description copied from interface: ChordNode
Returns the predecessor of this node, defined as the node n such that n.successor() == this.

Specified by:
predecessor in interface ChordNode

fingers

public final ChordNode[] fingers()
Description copied from interface: ChordNode
Returns the finger table for this node. The finger table is a set of nodes, such that the ith entry contains the identity of the first node that succeeds this node by at least 2 i-1 on the identifier circle.

Specified by:
fingers in interface ChordNode

join

public void join(ChordInfrastructure i)
The default implementation of join relies on the stabilize protocol to setup finger table entries over time.

Specified by:
join in interface ChordNode

leave

public void leave(ChordInfrastructure i)
Description copied from interface: ChordNode
Leaves the infrastructure, by notifying the immediate predecessor that we are going away.

Specified by:
leave in interface ChordNode

stabilize

public void stabilize()
Stabilizes this node by verifying the immediate successor node is correct. We also notify the successor about ourselves so it knows that we are the correct predecessor.

This method should be executed periodically to ensure correctness.


fixFingers

public void fixFingers()
Fixes the finger table. Chooses a finger at random and updates it. This method should be executed periodically to ensure correctness.


notify

public void notify(ChordNode x)
Notifies us that x is our predecessor.

Specified by:
notify in interface ChordNode

notifyGoingAway

public void notifyGoingAway(ChordNode x)
Description copied from interface: ChordNode
Instructs the node that the specified node is leaving the infrastructure. This may be received by an existing predecessor or successor node.

Specified by:
notifyGoingAway in interface ChordNode

closestPrecedingFinger

public ChordNode closestPrecedingFinger(ChordIdentifier id)
Returns the element of the finger table that most closely precedes the given identifier.

This is an implementation of the algorithm specified in the Chord paper [Stoica, et al] in Figure 4.

Specified by:
closestPrecedingFinger in interface ChordNode

hashCode

public int hashCode()
Description copied from class: java.lang.Object
Get a value that represents this Object, as uniquely as possible within the confines of an int.

There are some requirements on this method which subclasses must follow:

  • Semantic equality implies identical hashcodes. In other words, if a.equals(b) is true, then a.hashCode() == b.hashCode() must be as well. However, the reverse is not necessarily true, and two objects may have the same hashcode without being equal.
  • It must be consistent. Whichever value o.hashCode() returns on the first invocation must be the value returned on all later invocations as long as the object exists. Notice, however, that the result of hashCode may change between separate executions of a Virtual Machine, because it is not invoked on the same object.

Notice that since hashCode is used in java.util.Hashtable and other hashing classes, a poor implementation will degrade the performance of hashing (so don't blindly implement it as returning a constant!). Also, if calculating the hash is time-consuming, a class may consider caching the results.

The default implementation returns System.identityHashCode(this)


equals

public boolean equals(java.lang.Object o)
Tests for equality based exclusively on the identifier value. This may return true if the objects are not truly functionally equivalent, such as if one object represents a local node and one represents a remote node.


toHtml

public java.lang.String toHtml()
Description copied from interface: ChordNode
Returns an in-depth HTML description of this chord node. The information returned could include the set of keys stored here, etc.

It is anticipated that this method may be costly to invoke. Please do not use it for debugging purposes.

Specified by:
toHtml in interface ChordNode

keys

protected abstract java.util.Collection keys()
Returns a collection of keys that are stored locally at this node. This method is implemented by subclasses for use by algorithms implemented in this object.


moveItem

protected abstract void moveItem(java.lang.Object key,
                                 ChordNode destination)
Moves an item from the local data store to another node as specified. This is an abstract method so subclasses can make choices like retaining the moved item, or ignoring the move request altogether.