Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.archive.util
Class CachedBdbMap<K,V>

    java.lang.Object
      java.util.AbstractMap<K,V>
          org.archive.util.CachedBdbMap<K,V>

All Implemented Interfaces:
  java.io.Serializable, java.util.Map<K,V>

    public class CachedBdbMap<K,V>

extends java.util.AbstractMap<K,V>
implements java.util.Map<K,V>, java.io.Serializable

A BDB JE backed hashmap. It extends the normal BDB JE map implementation by holding a cache of soft referenced objects. That is objects are not written to disk until they are not referenced by any other object and therefore can be Garbage Collected.

Author:
  John Erik Halse, stack, gojomo
See Also:
  Serialized Form

Nested Class Summary
`protected static class` | `CachedBdbMap.DbEnvironmentEntry` Simple structure to keep needed information about a DB Environment.

Nested classes/interfaces inherited from interface java.util.Map
`java.util.Map.Entry<K,V>`

Field Summary
`protected com.sleepycat.je.Database` | `db` The BDB JE database used for this instance.
`protected com.sleepycat.collections.StoredSortedMap` | `diskMap` The Collection view of the BDB JE database used for this instance.
`protected int` | `diskMapSize` The number of objects in the diskMap StoredMap.
`protected static java.lang.reflect.Field` | `referentField` Reference to the Reference#referent Field.
`protected java.lang.ref.ReferenceQueue<V>` | `refQueue`

Constructor Summary
`CachedBdbMap(java.io.File dbDir, java.lang.String dbName, java.lang.Class<K> keyClass, java.lang.Class<V> valueClass)` A constructor for creating a new CachedBdbMap.
`CachedBdbMap(java.lang.String dbName)` Constructor.

