Class PersistentMap<K,V>

java.lang.Object
jadex.binary.persistent.collections.PersistentMap<K,V>
All Implemented Interfaces:
Map<K,V>

public class PersistentMap<K,V> extends Object implements Map<K,V>
A map implementation supporting automatic serialization its data and persisting it on disk.
  • Field Details

    • indexmap

      protected Map<K,PersistentMap<K,V>.ValueInfo> indexmap
      The index map, key to position and size of value.
    • file

      protected File file
      The persistence file.
    • mode

      protected String mode
      The file access mode.
    • raf

      protected RandomAccessFile raf
      Random access to the persistence file
    • dirtybytes

      protected long dirtybytes
      Bytes of dirty entries.
    • autocompactionthreshold

      protected long autocompactionthreshold
      Dirty threshold for auto-compaction.
    • classloader

      protected ClassLoader classloader
      Class loader used for serialization.
  • Constructor Details

    • PersistentMap

      public PersistentMap(File file, boolean synchronous, ClassLoader classloader)
      Creates the map.
      Parameters:
      file - File used for persistent data.
  • Method Details

    • main

      public static void main(String[] args)
      Test main method.
      Parameters:
      args - Arguments.
    • size

      public int size()
      Returns the size of the map.
      Specified by:
      size in interface Map<K,V>
    • isEmpty

      public boolean isEmpty()
      Returns whether this map is empty.
      Specified by:
      isEmpty in interface Map<K,V>
    • containsKey

      public boolean containsKey(Object key)
      Returns whether this map contains the specified key.
      Specified by:
      containsKey in interface Map<K,V>
    • containsValue

      public boolean containsValue(Object value)
      Returns whether the map contains the specified value. NOTE: This is very slow, use with caution.
      Specified by:
      containsValue in interface Map<K,V>
    • get

      public V get(Object key)
      Returns the value for a specified key.
      Specified by:
      get in interface Map<K,V>
    • put

      public V put(K key, V value)
      Puts a new value in the map.
      Specified by:
      put in interface Map<K,V>
    • remove

      public V remove(Object key)
      Removes a map entry.
      Specified by:
      remove in interface Map<K,V>
    • putAll

      public void putAll(Map<? extends K,? extends V> m)
      Copies entries from the specified map to this map,
      Specified by:
      putAll in interface Map<K,V>
    • clear

      public void clear()
      Removes all of the entries from this map.
      Specified by:
      clear in interface Map<K,V>
    • keySet

      public Set<K> keySet()
      Returns the keys of the map. Note: Unlike other maps, this is the preferred (fastest mode) for iteration.
      Specified by:
      keySet in interface Map<K,V>
    • values

      public Collection<V> values()
      Returns the values of the map. NOTE: This is very slow, use with caution.
      Specified by:
      values in interface Map<K,V>
    • entrySet

      public Set<Map.Entry<K,V>> entrySet()
      Returns the map's entry set. Warning: SLOW!
      Specified by:
      entrySet in interface Map<K,V>
    • compact

      public void compact()
      Removes stale entries and compacts the map.
    • close

      public void close()
      Closes the persistence file. The map ceases to function after calling this.
    • getDirtyBytes

      public long getDirtyBytes()
      Returns the bytes wasted due to stale entries.
    • setAutoCompactionThreshold

      public void setAutoCompactionThreshold(long threshold)
      Sets the threshold of stale bytes before auto-compaction is executed. Setting the threshold to Long.MAX_VALUE disables auto-compaction.
    • buildIndex

      protected void buildIndex()
      Builds the index.
    • doPut

      protected V doPut(K key, V value)
      Commits a value to the map
    • doRemove

      public V doRemove(Object key)