|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.archive.util.ObjectIdentityBdbCache<V>
public class ObjectIdentityBdbCache<V>
A BDB JE backed object cache. Soft references to previously-instantiated objects are held so that unless/until an object is garbage collected, subsequent get()s will return the exact same object. (If all outside references are lost, when the soft reference is broken, the object state -- still accessible to this class via reflective access to a phantom referent --is flushed to disk. The next get() will reconsitute a new object, from the disk state.)
The backing disk is only guaranteed to be up-to-date after a flush of all in-memory values to disk, as can be forced by sync(). To ensure that changes/mutations to values in this map are coherent and consistent at the application level, it is assumed that the application level only mutates values that are in this map and does not retain references to values longer than necessary. This allows mappings to be persisted during GC without explicit transactions or write operations. Based on the earlier CachedBdbMap.
Nested Class Summary | |
---|---|
protected class |
ObjectIdentityBdbCache.LowMemoryCanary
|
Field Summary | |
---|---|
protected java.lang.ref.SoftReference<ObjectIdentityBdbCache.LowMemoryCanary> |
canary
|
protected java.util.concurrent.atomic.AtomicLong |
count
|
protected com.sleepycat.je.Database |
db
The BDB JE database used for this instance. |
protected com.sleepycat.collections.StoredSortedMap<java.lang.String,V> |
diskMap
The Collection view of the BDB JE database used for this instance. |
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,org.archive.util.ObjectIdentityBdbCache.SoftEntry<V>> |
memMap
in-memory map of new/recent/still-referenced-elsewhere instances |
protected static java.lang.reflect.Field |
referentField
Reference to the Reference#referent Field. |
protected java.lang.ref.ReferenceQueue<V> |
refQueue
|
Constructor Summary | |
---|---|
ObjectIdentityBdbCache()
Constructor. |
Method Summary | |
---|---|
void |
close()
close/release any associated resources |
protected com.sleepycat.collections.StoredSortedMap<java.lang.String,V> |
createDiskMap(com.sleepycat.je.Database database,
com.sleepycat.bind.serial.StoredClassCatalog classCatalog,
java.lang.Class valueClass)
|
protected void |
finalize()
|
V |
get(java.lang.String key)
get the object under the given key/name |
protected java.lang.String |
getDatabaseName()
|
V |
getOrUse(java.lang.String key,
Supplier<V> supplierOrNull)
get the object under the given key/name, using (and remembering) the object supplied by the supplier if no prior mapping exists |
void |
initialize(com.sleepycat.je.Environment env,
java.lang.String dbName,
java.lang.Class valueClass,
com.sleepycat.bind.serial.StoredClassCatalog classCatalog)
Call this method when you have an instance when you used the default constructor or when you have a deserialized instance that you want to reconnect with an extant bdbje environment. |
java.util.Set<java.lang.String> |
keySet()
set of all keys |
protected com.sleepycat.je.Database |
openDatabase(com.sleepycat.je.Environment environment,
java.lang.String dbName)
|
(package private) void |
pageOutStaleEntries()
An incremental, poll-based expunger. |
int |
size()
count of name-to-object contained |
void |
sync()
Sync all in-memory map entries to backing disk store. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected transient com.sleepycat.je.Database db
protected transient java.util.concurrent.ConcurrentHashMap<java.lang.String,org.archive.util.ObjectIdentityBdbCache.SoftEntry<V>> memMap
protected transient java.lang.ref.ReferenceQueue<V> refQueue
protected transient com.sleepycat.collections.StoredSortedMap<java.lang.String,V> diskMap
protected java.util.concurrent.atomic.AtomicLong count
protected static java.lang.reflect.Field referentField
protected transient java.lang.ref.SoftReference<ObjectIdentityBdbCache.LowMemoryCanary> canary
Constructor Detail |
---|
public ObjectIdentityBdbCache()
#initialize(Environment, Class, Class, StoredClassCatalog)
to finish construction. Construction is two-stepped to support
reconnecting a deserialized CachedBdbMap with its backing bdbje
database.
dbName
- Name of the backing db this instance should use.Method Detail |
---|
public void initialize(com.sleepycat.je.Environment env, java.lang.String dbName, java.lang.Class valueClass, com.sleepycat.bind.serial.StoredClassCatalog classCatalog) throws com.sleepycat.je.DatabaseException
#CachedBdbMap(File, String, Class, Class)
constructor.
env
- keyClass
- valueClass
- classCatalog
-
com.sleepycat.je.DatabaseException
protected com.sleepycat.collections.StoredSortedMap<java.lang.String,V> createDiskMap(com.sleepycat.je.Database database, com.sleepycat.bind.serial.StoredClassCatalog classCatalog, java.lang.Class valueClass)
protected com.sleepycat.je.Database openDatabase(com.sleepycat.je.Environment environment, java.lang.String dbName) throws com.sleepycat.je.DatabaseException
com.sleepycat.je.DatabaseException
public void close()
ObjectIdentityCache
close
in interface java.io.Closeable
close
in interface ObjectIdentityCache<java.lang.String,V>
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public V get(java.lang.String key)
ObjectIdentityCache
get
in interface ObjectIdentityCache<java.lang.String,V>
public V getOrUse(java.lang.String key, Supplier<V> supplierOrNull)
ObjectIdentityCache
getOrUse
in interface ObjectIdentityCache<java.lang.String,V>
public java.util.Set<java.lang.String> keySet()
ObjectIdentityCache
keySet
in interface ObjectIdentityCache<java.lang.String,V>
public int size()
ObjectIdentityCache
size
in interface ObjectIdentityCache<java.lang.String,V>
protected java.lang.String getDatabaseName()
public void sync()
sync
in interface ObjectIdentityCache<java.lang.String,V>
void pageOutStaleEntries()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |