You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by hc...@apache.org on 2005/01/27 11:56:14 UTC

cvs commit: jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/core CacheChangeSupport.java CacheEntry.java CacheManager.java SafeCacheManager.java

hchar       2005/01/27 02:56:14

  Modified:    sandbox/yajcache/src/org/apache/jcs/yajcache/core
                        CacheChangeSupport.java CacheEntry.java
                        CacheManager.java SafeCacheManager.java
  Log:
  wip for disk overflow cache
  
  Revision  Changes    Path
  1.2       +22 -7     jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/core/CacheChangeSupport.java
  
  Index: CacheChangeSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/core/CacheChangeSupport.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CacheChangeSupport.java	24 Jan 2005 10:28:55 -0000	1.1
  +++ CacheChangeSupport.java	27 Jan 2005 10:56:14 -0000	1.2
  @@ -19,8 +19,11 @@
   import java.util.List;
   import java.util.concurrent.CopyOnWriteArrayList;
   
  -import org.apache.jcs.yajcache.annotate.*;
  +import org.apache.jcs.yajcache.lang.annotation.*;
   import org.apache.jcs.yajcache.event.CacheChangeEvent;
  +import org.apache.jcs.yajcache.event.CacheClearEvent;
  +import org.apache.jcs.yajcache.event.CachePutEvent;
  +import org.apache.jcs.yajcache.event.CacheRemoveEvent;
   
   /**
    *
  @@ -28,30 +31,42 @@
    */
   @CopyRightApache
   public class CacheChangeSupport<V> {
  -    private final @NonNullable List<CacheChangeListener<V>> listeners 
  -            = new CopyOnWriteArrayList<CacheChangeListener<V>>();
  +    private final @NonNullable List<ICacheChangeListener<V>> listeners 
  +            = new CopyOnWriteArrayList<ICacheChangeListener<V>>();
       
       private ICache<V> cache;
       
       public CacheChangeSupport(@NonNullable ICache<V> cache) {
           this.cache = cache;
       }
  -    public void addCacheChangeListener(@NonNullable CacheChangeListener<V> listener)
  +    public void addCacheChangeListener(@NonNullable ICacheChangeListener<V> listener)
       {
           listeners.add(listener);
       }
  -    public void removeCacheChangeListener(@NonNullable CacheChangeListener<V> listener) 
  +    public void removeCacheChangeListener(@NonNullable ICacheChangeListener<V> listener) 
       {
           listeners.remove(listener);
       }
  -    public @NonNullable Iterable<CacheChangeListener<V>> getCacheChangeListeners() 
  +    public @NonNullable Iterable<ICacheChangeListener<V>> getCacheChangeListeners() 
       {
           return listeners;
       }
       public void fireCacheChange(@NonNullable CacheChangeEvent<V> evt) 
       {
  -        for (CacheChangeListener<V> listener : this.listeners) {
  +        for (ICacheChangeListener<V> listener : this.listeners) {
               listener.cacheChange(evt);
           }
       }
  +    public void fireCachePut(@NonNullable String key, @NonNullable V value) 
  +    {
  +        this.fireCacheChange(new CachePutEvent<V>(this.cache, key, value));
  +    }
  +    public void fireCacheRemove(@NonNullable String key) 
  +    {
  +        this.fireCacheChange(new CacheRemoveEvent<V>(this.cache, key));
  +    }
  +    public void fireCacheClear() 
  +    {
  +        this.fireCacheChange(new CacheClearEvent<V>(this.cache));
  +    }
   }
  
  
  
  1.3       +1 -1      jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/core/CacheEntry.java
  
  Index: CacheEntry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/core/CacheEntry.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CacheEntry.java	24 Jan 2005 10:33:22 -0000	1.2
  +++ CacheEntry.java	27 Jan 2005 10:56:14 -0000	1.3
  @@ -19,7 +19,7 @@
   import java.util.Map;
   import org.apache.commons.lang.builder.HashCodeBuilder;
   import org.apache.commons.lang.builder.ToStringBuilder;
  -import org.apache.jcs.yajcache.annotate.*;
  +import org.apache.jcs.yajcache.lang.annotation.*;
   
   /**
    *
  
  
  
  1.3       +12 -7     jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/core/CacheManager.java
  
  Index: CacheManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/core/CacheManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CacheManager.java	24 Jan 2005 10:33:22 -0000	1.2
  +++ CacheManager.java	27 Jan 2005 10:56:14 -0000	1.3
  @@ -18,14 +18,16 @@
   
   import java.util.concurrent.ConcurrentHashMap;
   import java.util.concurrent.ConcurrentMap;
  -
  -import org.apache.jcs.yajcache.soft.SoftRefCache;
  -import org.apache.jcs.yajcache.annotate.*;
  +import org.apache.jcs.yajcache.lang.annotation.*;
  +import org.apache.jcs.yajcache.config.PerCacheConfig;
  +import org.apache.jcs.yajcache.file.CacheFileManager;
  +import org.apache.jcs.yajcache.soft.SoftRefFileCache;
   
   /**
    * @author Hanson Char
    */
  -@CopyRightApache
  +// @CopyRightApache
  +// http://www.netbeans.org/issues/show_bug.cgi?id=53704
   public enum CacheManager {
       inst;
       // Cache name to Cache mapping.
  @@ -73,14 +75,17 @@
        * an existing cache created earlier by another thread.
        */
   //    @SuppressWarnings({"unchecked"})
  -    private @NonNullable <V> ICache<V> createCache(@NonNullable String name, @NonNullable Class<V> valueType) {
  -        ICache<V> c = new SoftRefCache<V>(name, valueType);
  +    private @NonNullable <V> ICache<V> createCache(
  +            @NonNullable String name, @NonNullable Class<V> valueType) 
  +    {
  +        SoftRefFileCache<V> c = new SoftRefFileCache<V>(name, valueType, new PerCacheConfig());
  +        c.addCacheChangeListener(new CacheFileManager<V>(c));
           ICache old = this.map.putIfAbsent(name, c);
   
           if (old != null) {
               // race condition: cache already created by another thread.
               CacheManagerUtils.inst.checkValueType(old, valueType);
  -            c = old;
  +            return old;
           }
           return c;
       }
  
  
  
  1.3       +12 -7     jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/core/SafeCacheManager.java
  
  Index: SafeCacheManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/core/SafeCacheManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SafeCacheManager.java	24 Jan 2005 10:33:22 -0000	1.2
  +++ SafeCacheManager.java	27 Jan 2005 10:56:14 -0000	1.3
  @@ -18,14 +18,16 @@
   
   import java.util.concurrent.ConcurrentHashMap;
   import java.util.concurrent.ConcurrentMap;
  -
  -import org.apache.jcs.yajcache.soft.SoftRefCacheSafe;
  -import org.apache.jcs.yajcache.annotate.*;
  +import org.apache.jcs.yajcache.lang.annotation.*;
  +import org.apache.jcs.yajcache.config.PerCacheConfig;
  +import org.apache.jcs.yajcache.file.CacheFileManager;
  +import org.apache.jcs.yajcache.soft.SoftRefFileCacheSafe;
   
   /**
    * @author Hanson Char
    */
  -@CopyRightApache
  +// @CopyRightApache
  +// http://www.netbeans.org/issues/show_bug.cgi?id=53704
   public enum SafeCacheManager {
       inst;
       // Cache name to Cache mapping.
  @@ -38,7 +40,8 @@
        * @throws ClassCastException if the cache already exists for an
        * incompatible value type.
        */
  -    public @NonNullable <V> ICacheSafe<V> getCache(@NonNullable String name, @NonNullable Class<V> valueType)
  +    public @NonNullable <V> ICacheSafe<V> getCache(
  +            @NonNullable String name, @NonNullable Class<V> valueType)
       {
           ICacheSafe c = this.map.get(name);
                  
  @@ -74,13 +77,15 @@
       private @NonNullable <V> ICacheSafe<V> createCache(
               @NonNullable String name, @NonNullable Class<V> valueType) 
       {
  -        ICacheSafe c = new SoftRefCacheSafe<V>(name, valueType);
  +        SoftRefFileCacheSafe<V> c = 
  +                new SoftRefFileCacheSafe<V>(name, valueType, new PerCacheConfig());
  +        c.addCacheChangeListener(new CacheFileManager<V>(c));
           ICacheSafe old = this.map.putIfAbsent(name, c);
   
           if (old != null) {
               // race condition: cache already created by another thread.
               CacheManagerUtils.inst.checkValueType(old, valueType);
  -            c = old;
  +            return old;
           }
           return c;
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org