Beispiel #1
0
  /**
   * NOTE: this returns an unmodifiable copy of the keySet, so removing from here won't have an
   * effect, and calling a remove while iterating through the set will not cause a concurrent
   * modification exception. This behavior is necessary for now for the persisted cache feature.
   */
  public Set<? extends K> getCacheLineKeys() {
    // note that this must be a HashSet and not a FastSet in order to have a null value
    Set<Object> keys;

    if (fileTable != null) {
      keys = new HashSet<Object>();
      try {
        synchronized (this) {
          addAllFileTableKeys(keys);
        }
      } catch (IOException e) {
        Debug.logError(e, module);
      }
      if (keys.remove(ObjectType.NULL)) {
        keys.add(null);
      }
    } else {
      if (memoryTable.containsKey(ObjectType.NULL)) {
        keys = new HashSet<Object>(memoryTable.keySet());
        keys.remove(ObjectType.NULL);
        keys.add(null);
      } else {
        keys = memoryTable.keySet();
      }
    }
    return Collections.unmodifiableSet(UtilGenerics.<Set<? extends K>>cast(keys));
  }
Beispiel #2
0
 /**
  * Gets an element from the cache according to the specified key.
  *
  * @param key The key for the element, used to reference it in the hastables and LRU linked list
  * @return The value of the element specified by the key
  */
 public V get(Object key) {
   boolean countGet = true;
   Object nulledKey = fromKey(key);
   CacheLine<V> line = memoryTable.get(nulledKey);
   if (line == null) {
     if (fileTable != null) {
       V value;
       try {
         synchronized (this) {
           value = fileTable.get(nulledKey);
         }
       } catch (IOException e) {
         Debug.logError(e, module);
         value = null;
       }
       if (value == null) {
         missCountNotFound.incrementAndGet();
         return null;
       } else {
         hitCount.incrementAndGet();
       }
       memoryTable.put(
           nulledKey, createCacheLine(UtilGenerics.<K>cast(key), value, expireTimeNanos));
       return value;
     } else {
       missCountNotFound.incrementAndGet();
     }
   } else {
     if (countGet) hitCount.incrementAndGet();
   }
   return line != null ? line.getValue() : null;
 }
Beispiel #3
0
 protected synchronized void removeInternal(Object key, CacheLine<V> existingCacheLine) {
   Object nulledKey = fromKey(key);
   cancel(existingCacheLine);
   if (!memoryTable.remove(nulledKey, existingCacheLine)) {
     return;
   }
   if (fileTable != null) {
     try {
       synchronized (this) {
         fileTable.remove(nulledKey);
         jdbmMgr.commit();
       }
     } catch (IOException e) {
       Debug.logError(e, module);
     }
   }
   noteRemoval(UtilGenerics.<K>cast(key), existingCacheLine.getValue());
 }