edu.jas.util
Class DistHashTable<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by edu.jas.util.DistHashTable<K,V>
All Implemented Interfaces:
java.util.Map<K,V>

public class DistHashTable<K,V>
extends java.util.AbstractMap<K,V>

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

Author:
Heinz Kredel

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
protected  ChannelFactory cf
           
protected  SocketChannel channel
           
protected  edu.jas.util.DHTListener<K,V> listener
           
protected  java.util.SortedMap<K,V> 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.
 boolean containsKey(java.lang.Object o)
          Contains key.
 boolean containsValue(java.lang.Object o)
          Contains value.
 java.util.Set<java.util.Map.Entry<K,V>> entrySet()
          Get the entries as Set.
 boolean equals(java.lang.Object o)
          Equals.
 V get(java.lang.Object key)
          Get value under key from DHT.
 java.util.SortedMap<K,V> getList()
          Get the internal sorted map.
 java.util.List<V> getValueList()
          Get the internal list, convert from Collection.
 V getWait(K key)
          Get value under key from DHT.
 int hashCode()
          Hash code.
 boolean isEmpty()
          Is the List empty?
 java.util.Iterator<K> iterator()
          List key iterator.
 java.util.Set<K> keySet()
          Get the keys as set.
 V put(K key, V value)
          Put object to the distributed hash table.
 void putWait(K key, V value)
          Put object to the distributed hash table.
 int size()
          Size of the (local) list.
 void terminate()
          Terminate the list thread.
 java.util.Iterator<V> valueIterator()
          List value iterator.
 java.util.Collection<V> values()
          Get the values as Collection.
 
Methods inherited from class java.util.AbstractMap
clone, putAll, remove, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

theList

protected final java.util.SortedMap<K,V> theList

cf

protected final ChannelFactory cf

channel

protected SocketChannel channel

listener

protected edu.jas.util.DHTListener<K,V> 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

hashCode

public int hashCode()
Hash code.

Specified by:
hashCode in interface java.util.Map<K,V>
Overrides:
hashCode in class java.util.AbstractMap<K,V>

equals

public boolean equals(java.lang.Object o)
Equals.

Specified by:
equals in interface java.util.Map<K,V>
Overrides:
equals in class java.util.AbstractMap<K,V>

containsKey

public boolean containsKey(java.lang.Object o)
Contains key.

Specified by:
containsKey in interface java.util.Map<K,V>
Overrides:
containsKey in class java.util.AbstractMap<K,V>

containsValue

public boolean containsValue(java.lang.Object o)
Contains value.

Specified by:
containsValue in interface java.util.Map<K,V>
Overrides:
containsValue in class java.util.AbstractMap<K,V>

values

public java.util.Collection<V> values()
Get the values as Collection.

Specified by:
values in interface java.util.Map<K,V>
Overrides:
values in class java.util.AbstractMap<K,V>

keySet

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

Specified by:
keySet in interface java.util.Map<K,V>
Overrides:
keySet in class java.util.AbstractMap<K,V>

entrySet

public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
Get the entries as Set.

Specified by:
entrySet in interface java.util.Map<K,V>
Specified by:
entrySet in class java.util.AbstractMap<K,V>

getValueList

public java.util.List<V> getValueList()
Get the internal list, convert from Collection.

Fix me
but is ok

getList

public java.util.SortedMap<K,V> getList()
Get the internal sorted map. For synchronization purpose in normalform.


size

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

Specified by:
size in interface java.util.Map<K,V>
Overrides:
size in class java.util.AbstractMap<K,V>

isEmpty

public boolean isEmpty()
Is the List empty?

Specified by:
isEmpty in interface java.util.Map<K,V>
Overrides:
isEmpty in class java.util.AbstractMap<K,V>

iterator

public java.util.Iterator<K> iterator()
List key iterator.


valueIterator

public java.util.Iterator<V> valueIterator()
List value iterator.


putWait

public void putWait(K key,
                    V 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 V put(K key,
             V value)
Put object to the distributed hash table. Returns immediately after sending does not block.

Specified by:
put in interface java.util.Map<K,V>
Overrides:
put in class java.util.AbstractMap<K,V>
Parameters:
key -
value -

getWait

public V getWait(K 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 V get(java.lang.Object key)
Get value under key from DHT. If no value is jet available null is returned.

Specified by:
get in interface java.util.Map<K,V>
Overrides:
get in class java.util.AbstractMap<K,V>
Parameters:
key -
Returns:
the value stored under the key.

clear

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

Specified by:
clear in interface java.util.Map<K,V>
Overrides:
clear in class java.util.AbstractMap<K,V>

terminate

public void terminate()
Terminate the list thread.