Method Summary
`void` | `clear()` Note that a call to this method CLOSEs the underlying bdbje.
`void` | `close()`
`boolean` | `containsKey(java.lang.Object key)`
`boolean` | `containsValue(java.lang.Object value)`
`protected com.sleepycat.collections.StoredSortedMap` | `createDiskMap(com.sleepycat.je.Database database, com.sleepycat.bind.serial.StoredClassCatalog classCatalog, java.lang.Class keyClass, java.lang.Class valueClass)`
`java.util.Set<java.util.Map.Entry<K,V>>` | `entrySet()`
`protected void` | `finalize()`
`V` | `get(java.lang.Object object)`
`protected java.lang.String` | `getDatabaseName()`
`void` | `initialize(com.sleepycat.je.Environment env, java.lang.Class keyClass, 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.
`protected void` | `initializeInstance()` Do any instance setup.
`java.util.Set<K>` | `keySet()` The keySet of the diskMap is all relevant keys.
`protected com.sleepycat.je.Database` | `openDatabase(com.sleepycat.je.Environment environment, java.lang.String dbName)`
`V` | `put(K key, V value)`
`boolean` | `quickContainsKey(java.lang.Object key)`
`boolean` | `quickContainsValue(java.lang.Object value)`
`V` | `remove(java.lang.Object key)`
`int` | `size()`
`void` | `sync()` Sync in-memory map entries to backing disk store.

Methods inherited from class java.util.AbstractMap
`clone, equals, hashCode, isEmpty, putAll, toString, values`

Methods inherited from class java.lang.Object
`getClass, notify, notifyAll, wait, wait, wait`

Methods inherited from interface java.util.Map
`equals, hashCode, isEmpty, putAll, values`

Field Detail

### db

    protected transient com.sleepycat.je.Database db

  The BDB JE database used for this instance.

### diskMap

    protected transient com.sleepycat.collections.StoredSortedMap diskMap

  The Collection view of the BDB JE database used for this instance.

### refQueue

    protected transient java.lang.ref.ReferenceQueue<V> refQueue

### diskMapSize

    protected int diskMapSize

  The number of objects in the diskMap StoredMap. (Package access for unit testing.)

### referentField

    protected static java.lang.reflect.Field referentField

  Reference to the Reference#referent Field.

Constructor Detail

### CachedBdbMap

    public CachedBdbMap(java.lang.String dbName)

  Constructor. You must call `initialize(Environment, Class, Class, StoredClassCatalog)` to finish construction. Construction is two-stepped to support reconnecting a deserialized CachedBdbMap with its backing bdbje database.

  Parameters:
    `dbName` - Name of the backing db this instance should use.

### CachedBdbMap

    public CachedBdbMap(java.io.File dbDir,
                        java.lang.String dbName,
                        java.lang.Class<K> keyClass,
                        java.lang.Class<V> valueClass)
                 throws com.sleepycat.je.DatabaseException

  A constructor for creating a new CachedBdbMap. Even though the put and get methods conforms to the Collections interface taking any object as key or value, you have to submit the class of the allowed key and value objects here and will get an exception if you try to put anything else in the map.

  This constructor internally calls `initialize(Environment, Class, Class, StoredClassCatalog)`. Do not call initialize if you use this constructor.

  Parameters:
    `dbDir` - The directory where the database will be created.
    `dbName` - The name of the database to back this map by.
    `keyClass` - The class of the objects allowed as keys.
    `valueClass` - The class of the objects allowed as values.
  Throws:
    `com.sleepycat.je.DatabaseException` - is thrown if the underlying BDB JE database throws an exception.

Method Detail

### initialize

    public void initialize(com.sleepycat.je.Environment env,
                           java.lang.Class keyClass,
                           java.lang.Class valueClass,
                           com.sleepycat.bind.serial.StoredClassCatalog classCatalog)
                    throws com.sleepycat.je.DatabaseException

  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. Do not call this method if you used the `CachedBdbMap(File, String, Class, Class)` constructor.

  Parameters:
    `env` -
    `keyClass` -
    `valueClass` -
    `classCatalog` -
  Throws:
    `com.sleepycat.je.DatabaseException`

### initializeInstance

    protected void initializeInstance()

  Do any instance setup. This method is used by constructors and when deserializing an instance.

### createDiskMap

    protected com.sleepycat.collections.StoredSortedMap createDiskMap(com.sleepycat.je.Database database,
                                                                      com.sleepycat.bind.serial.StoredClassCatalog classCatalog,
                                                                      java.lang.Class keyClass,
                                                                      java.lang.Class valueClass)

### openDatabase

    protected com.sleepycat.je.Database openDatabase(com.sleepycat.je.Environment environment,
                                                     java.lang.String dbName)
                                              throws com.sleepycat.je.DatabaseException

  Throws:
    `com.sleepycat.je.DatabaseException`

### close

    public void close()
               throws com.sleepycat.je.DatabaseException

  Throws:
    `com.sleepycat.je.DatabaseException`

### finalize

    protected void finalize()
                     throws java.lang.Throwable

  Overrides:
    `finalize` in class `java.lang.Object`
  Throws:
    `java.lang.Throwable`

### keySet

    public java.util.Set<K> keySet()

  The keySet of the diskMap is all relevant keys.

  Specified by:
    `keySet` in interface `java.util.Map<K,V>`
  Overrides:
    `keySet` in class `java.util.AbstractMap<K,V>`
  See Also:
    `Map.keySet()`

### entrySet

    public java.util.Set<java.util.Map.Entry<K,V>> entrySet()

  Specified by:
    `entrySet` in interface `java.util.Map<K,V>`
  Specified by:
    `entrySet` in class `java.util.AbstractMap<K,V>`

### get

    public V get(java.lang.Object object)

  Specified by:
    `get` in interface `java.util.Map<K,V>`
  Overrides:
    `get` in class `java.util.AbstractMap<K,V>`

### put

    public V put(K key,
                 V value)

  Specified by:
    `put` in interface `java.util.Map<K,V>`
  Overrides:
    `put` in class `java.util.AbstractMap<K,V>`

### clear

    public void clear()

  Note that a call to this method CLOSEs the underlying bdbje. This instance is no longer of any use. It must be re-initialized. We close the db here because if this BigMap is being treated as a plain Map, this is only opportunity for cleanup.

  Specified by:
    `clear` in interface `java.util.Map<K,V>`
  Overrides:
    `clear` in class `java.util.AbstractMap<K,V>`

### remove

    public V remove(java.lang.Object key)

  Specified by:
    `remove` in interface `java.util.Map<K,V>`
  Overrides:
    `remove` in class `java.util.AbstractMap<K,V>`

### containsKey

    public boolean containsKey(java.lang.Object key)

  Specified by:
    `containsKey` in interface `java.util.Map<K,V>`
  Overrides:
    `containsKey` in class `java.util.AbstractMap<K,V>`

### quickContainsKey

    public boolean quickContainsKey(java.lang.Object key)

### containsValue

    public boolean containsValue(java.lang.Object value)

  Specified by:
    `containsValue` in interface `java.util.Map<K,V>`
  Overrides:
    `containsValue` in class `java.util.AbstractMap<K,V>`

### quickContainsValue

    public boolean quickContainsValue(java.lang.Object value)

### size

    public int size()

  Specified by:
    `size` in interface `java.util.Map<K,V>`
  Overrides:
    `size` in class `java.util.AbstractMap<K,V>`

### getDatabaseName

    protected java.lang.String getDatabaseName()

### sync

    public void sync()

  Sync in-memory map entries to backing disk store. When done, the memory map will be cleared and all entries stored on disk.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2008 Internet Archive. All Rights Reserved.