public class PersistentHashMap<Key,Value> extends PersistentEnumeratorDelegate<Key> implements PersistentMap<Key,Value>
It is important to note that offset
is non-negative and can be 4 or 8 bytes, depending on the size of the ".values" file.
PHM can work in appendable mode: for particular key additional calculated chunk of value can be appended to ".values" file with the offset
of previously calculated chunk.
For performance reasons we try hard to minimize storage occupied by keys / offsets in ".values" file: this storage is allocated as (limited)
direct byte buffers so 4 bytes offset is used until it is possible. Generic record produced by enumerator used with PHM as part of new
key enumeration is
| Modifier and Type | Class and Description |
|---|---|
static interface |
PersistentHashMap.ValueDataAppender |
| Modifier and Type | Field and Description |
|---|---|
protected DataExternalizer<Value> |
myValueExternalizer |
myEnumerator| Constructor and Description |
|---|
PersistentHashMap(java.io.File file,
KeyDescriptor<Key> keyDescriptor,
DataExternalizer<Value> valueExternalizer) |
PersistentHashMap(java.nio.file.Path file,
KeyDescriptor<Key> keyDescriptor,
DataExternalizer<Value> valueExternalizer) |
PersistentHashMap(java.nio.file.Path file,
KeyDescriptor<Key> keyDescriptor,
DataExternalizer<Value> valueExternalizer,
int initialSize) |
PersistentHashMap(java.nio.file.Path file,
KeyDescriptor<Key> keyDescriptor,
DataExternalizer<Value> valueExternalizer,
int initialSize,
int version) |
PersistentHashMap(java.nio.file.Path file,
KeyDescriptor<Key> keyDescriptor,
DataExternalizer<Value> valueExternalizer,
int initialSize,
int version,
PagedFileStorage.StorageLockContext lockContext) |
| Modifier and Type | Method and Description |
|---|---|
void |
appendData(Key key,
PersistentHashMap.ValueDataAppender appender)
Appends value chunk from specified appender to key's value.
|
void |
close() |
void |
compact() |
boolean |
containsMapping(Key key) |
static void |
deleteFilesStartingWith(java.io.File prefixFile) |
static void |
deleteMap(PersistentHashMap<?,?> map)
Deletes files and trying to close it before.
|
protected void |
doDropMemoryCaches() |
protected void |
doForce() |
protected Value |
doGet(Key key) |
protected void |
doPut(Key key,
Value value) |
protected void |
doRemove(Key key) |
void |
dropMemoryCaches() |
int |
enumerate(Key name) |
void |
force() |
Value |
get(Key key) |
java.util.Collection<Key> |
getAllKeysWithExistingMapping() |
java.nio.file.Path |
getBaseFile() |
boolean |
getReadOnly() |
int |
getSize() |
boolean |
isBusyReading() |
protected boolean |
isReadOnly() |
boolean |
makesSenseToCompact() |
boolean |
processKeys(Processor<? super Key> processor)
Process all keys registered in the map.
|
boolean |
processKeysWithExistingMapping(Processor<? super Key> processor) |
void |
put(Key key,
Value value) |
void |
remove(Key key) |
java.lang.String |
toString() |
protected boolean |
wantNonNegativeIntegralValues() |
getAllDataObjects, getVersion, isClosed, isCorrupted, isDirty, markCorrupted, markDirty, traverseAllRecords, tryEnumerate, useBtree, valueOfclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitisClosed, isDirty, markDirtyprotected final DataExternalizer<Value> myValueExternalizer
public PersistentHashMap(java.io.File file,
KeyDescriptor<Key> keyDescriptor,
DataExternalizer<Value> valueExternalizer)
throws java.io.IOException
java.io.IOExceptionpublic PersistentHashMap(java.nio.file.Path file,
KeyDescriptor<Key> keyDescriptor,
DataExternalizer<Value> valueExternalizer)
throws java.io.IOException
java.io.IOExceptionpublic PersistentHashMap(java.nio.file.Path file,
KeyDescriptor<Key> keyDescriptor,
DataExternalizer<Value> valueExternalizer,
int initialSize)
throws java.io.IOException
java.io.IOExceptionpublic PersistentHashMap(java.nio.file.Path file,
KeyDescriptor<Key> keyDescriptor,
DataExternalizer<Value> valueExternalizer,
int initialSize,
int version)
throws java.io.IOException
java.io.IOExceptionpublic PersistentHashMap(java.nio.file.Path file,
KeyDescriptor<Key> keyDescriptor,
DataExternalizer<Value> valueExternalizer,
int initialSize,
int version,
PagedFileStorage.StorageLockContext lockContext)
throws java.io.IOException
java.io.IOExceptionprotected boolean wantNonNegativeIntegralValues()
protected boolean isReadOnly()
public final void dropMemoryCaches()
protected void doDropMemoryCaches()
public int getSize()
public java.nio.file.Path getBaseFile()
public boolean makesSenseToCompact()
public static void deleteFilesStartingWith(java.io.File prefixFile)
public static void deleteMap(PersistentHashMap<?,?> map)
public final void put(Key key, Value value) throws java.io.IOException
put in interface KeyValueStore<Key,Value>java.io.IOExceptionprotected void doPut(Key key, Value value) throws java.io.IOException
java.io.IOExceptionpublic final int enumerate(Key name) throws java.io.IOException
enumerate in interface DataEnumerator<Key>enumerate in class PersistentEnumeratorDelegate<Key>java.io.IOExceptionpublic final void appendData(Key key, PersistentHashMap.ValueDataAppender appender) throws java.io.IOException
get(Object) will
be eventually called for the key, deserializer will read all bytes retrieving Strings and collecting them into Setjava.io.IOExceptionpublic final boolean processKeys(Processor<? super Key> processor) throws java.io.IOException
compact() call will be processed as well. Use
processKeysWithExistingMapping(Processor) to process only keys with existing mappingsprocessKeys in interface PersistentMap<Key,Value>java.io.IOExceptionpublic java.util.Collection<Key> getAllKeysWithExistingMapping() throws java.io.IOException
java.io.IOExceptionpublic final boolean processKeysWithExistingMapping(Processor<? super Key> processor) throws java.io.IOException
java.io.IOExceptionpublic final Value get(Key key) throws java.io.IOException
get in interface KeyValueStore<Key,Value>java.io.IOExceptionpublic boolean isBusyReading()
public final boolean containsMapping(Key key) throws java.io.IOException
java.io.IOExceptionpublic final void remove(Key key) throws java.io.IOException
java.io.IOExceptionprotected void doRemove(Key key) throws java.io.IOException
java.io.IOExceptionpublic final void force()
force in interface Forceableforce in interface KeyValueStore<Key,Value>force in class PersistentEnumeratorDelegate<Key>protected void doForce()
public final void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class PersistentEnumeratorDelegate<Key>java.io.IOExceptionpublic void compact()
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean getReadOnly()