Package edu.jas.util

Class 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 extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • 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.
      • 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
    • 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.
    • 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<Vvalues()
        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<KkeySet()
        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<VgetValueList()
        Get the internal list, convert from Collection.
      • getList

        public java.util.SortedMap<K,​VgetList()
        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<Kiterator()
        List key iterator.
      • valueIterator

        public java.util.Iterator<VvalueIterator()
        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. Clearance request is distributed to all clients.
        Specified by:
        clear in interface java.util.Map<K,​V>
        Overrides:
        clear in class java.util.AbstractMap<K,​V>
      • init

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

        public void terminate()
        Terminate the list thread.