hchar       2005/01/19 02:58:55

  Added:       auxiliary-builds/jdk15/yajcache/cache/src/net/sf/yajcache/soft
                        KeyedSoftRef.java KeyedSoftRefCollector.java
  Log:
  no message
  
  Revision  Changes    Path
  1.1                  
jakarta-turbine-jcs/auxiliary-builds/jdk15/yajcache/cache/src/net/sf/yajcache/soft/KeyedSoftRef.java
  
  Index: KeyedSoftRef.java
  ===================================================================
  /*
   * SoftValue.java
   *
   * Created on 17 January 2005, 03:45
   */
  
  package net.sf.yajcache.soft;
  
  import java.lang.ref.ReferenceQueue;
  import java.lang.ref.SoftReference;
  
  /**
   * Soft reference with an embedded key.
   *
   * @author Hanson Char
   */
  class KeyedSoftRef<T> extends SoftReference<T> {
      private final String key;
      
  //    KeyedSoftRef(String key, T value) {
  //    super(value);
  //        this.key = key;
  //    }
      KeyedSoftRef(String key, T value, ReferenceQueue<? super T> q) {
          super(value, q);
          this.key = key;
      }
      public String getKey() {
          return this.key;
      }
  }
  
  
  
  1.1                  
jakarta-turbine-jcs/auxiliary-builds/jdk15/yajcache/cache/src/net/sf/yajcache/soft/KeyedSoftRefCollector.java
  
  Index: KeyedSoftRefCollector.java
  ===================================================================
  /*
   * ReferenceQProcessor.java
   *
   * Created on 17 January 2005, 03:54
   */
  
  package net.sf.yajcache.soft;
  
  import java.lang.ref.ReferenceQueue;
  import java.util.Map;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * Collects and clears state cache entries implemented using Soft References.
   *
   * @author Hanson Char
   */
  class KeyedSoftRefCollector<V> implements Runnable {
      private static final boolean debug = true;
      private Log log = debug ? LogFactory.getLog(this.getClass()) : null;
      private volatile int count;
      private final ReferenceQueue<V> q;
      private final Map<String, KeyedSoftRef<V>> map;
      /** Creates a new instance of ReferenceQProcessor */
      KeyedSoftRefCollector(ReferenceQueue<V> q, Map<String, KeyedSoftRef<V>> 
map) {
          this.q = q;
          this.map = map;
      }
      /**
       * Removes stale entries from the cache map collected by GC.
       * Thread safetyness provided by ReferenceQueue.
       */
      public void run() {
  //        if (debug)
  //            log.debug("Run...");
          KeyedSoftRef<V> ksr;
          
          while ((ksr = (KeyedSoftRef<V>)this.q.poll()) != null) {
              String key = ksr.getKey();
              if (debug)
                  log.debug("Remove stale entry with key=" + key);
  //            map.remove(key);
              SoftRefCacheCleaner.inst.cleanupKey(map, key);
              ksr.clear();
              count++;
          }        
      }
      public int getCount() {
          return count;
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to