Class PersistentMap<K,V>
java.lang.Object
jadex.binary.persistent.collections.PersistentMap<K,V>
- All Implemented Interfaces:
Map<K,
V>
A map implementation supporting automatic serialization its data
and persisting it on disk.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
Marker for deleted entries.protected class
Information about a stored value. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected long
Dirty threshold for auto-compaction.protected ClassLoader
Class loader used for serialization.protected long
Bytes of dirty entries.protected File
The persistence file.The index map, key to position and size of value.protected String
The file access mode.protected RandomAccessFile
Random access to the persistence file -
Constructor Summary
ConstructorsConstructorDescriptionPersistentMap
(File file, boolean synchronous, ClassLoader classloader) Creates the map. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
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
(Object key) Returns whether this map contains the specified key.boolean
containsValue
(Object value) Returns whether the map contains the specified value.protected V
Commits a value to the mapentrySet()
Returns the map's entry set.Returns the value for a specified key.long
Returns the bytes wasted due to stale entries.boolean
isEmpty()
Returns whether this map is empty.keySet()
Returns the keys of the map.static void
Test main method.Puts a new value in the map.void
Copies entries from the specified map to this map,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.values()
Returns the values of the map.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
indexmap
The index map, key to position and size of value. -
file
The persistence file. -
mode
The file access mode. -
raf
Random access to the persistence file -
dirtybytes
protected long dirtybytesBytes of dirty entries. -
autocompactionthreshold
protected long autocompactionthresholdDirty threshold for auto-compaction. -
classloader
Class loader used for serialization.
-
-
Constructor Details
-
PersistentMap
Creates the map.- Parameters:
file
- File used for persistent data.
-
-
Method Details
-
main
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
Returns whether this map contains the specified key.- Specified by:
containsKey
in interfaceMap<K,
V>
-
containsValue
Returns whether the map contains the specified value. NOTE: This is very slow, use with caution.- Specified by:
containsValue
in interfaceMap<K,
V>
-
get
Returns the value for a specified key. -
put
Puts a new value in the map. -
remove
Removes a map entry. -
putAll
Copies entries from the specified map to this map, -
clear
public void clear()Removes all of the entries from this map. -
keySet
Returns the keys of the map. Note: Unlike other maps, this is the preferred (fastest mode) for iteration. -
values
Returns the values of the map. NOTE: This is very slow, use with caution. -
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. -
doPut
Commits a value to the map -
doRemove
-