/**
  * An incremental, poll-based expunger.
  *
  * <p>Package-protected for unit-test visibility.
  */
 @SuppressWarnings("unchecked")
 synchronized void pageOutStaleEntries() {
   int c = 0;
   long startTime = System.currentTimeMillis();
   for (SoftEntry<V> entry; (entry = (SoftEntry<V>) refQueue.poll()) != null; ) {
     pageOutStaleEntry(entry);
     c++;
   }
   if (c > 0 && logger.isLoggable(Level.FINER)) {
     long endTime = System.currentTimeMillis();
     try {
       logger.finer(
           "DB: "
               + db.getDatabaseName()
               + ",  Expunged: "
               + c
               + ", Diskmap size: "
               + diskMap.size()
               + ", Cache size: "
               + memMap.size()
               + ", in "
               + (endTime - startTime)
               + "ms");
     } catch (DatabaseException e) {
       logger.log(Level.FINER, "exception while logging", e);
     }
   }
 }
  /**
   * 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 {@link #CachedBdbMap(File, String, Class, Class)}
   * constructor.
   *
   * @param env
   * @param keyClass
   * @param valueClass
   * @param classCatalog
   * @throws DatabaseException
   */
  @SuppressWarnings("unchecked")
  public void initialize(
      final Environment env,
      String dbName,
      final Class valueClass,
      final StoredClassCatalog classCatalog)
      throws DatabaseException {
    // TODO: initial capacity should be related to number of seeds, max depth, max docs
    this.memMap =
        new ConcurrentHashMap<String, SoftEntry<V>>(
            8192, // initial capacity
            0.9f, // acceptable load factor
            64 // est. number of concurrent threads
            );
    this.refQueue = new ReferenceQueue<V>();
    canary = new SoftReference<LowMemoryCanary>(new LowMemoryCanary());

    this.db = openDatabase(env, dbName);
    this.diskMap = createDiskMap(this.db, classCatalog, valueClass);
    this.count = new AtomicLong(diskMap.size());
  }