edu.jas.util
Class DistHashTable

java.lang.Object
  extended by edu.jas.util.DistHashTable

public class DistHashTable
extends java.lang.Object

Distributed version of a HashTable. Implemented with a SortedMap / TreeMap to keep the sequence order of elements.

Author:
Heinz Kredel

Field Summary
protected  ChannelFactory cf
           
protected  SocketChannel channel
           
protected  edu.jas.util.DHTListener listener
           
protected  java.util.SortedMap theList
           
 
Constructor Summary
DistHashTable(ChannelFactory cf, java.lang.String host, int port)
          DistHashTable.
DistHashTable(SocketChannel sc)
          DistHashTable.
DistHashTable(java.lang.String host)
          Constructs a new DistHashTable.
DistHashTable(java.lang.String host, int port)
          DistHashTable.
 
Method Summary
 void clear()
          Clear the List.
 java.lang.Object get(java.lang.Object key)
          Get value under key from DHT.
 java.util.ArrayList getArrayList()
          Get the internal list, convert from Collection.
 java.util.SortedMap getList()
          Get the internal sorted map.
 java.lang.Object getWait(java.lang.Object key)
          Get value under key from DHT.
 boolean isEmpty()
          Is the List empty?
 java.util.Iterator iterator()
          List key iterator.
 java.util.Set keySet()
          Get the keys as set.
 void put(java.lang.Object key, java.lang.Object value)
          Put object to the distributed hash table.
 void putWait(java.lang.Object key, java.lang.Object value)
          Put object to the distributed hash table.
 int size()
          Size of the (local) list.
 void terminate()
          Terminate the list thread.
 java.util.Iterator valueIterator()
          List value iterator.
 java.util.Collection values()
          Get the values as Collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theList

protected final java.util.SortedMap theList

cf

protected final ChannelFactory cf

channel

protected SocketChannel channel

listener

protected edu.jas.util.DHTListener listener
Constructor Detail

DistHashTable

public DistHashTable(java.lang.String host)
Constructs a new DistHashTable.

Parameters:
host - name or IP of server host.

DistHashTable

public DistHashTable(java.lang.String host,
                     int port)
DistHashTable.

Parameters:
host - name or IP of server host.
port - on server.

DistHashTable

public DistHashTable(ChannelFactory cf,
                     java.lang.String host,
                     int port)
DistHashTable.

Parameters:
cf - ChannelFactory to use.
host - name or IP of server host.
port - on server.

DistHashTable

public DistHashTable(SocketChannel sc)
DistHashTable.

Parameters:
sc - SocketChannel to use.
Method Detail

values

public java.util.Collection values()
Get the values as Collection.


keySet

public java.util.Set keySet()
Get the keys as set.


getArrayList

public java.util.ArrayList getArrayList()
Get the internal list, convert from Collection.

Fix me
but is ok

getList

public java.util.SortedMap getList()
Get the internal sorted map. For synchronization purpose in normalform.


size

public int size()
Size of the (local) list.


isEmpty

public boolean isEmpty()
Is the List empty?


iterator

public java.util.Iterator iterator()
List key iterator.


valueIterator

public java.util.Iterator valueIterator()
List value iterator.


putWait

public void putWait(java.lang.Object key,
                    java.lang.Object value)
Put object to the distributed hash table. Blocks until the key value pair is send and received from the server.

Parameters:
key -
value -

put

public void put(java.lang.Object key,
                java.lang.Object value)
Put object to the distributed hash table. Returns immediately after sending does not block.

Parameters:
key -
value -

getWait

public java.lang.Object getWait(java.lang.Object key)
Get value under key from DHT. Blocks until the object is send and received from the server (actually it blocks until some value under key is received).

Parameters:
key -
Returns:
the value stored under the key.

get

public java.lang.Object get(java.lang.Object key)
Get value under key from DHT. If no value is jet available null is returned.

Parameters:
key -
Returns:
the value stored under the key.

clear

public void clear()
Clear the List. Caveat: must be called on all clients.


terminate

public void terminate()
Terminate the list thread.