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.Closeable
Implements 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) boolean
closed
(package private) static JSONCodec
codec
(package private) java.io.File
data
(package private) java.io.File
dir
(package private) boolean
inited
(package private) java.io.RandomAccessFile
lockFile
(package private) java.lang.reflect.Type
type
-
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 void
clear()
void
clear(long whenOlder)
void
close()
java.util.Set<java.util.Map.Entry<java.lang.String,V>>
entrySet()
(package private) void
init()
java.util.Set<java.lang.String>
keySet()
private java.nio.channels.FileLock
lock()
V
put(java.lang.String key, V value)
V
remove(java.lang.String key)
java.lang.String
toString()
private void
unlock(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
-
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.IOException
java.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:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.util.AbstractMap<java.lang.String,V>
-
clear
public void clear(long whenOlder)
-
-