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:
Map<K,
V>
Distributed version of a HashTable. Implemented with a SortedMap / TreeMap to
keep the sequence order of elements.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,
V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ChannelFactory
protected SocketChannel
private static final boolean
protected DHTListener
<K, V> private static final org.apache.logging.log4j.Logger
-
Constructor Summary
ConstructorsConstructorDescriptionDistHashTable
(ChannelFactory cf, String host, int port) DistHashTable.DistHashTable.DistHashTable
(String host) Constructs a new DistHashTable.DistHashTable
(String host, int port) DistHashTable. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear the List.boolean
Contains key.boolean
Contains value.entrySet()
Get the entries as Set.boolean
Equals.Get value under key from DHT.getList()
Get the internal sorted map.Get the internal list, convert from Collection.Get value under key from DHT.int
hashCode()
Hash code.void
init()
Initialize and start the list thread.boolean
isEmpty()
Is the List empty?iterator()
List key iterator.keySet()
Get the keys as set.Put object to the distributed hash table.void
Put object to the distributed hash table.int
size()
Size of the (local) list.void
Terminate the list thread.List value iterator.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
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
logger
private static final org.apache.logging.log4j.Logger logger -
debug
private static final boolean debug -
theList
-
cf
-
channel
-
listener
-
-
Constructor Details
-
DistHashTable
Constructs a new DistHashTable.- Parameters:
host
- name or IP of server host.
-
DistHashTable
DistHashTable.- Parameters:
host
- name or IP of server host.port
- on server.
-
DistHashTable
DistHashTable.- Parameters:
cf
- ChannelFactory to use.host
- name or IP of server host.port
- on server.
-
DistHashTable
DistHashTable.- Parameters:
sc
- SocketChannel to use.
-
-
Method Details
-
hashCode
public int hashCode()Hash code. -
equals
Equals. -
containsKey
Contains key.- Specified by:
containsKey
in interfaceMap<K,
V> - Overrides:
containsKey
in classAbstractMap<K,
V>
-
containsValue
Contains value.- Specified by:
containsValue
in interfaceMap<K,
V> - Overrides:
containsValue
in classAbstractMap<K,
V>
-
values
Get the values as Collection. -
keySet
Get the keys as set. -
entrySet
Get the entries as Set. -
getValueList
Get the internal list, convert from Collection. -
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
List key iterator. -
valueIterator
List value iterator. -
putWait
Put object to the distributed hash table. Blocks until the key value pair is send and received from the server.- Parameters:
key
-value
-
-
put
Put object to the distributed hash table. Returns immediately after sending, does not block. -
getWait
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
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.
-