Example #1
0
  public synchronized <A> A fetch(long recid, Serializer<A> serializer) throws IOException {
    checkIfClosed();
    if (_softCache)
      synchronized (_softHash) {
        SoftCacheEntry e = _softHash.get(recid);
        if (e != null) {
          Object a = e.get();
          if (a != null) {
            return (A) a;
          }
        }
      }

    CacheEntry entry = (CacheEntry) cacheGet(recid);
    if (entry == null) {
      A value = _recman.fetch(recid, serializer);
      if (!_softCache) cachePut(recid, value, serializer, false);
      else { // put record into soft cache
        synchronized (_softHash) {
          _softHash.put(recid, new SoftCacheEntry(recid, value, _refQueue));
        }
      }
      return value;
    } else {
      return (A) entry._obj;
    }
  }
Example #2
0
 /** Update all dirty cache objects to the underlying RecordManager. */
 protected void updateCacheEntries() throws IOException {
   Iterator<CacheEntry> iter = _hash.valuesIterator();
   while (iter.hasNext()) {
     CacheEntry entry = iter.next();
     if (entry._isDirty) {
       _recman.update(entry._recid, entry._obj, entry._serializer);
       entry._isDirty = false;
     }
   }
 }
Example #3
0
  public synchronized void close() throws IOException {
    checkIfClosed();

    updateCacheEntries();
    _recman.close();
    _recman = null;
    _hash = null;
    _softHash = null;
    if (_softCache) _softRefThread.interrupt();
  }
Example #4
0
  /**
   * Purge least recently used object from the cache
   *
   * @return recyclable CacheEntry
   */
  protected CacheEntry purgeEntry() throws IOException {
    CacheEntry entry = _first;
    if (entry == null) return new CacheEntry(-1, null, null, false);

    if (entry._isDirty) _recman.update(entry._recid, entry._obj, entry._serializer);
    removeEntry(entry);
    _hash.remove(entry._recid);

    entry._obj = null;
    entry._serializer = null;
    entry._isDirty = false;
    return entry;
  }
Example #5
0
  public synchronized <A> long insert(A obj, Serializer<A> serializer) throws IOException {
    checkIfClosed();

    long recid = _recman.insert(obj, serializer);

    // DONT use cache for inserts, it usually hurts performance on batch inserts
    //        if(_softCache) synchronized(_softHash) {
    //        	_softHash.put(recid, new SoftCacheEntry(recid, obj, serializer,_refQueue));
    //        }else {
    //        	cachePut(  recid , obj, serializer, false );
    //        }
    return recid;
  }
Example #6
0
  public synchronized void delete(long recid) throws IOException {
    checkIfClosed();

    _recman.delete(recid);
    CacheEntry entry = _hash.get(recid);
    if (entry != null) {
      removeEntry(entry);
      _hash.remove(entry._recid);
    }
    if (_softCache)
      synchronized (_softHash) {
        SoftCacheEntry e = _softHash.remove(recid);
        if (e != null) {
          e.clear();
        }
      }
  }
Example #7
0
  public synchronized void rollback() throws IOException {
    checkIfClosed();

    _recman.rollback();

    // discard all cache entries since we don't know which entries
    // where part of the transaction
    _hash.clear();
    if (_softCache)
      synchronized (_softHash) {
        Iterator<SoftCacheEntry> iter = _softHash.valuesIterator();
        while (iter.hasNext()) {
          SoftCacheEntry e = iter.next();
          e.clear();
        }
        _softHash.clear();
      }
    _first = null;
    _last = null;
  }
Example #8
0
 public void defrag() throws IOException {
   commit();
   _recman.defrag();
 }
Example #9
0
  public synchronized void setNamedObject(String name, long recid) throws IOException {
    checkIfClosed();

    _recman.setNamedObject(name, recid);
  }
Example #10
0
  public synchronized long getNamedObject(String name) throws IOException {
    checkIfClosed();

    return _recman.getNamedObject(name);
  }
Example #11
0
 public synchronized void commit() throws IOException {
   checkIfClosed();
   updateCacheEntries();
   _recman.commit();
 }
Example #12
0
 public synchronized <A> A fetch(long recid, Serializer<A> serializer, boolean disableCache)
     throws IOException {
   if (disableCache) return _recman.fetch(recid, serializer, disableCache);
   else return fetch(recid, serializer);
 }