Class PersistentMap<K,V>
- java.lang.Object
-
- jadex.binary.persistent.collections.PersistentMap<K,V>
-
- All Implemented Interfaces:
java.util.Map<K,V>
public class PersistentMap<K,V> extends java.lang.Object implements java.util.Map<K,V>A map implementation supporting automatic serialization its data and persisting it on disk.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classPersistentMap.DeletedKeyMarker for deleted entries.protected classPersistentMap.ValueInfoInformation about a stored value.
-
Field Summary
Fields Modifier and Type Field Description protected longautocompactionthresholdDirty threshold for auto-compaction.protected java.lang.ClassLoaderclassloaderClass loader used for serialization.protected longdirtybytesBytes of dirty entries.protected java.io.FilefileThe persistence file.protected java.util.Map<K,PersistentMap.ValueInfo>indexmapThe index map, key to position and size of value.protected java.lang.StringmodeThe file access mode.protected java.io.RandomAccessFilerafRandom access to the persistence file
-
Constructor Summary
Constructors Constructor Description PersistentMap(java.io.File file, boolean synchronous, java.lang.ClassLoader classloader)Creates the map.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbuildIndex()Builds the index.voidclear()Removes all of the entries from this map.voidclose()Closes the persistence file.voidcompact()Removes stale entries and compacts the map.booleancontainsKey(java.lang.Object key)Returns whether this map contains the specified key.booleancontainsValue(java.lang.Object value)Returns whether the map contains the specified value.protected VdoPut(K key, V value)Commits a value to the mapVdoRemove(java.lang.Object key)java.util.Set<java.util.Map.Entry<K,V>>entrySet()Returns the map's entry set.Vget(java.lang.Object key)Returns the value for a specified key.longgetDirtyBytes()Returns the bytes wasted due to stale entries.booleanisEmpty()Returns whether this map is empty.java.util.Set<K>keySet()Returns the keys of the map.static voidmain(java.lang.String[] args)Test main method.Vput(K key, V value)Puts a new value in the map.voidputAll(java.util.Map<? extends K,? extends V> m)Copies entries from the specified map to this map,Vremove(java.lang.Object key)Removes a map entry.voidsetAutoCompactionThreshold(long threshold)Sets the threshold of stale bytes before auto-compaction is executed.intsize()Returns the size of the map.java.util.Collection<V>values()Returns the values of the map.
-
-
-
Field Detail
-
indexmap
protected java.util.Map<K,PersistentMap.ValueInfo> indexmap
The index map, key to position and size of value.
-
file
protected java.io.File file
The persistence file.
-
mode
protected java.lang.String mode
The file access mode.
-
raf
protected java.io.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 java.lang.ClassLoader classloader
Class loader used for serialization.
-
-
Method Detail
-
main
public static void main(java.lang.String[] args)
Test main method.- Parameters:
args- Arguments.
-
size
public int size()
Returns the size of the map.
-
isEmpty
public boolean isEmpty()
Returns whether this map is empty.
-
containsKey
public boolean containsKey(java.lang.Object key)
Returns whether this map contains the specified key.
-
containsValue
public boolean containsValue(java.lang.Object value)
Returns whether the map contains the specified value. NOTE: This is very slow, use with caution.
-
get
public V get(java.lang.Object key)
Returns the value for a specified key.
-
remove
public V remove(java.lang.Object key)
Removes a map entry.
-
putAll
public void putAll(java.util.Map<? extends K,? extends V> m)
Copies entries from the specified map to this map,
-
clear
public void clear()
Removes all of the entries from this map.
-
keySet
public java.util.Set<K> keySet()
Returns the keys of the map. Note: Unlike other maps, this is the preferred (fastest mode) for iteration.
-
values
public java.util.Collection<V> values()
Returns the values of the map. NOTE: This is very slow, use with caution.
-
entrySet
public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
Returns the map's entry set. Warning: SLOW!
-
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.
-
doRemove
public V doRemove(java.lang.Object key)
-
-