Package edu.jas.util
Class DistHashTable<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- 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
-
-
Field Summary
Fields Modifier and Type Field Description protected ChannelFactory
cf
protected SocketChannel
channel
protected edu.jas.util.DHTListener<K,V>
listener
protected java.util.SortedMap<K,V>
theList
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.void
init()
Initialize and start the list thread.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.
-
-
-
Field Detail
-
cf
protected final ChannelFactory cf
-
channel
protected SocketChannel channel
-
-
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.
-
equals
public boolean equals(java.lang.Object o)
Equals.
-
containsKey
public boolean containsKey(java.lang.Object o)
Contains key.
-
containsValue
public boolean containsValue(java.lang.Object o)
Contains value.
-
getValueList
public java.util.List<V> getValueList()
Get the internal list, convert from Collection.
-
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.
-
isEmpty
public boolean isEmpty()
Is the List empty?
-
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.
-
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.
-
clear
public void clear()
Clear the List. Clearance request is distributed to all clients.
-
init
public void init()
Initialize and start the list thread.
-
terminate
public void terminate()
Terminate the list thread.
-
-