Class MyChord

java.lang.Object
  |
  +--MyChord

public class MyChord
extends java.lang.Object

Basic Chord implementation. This is a simple implementation that should permit development to progress. The current implementation is not particularly robust to failure, is quite inefficient, and is not scalable. It utilizes a centralised server that will make the timing relationships easier to work with. If there is demand I will attempt to supply a more scalable version with an identical interface. The class uses two different handlers depending on whether it is the master node that retains the list of all nodes or it is a normal node that queries the master node to get information.


Inner Class Summary
protected  class MyChord.MasterHandler
          Inner class to handle one interaction for the master node.
protected  class MyChord.StandardHandler
          Inner class to handle one interaction for the standard node.
 
Field Summary
protected  MyChange change
           
protected  boolean closing
           
protected  int debug
           
protected  ChordLocation here
           
protected  ChordLocation master
           
protected  java.net.ServerSocket servSock
           
 
Method Summary
protected  void add(ChordLocation node)
          Add adds a node to the list.
protected  void delete(ChordLocation node)
          Deletes a node from the list when it leaves the ring.
 void leave()
          We call this when we want to leave the chord ring.
protected  void log(java.lang.String s)
          Shorthand for a print statement.
protected  int lookKey(byte[] key)
          LookKey looks up a key in the list of locations.
 ChordLocation lookUp(byte[] key)
          This looks up a key in the Chord ring.
protected  void printNodes()
          Used for debugging, this prints an ordered list of nodes.
 void runServer()
          This is the method that kicks off a server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

change

protected MyChange change

here

protected ChordLocation here

master

protected ChordLocation master

servSock

protected java.net.ServerSocket servSock

debug

protected int debug

closing

protected boolean closing
Method Detail

printNodes

protected void printNodes()
Used for debugging, this prints an ordered list of nodes.

lookKey

protected int lookKey(byte[] key)
LookKey looks up a key in the list of locations.

add

protected void add(ChordLocation node)
Add adds a node to the list. It is synchronised to ensure simultaneous adds do not interfere.

delete

protected void delete(ChordLocation node)
Deletes a node from the list when it leaves the ring. Again, this is synchronized to avoid interference between different leaves and joins.

lookUp

public ChordLocation lookUp(byte[] key)
This looks up a key in the Chord ring. It is implemented by sending messages to the server to access the list.

leave

public void leave()
We call this when we want to leave the chord ring. This has the side effect of calling change.left and shutting off the server.

runServer

public void runServer()
This is the method that kicks off a server. When you call it, it loops until closing is set to true, indicating the server is closing down.

log

protected void log(java.lang.String s)
Shorthand for a print statement.