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>

public class DistHashTable<K,V> extends AbstractMap<K,V>
Distributed version of a HashTable. Implemented with a SortedMap / TreeMap to keep the sequence order of elements.
  • Field Details

    • logger

      private static final org.apache.logging.log4j.Logger logger
    • debug

      private static final boolean debug
    • theList

      protected final SortedMap<K,V> theList
    • cf

      protected final ChannelFactory cf
    • channel

      protected SocketChannel channel
    • listener

      protected DHTListener<K,V> listener
  • Constructor Details

    • DistHashTable

      public DistHashTable(String host)
      Constructs a new DistHashTable.
      Parameters:
      host - name or IP of server host.
    • DistHashTable

      public DistHashTable(String host, int port)
      DistHashTable.
      Parameters:
      host - name or IP of server host.
      port - on server.
    • DistHashTable

      public DistHashTable(ChannelFactory cf, 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 Details

    • hashCode

      public int hashCode()
      Hash code.
      Specified by:
      hashCode in interface Map<K,V>
      Overrides:
      hashCode in class AbstractMap<K,V>
    • equals

      public boolean equals(Object o)
      Equals.
      Specified by:
      equals in interface Map<K,V>
      Overrides:
      equals in class AbstractMap<K,V>
    • containsKey

      public boolean containsKey(Object o)
      Contains key.
      Specified by:
      containsKey in interface Map<K,V>
      Overrides:
      containsKey in class AbstractMap<K,V>
    • containsValue

      public boolean containsValue(Object o)
      Contains value.
      Specified by:
      containsValue in interface Map<K,V>
      Overrides:
      containsValue in class AbstractMap<K,V>
    • values

      public Collection<V> values()
      Get the values as Collection.
      Specified by:
      values in interface Map<K,V>
      Overrides:
      values in class AbstractMap<K,V>
    • keySet

      public Set<K> keySet()
      Get the keys as set.
      Specified by:
      keySet in interface Map<K,V>
      Overrides:
      keySet in class AbstractMap<K,V>
    • entrySet

      public Set<Map.Entry<K,V>> entrySet()
      Get the entries as Set.
      Specified by:
      entrySet in interface Map<K,V>
      Specified by:
      entrySet in class AbstractMap<K,V>
    • getValueList

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

      public 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 Map<K,V>
      Overrides:
      size in class AbstractMap<K,V>
    • isEmpty

      public boolean isEmpty()
      Is the List empty?
      Specified by:
      isEmpty in interface Map<K,V>
      Overrides:
      isEmpty in class AbstractMap<K,V>
    • iterator

      public Iterator<K> iterator()
      List key iterator.
    • valueIterator

      public 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 Map<K,V>
      Overrides:
      put in class 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(Object key)
      Get value under key from DHT. If no value is jet available null is returned.
      Specified by:
      get in interface Map<K,V>
      Overrides:
      get in class AbstractMap<K,V>
      Parameters:
      key -
      Returns:
      the value stored under the key.
    • clear

      public void clear()
      Clear the List. Clearance request is distributed to all clients.
      Specified by:
      clear in interface Map<K,V>
      Overrides:
      clear in class AbstractMap<K,V>
    • init

      public void init()
      Initialize and start the list thread.
    • terminate

      public void terminate()
      Terminate the list thread.