Package aQute.lib.persistentmap
Class PersistentMap<V>
- java.lang.Object
-
- java.util.AbstractMap<java.lang.String,V>
-
- aQute.lib.persistentmap.PersistentMap<V>
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.util.Map<java.lang.String,V>
public class PersistentMap<V> extends java.util.AbstractMap<java.lang.String,V> implements java.io.CloseableImplements a low performance but easy to use map that is backed on a directory. All objects are stored as JSON objects and therefore should be DTOs. Each key is a file name and the contents is the value encoded in JSON. The PersistentMap will attempt to lock the directory. This is a non-concurrent implementation so you must ensure it is only used in a single thread. It cannot of course also not share the data directory.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.Map<java.lang.String,java.lang.ref.SoftReference<V>>cache(package private) booleanclosed(package private) static JSONCodeccodec(package private) java.io.Filedata(package private) java.io.Filedirprivate static charESCAPE(package private) booleaninited(package private) java.io.RandomAccessFilelockFile(package private) java.lang.reflect.Typetype
-
Constructor Summary
Constructors Constructor Description PersistentMap(java.io.File dir, java.lang.Class<V> type)PersistentMap(java.io.File dir, java.lang.Class<V> type, java.util.Map<java.lang.String,V> map)PersistentMap(java.io.File dir, java.lang.reflect.Type type)PersistentMap(java.io.File dir, java.lang.reflect.Type type, java.util.Map<java.lang.String,V> map)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()voidclear(long whenOlder)voidclose()java.util.Set<java.util.Map.Entry<java.lang.String,V>>entrySet()(package private) voidinit()java.util.Set<java.lang.String>keySet()private java.io.FilekeyToFile(java.lang.String key)private java.nio.channels.FileLocklock()Vput(java.lang.String key, V value)Vremove(java.lang.String key)java.lang.StringtoString()private voidunlock(java.nio.channels.FileLock lock)-
Methods inherited from class java.util.AbstractMap
clone, containsKey, containsValue, equals, get, hashCode, isEmpty, putAll, remove, size, values
-
-
-
-
Field Detail
-
ESCAPE
private static final char ESCAPE
- See Also:
- Constant Field Values
-
codec
static final JSONCodec codec
-
dir
final java.io.File dir
-
data
final java.io.File data
-
lockFile
final java.io.RandomAccessFile lockFile
-
cache
final java.util.Map<java.lang.String,java.lang.ref.SoftReference<V>> cache
-
inited
boolean inited
-
closed
boolean closed
-
type
java.lang.reflect.Type type
-
-
Constructor Detail
-
PersistentMap
public PersistentMap(java.io.File dir, java.lang.reflect.Type type) throws java.lang.Exception- Throws:
java.lang.Exception
-
PersistentMap
public PersistentMap(java.io.File dir, java.lang.Class<V> type) throws java.lang.Exception- Throws:
java.lang.Exception
-
PersistentMap
public PersistentMap(java.io.File dir, java.lang.Class<V> type, java.util.Map<java.lang.String,V> map) throws java.lang.Exception- Throws:
java.lang.Exception
-
PersistentMap
public PersistentMap(java.io.File dir, java.lang.reflect.Type type, java.util.Map<java.lang.String,V> map) throws java.lang.Exception- Throws:
java.lang.Exception
-
-
Method Detail
-
init
void init()
-
entrySet
public java.util.Set<java.util.Map.Entry<java.lang.String,V>> entrySet()
-
lock
private java.nio.channels.FileLock lock() throws java.io.IOException, java.lang.InterruptedException- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
unlock
private void unlock(java.nio.channels.FileLock lock) throws java.io.IOException- Throws:
java.io.IOException
-
remove
public V remove(java.lang.String key)
-
clear
public void clear()
-
keySet
public java.util.Set<java.lang.String> keySet()
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.util.AbstractMap<java.lang.String,V>
-
clear
public void clear(long whenOlder)
-
keyToFile
private java.io.File keyToFile(java.lang.String key)
-
-