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 class
PersistentMap.DeletedKey
Marker for deleted entries.protected class
PersistentMap.ValueInfo
Information about a stored value.
-
Field Summary
Fields Modifier and Type Field Description protected long
autocompactionthreshold
Dirty threshold for auto-compaction.protected java.lang.ClassLoader
classloader
Class loader used for serialization.protected long
dirtybytes
Bytes of dirty entries.protected java.io.File
file
The persistence file.protected java.util.Map<K,PersistentMap.ValueInfo>
indexmap
The index map, key to position and size of value.protected java.lang.String
mode
The file access mode.protected java.io.RandomAccessFile
raf
Random 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 void
buildIndex()
Builds the index.void
clear()
Removes all of the entries from this map.void
close()
Closes the persistence file.void
compact()
Removes stale entries and compacts the map.boolean
containsKey(java.lang.Object key)
Returns whether this map contains the specified key.boolean
containsValue(java.lang.Object value)
Returns whether the map contains the specified value.protected V
doPut(K key, V value)
Commits a value to the mapV
doRemove(java.lang.Object key)
java.util.Set<java.util.Map.Entry<K,V>>
entrySet()
Returns the map's entry set.V
get(java.lang.Object key)
Returns the value for a specified key.long
getDirtyBytes()
Returns the bytes wasted due to stale entries.boolean
isEmpty()
Returns whether this map is empty.java.util.Set<K>
keySet()
Returns the keys of the map.static void
main(java.lang.String[] args)
Test main method.V
put(K key, V value)
Puts a new value in the map.void
putAll(java.util.Map<? extends K,? extends V> m)
Copies entries from the specified map to this map,V
remove(java.lang.Object key)
Removes a map entry.void
setAutoCompactionThreshold(long threshold)
Sets the threshold of stale bytes before auto-compaction is executed.int
size()
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)
-
-