public class ShadowedPersistentMap<K,V>
extends java.lang.Object
implements java.util.Map<K,V>
Modifier and Type | Class and Description |
---|---|
protected class |
ShadowedPersistentMap.DeletedKey
Marker for deleted entries.
|
protected class |
ShadowedPersistentMap.ValueInfo
Information about a stored value.
|
Modifier and Type | Field and Description |
---|---|
protected long |
autocompactionthreshold
Dirty threshold for auto-compaction.
|
protected java.lang.ClassLoader |
classloader
Class loader used for serialization.
|
protected ShadowedPersistentMap<java.lang.Object,java.lang.Object> |
compactionshadowmap
Shadow map used during compaction.
|
protected long |
dirtybytes
Bytes of dirty entries.
|
protected java.io.File |
file
The persistence file.
|
protected java.util.Map<K,ShadowedPersistentMap.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
|
protected int |
shadowcounter
Object counter for shadow map.
|
protected java.lang.Object |
shadowlock
Lock for the compaction shadow map.
|
Constructor and Description |
---|
ShadowedPersistentMap(java.io.File file,
boolean synchronous,
java.lang.ClassLoader classloader)
Creates the map.
|
Modifier and Type | Method and 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 map
|
V |
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.
|
void |
waitForCompaction()
Waits for a background compaction to finish (if running).
|
protected java.util.Map<K,ShadowedPersistentMap.ValueInfo> indexmap
protected java.io.File file
protected java.lang.String mode
protected java.io.RandomAccessFile raf
protected long dirtybytes
protected long autocompactionthreshold
protected java.lang.ClassLoader classloader
protected java.lang.Object shadowlock
protected int shadowcounter
protected volatile ShadowedPersistentMap<java.lang.Object,java.lang.Object> compactionshadowmap
public ShadowedPersistentMap(java.io.File file, boolean synchronous, java.lang.ClassLoader classloader)
file
- File used for persistent data.public static void main(java.lang.String[] args)
args
- Arguments.public int size()
public boolean isEmpty()
public boolean containsKey(java.lang.Object key)
public boolean containsValue(java.lang.Object value)
public V get(java.lang.Object key)
public V remove(java.lang.Object key)
public void putAll(java.util.Map<? extends K,? extends V> m)
public void clear()
public java.util.Set<K> keySet()
public java.util.Collection<V> values()
public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
public void compact()
public void waitForCompaction()
public void close()
public long getDirtyBytes()
public void setAutoCompactionThreshold(long threshold)
protected void buildIndex()
public V doRemove(java.lang.Object key)