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/20 09:33:00 UTC

cvs commit: jakarta-turbine-jcs/auxiliary-builds/jdk15/yajcache/cache/src/net/sf/yajcache/core CacheEntry.java CacheManager.java CacheManagerUtils.java ICache.java ICacheSafe.java SafeCacheManager.java

hchar       2005/01/20 00:33:00

  Modified:    auxiliary-builds/jdk15/yajcache/cache/src/net/sf/yajcache/core
                        CacheEntry.java CacheManager.java
                        CacheManagerUtils.java ICache.java ICacheSafe.java
                        SafeCacheManager.java
  Log:
  no message
  
  Revision  Changes    Path
  1.3       +9 -2      jakarta-turbine-jcs/auxiliary-builds/jdk15/yajcache/cache/src/net/sf/yajcache/core/CacheEntry.java
  
  Index: CacheEntry.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/auxiliary-builds/jdk15/yajcache/cache/src/net/sf/yajcache/core/CacheEntry.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CacheEntry.java	19 Jan 2005 11:22:40 -0000	1.2
  +++ CacheEntry.java	20 Jan 2005 08:32:59 -0000	1.3
  @@ -7,6 +7,8 @@
   package net.sf.yajcache.core;
   
   import java.util.Map;
  +import org.apache.commons.lang.builder.HashCodeBuilder;
  +import org.apache.commons.lang.builder.ToStringBuilder;
   
   /**
    *
  @@ -34,5 +36,10 @@
           this.value = val;
           return ret;
       }
  -    
  +    @Override public int hashCode() {
  +        return HashCodeBuilder.reflectionHashCode(this);
  +    }
  +    @Override public String toString() {
  +        return ToStringBuilder.reflectionToString(this);
  +    }
   }
  
  
  
  1.3       +5 -2      jakarta-turbine-jcs/auxiliary-builds/jdk15/yajcache/cache/src/net/sf/yajcache/core/CacheManager.java
  
  Index: CacheManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/auxiliary-builds/jdk15/yajcache/cache/src/net/sf/yajcache/core/CacheManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CacheManager.java	19 Jan 2005 11:22:40 -0000	1.2
  +++ CacheManager.java	20 Jan 2005 08:32:59 -0000	1.3
  @@ -18,7 +18,8 @@
   public enum CacheManager {
       inst;
       // Cache name to Cache mapping.
  -    private final ConcurrentMap<String,ICache<?>> map = new ConcurrentHashMap<String, ICache<?>>();
  +    private final ConcurrentMap<String,ICache<?>> map = 
  +                new ConcurrentHashMap<String, ICache<?>>();
       /** 
        * Returns the cache for the specified name and value type;  
        * Creates the cache if necessary.
  @@ -26,6 +27,7 @@
        * @throws ClassCastException if the cache already exists for an
        * incompatible value type.
        */
  +//    @SuppressWarnings({"unchecked"})
       public <V> ICache<V> getCache(String name, Class<V> valueType)
       {
           ICache c = this.map.get(name);
  @@ -59,6 +61,7 @@
        * @return either the cache created by the current thread, or
        * an existing cache created earlier by another thread.
        */
  +//    @SuppressWarnings({"unchecked"})
       private <V> ICache<V> createCache(String name, Class<V> valueType) {
           ICache<V> c = new SoftRefCache<V>(name, valueType);
           ICache old = this.map.putIfAbsent(name, c);
  
  
  
  1.3       +4 -2      jakarta-turbine-jcs/auxiliary-builds/jdk15/yajcache/cache/src/net/sf/yajcache/core/CacheManagerUtils.java
  
  Index: CacheManagerUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/auxiliary-builds/jdk15/yajcache/cache/src/net/sf/yajcache/core/CacheManagerUtils.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CacheManagerUtils.java	19 Jan 2005 11:22:40 -0000	1.2
  +++ CacheManagerUtils.java	20 Jan 2005 08:32:59 -0000	1.3
  @@ -14,7 +14,9 @@
       inst;
       /** Checks the value type assignability of an existing cache. */
       void checkValueType(ICache c, Class<?> valueType) {
  -        if (!c.getValueType().isAssignableFrom(valueType))
  +        Class<?> cacheValueType = c.getValueType();
  +        
  +        if (!cacheValueType.isAssignableFrom(valueType))
               throw new ClassCastException("Cache " + c.getName()
                   + " of " + c.getValueType() 
                   + " already exists and cannot be used for " + valueType);
  
  
  
  1.3       +11 -1     jakarta-turbine-jcs/auxiliary-builds/jdk15/yajcache/cache/src/net/sf/yajcache/core/ICache.java
  
  Index: ICache.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/auxiliary-builds/jdk15/yajcache/cache/src/net/sf/yajcache/core/ICache.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ICache.java	19 Jan 2005 11:22:40 -0000	1.2
  +++ ICache.java	20 Jan 2005 08:32:59 -0000	1.3
  @@ -8,6 +8,7 @@
   
   import java.util.Map;
   
  +import net.sf.yajcache.annotate.*;
   
   
   /**
  @@ -15,11 +16,20 @@
    *
    * @author Hanson Char
    */
  +@ThreadSafety(ThreadSafetyType.SAFE)
   public interface ICache<V> extends Map<String,V> {
       /** Returns the cache name. */
  +    @ThreadSafety(ThreadSafetyType.IMMUTABLE)
       public String getName();
       /** Returns the value type of the cached items. */
  +    @ThreadSafety(ThreadSafetyType.IMMUTABLE)
       public Class<V> getValueType();
       /** Returns the value cached for the specified key. */
  +    @ThreadSafety(
  +        value=ThreadSafetyType.SAFE,
  +        caveat="This method itself is thread-safe.  However,"
  +             + " the thread-safetyness of the return value cannot be guaranteed"
  +             + " by this interface."
  +    )
       public V get(String key);
   }
  
  
  
  1.2       +59 -1     jakarta-turbine-jcs/auxiliary-builds/jdk15/yajcache/cache/src/net/sf/yajcache/core/ICacheSafe.java
  
  Index: ICacheSafe.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/auxiliary-builds/jdk15/yajcache/cache/src/net/sf/yajcache/core/ICacheSafe.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ICacheSafe.java	19 Jan 2005 10:58:38 -0000	1.1
  +++ ICacheSafe.java	20 Jan 2005 08:32:59 -0000	1.2
  @@ -7,55 +7,113 @@
   package net.sf.yajcache.core;
   
   import java.util.Map;
  +import net.sf.yajcache.annotate.*;
   
   /**
    *
    * @author Hanson Char
    */
  +@ThreadSafety(ThreadSafetyType.SAFE)
   public interface ICacheSafe<V> extends ICache<V> {
       /**
        * If the cache value is Serializable, returns a deep clone copy of
        * the cached value.  Else, the behavior is the same as get.
        */
  +    @ThreadSafety(
  +        value=ThreadSafetyType.SAFE,
  +        note="The return value is guaranteed to be thread-safe"
  +            + " only if the return value type is Serializable."
  +    )
       public V getCopy(String key);
       /**
        * If the cache value is Serializable, puts a deep clone copy of
        * the given value to the cache.  Else, the behavior is the same as put.
        */
  +    @ThreadSafety(
  +        value=ThreadSafetyType.SAFE,
  +        note="The given value is guaranteed to be thread-safe"
  +            + " only if the value type is Serializable."
  +    )
       public V putCopy(String key, V value);
       /**
        * If the cache value is Serializable, puts the deep clone copies of
        * the given values to the cache.  Else, the behavior is the same as putAll.
        */
  +    @ThreadSafety(
  +        value=ThreadSafetyType.SAFE,
  +        caveat="The thread-safetyness of the given map cannot be guaranteed.",
  +        note="The given values in the map is guaranteed to be thread-safe"
  +            + " only if the value type is Serializable."
  +    )
       public void putAllCopies(Map<? extends String, ? extends V> map);
       /**
        * Treats the cache value as a Java Bean and returns a deep clone copy of
        * the cached value.
        */
  +    @ThreadSafety(
  +        value=ThreadSafetyType.SAFE,
  +        note="The return value is guaranteed to be thread-safe"
  +            + " only if the return value is a Java Bean."
  +    )
       public V getBeanCopy(String key);
       /**
        * Treats the cache value as a Java Bean and puts a deep clone copy of
        * the given value to the cache.
        */
  +    @ThreadSafety(
  +        value=ThreadSafetyType.SAFE,
  +        note="The given value is guaranteed to be thread-safe"
  +            + " only if the value is a Java Bean."
  +    )
       public V putBeanCopy(String key, V value);
       /**
        * Treats the cache value as a Java Bean and puts the deep clone copies of
        * the given values to the cache.
        */
  +    @ThreadSafety(
  +        value=ThreadSafetyType.SAFE,
  +        caveat="The thread-safetyness of the given map cannot be guaranteed" 
  +             + " by this interface.",
  +        note="The given values in the map is guaranteed to be thread-safe"
  +           + " only if the values are Java Beans."
  +    )
       public void putAllBeanCopies(Map<? extends String, ? extends V> map);
       /**
        * Treats the cache value as a Java Bean and returns a shallow clone copy of
        * the cached value.
        */
  +    @ThreadSafety(
  +        value=ThreadSafetyType.SAFE,
  +        caveat="The thread-safetyness of the members of the return value cannot"
  +            + " be garanteed by this interface.",
  +        note="The return value is guaranteed to be thread-safe"
  +            + " only if the return value is a JavaBean."
  +    )
       public V getBeanClone(String key);
       /**
        * Treats the cache value as a Java Bean and puts a shallow clone copy of
        * the given value to the cache.
        */
  +    @ThreadSafety(
  +        value=ThreadSafetyType.SAFE,
  +        caveat="The thread-safetyness of the members of the given value cannot"
  +            + " be garanteed by this interface.",
  +        note="The given value is guaranteed to be thread-safe"
  +            + " only if the value is a Java Bean."
  +    )
       public V putBeanClone(String key, V value);
       /**
        * Treats the cache value as a Java Bean and puts the shallow clone copies of
        * the given values to the cache.
        */
  +    @ThreadSafety(
  +        value=ThreadSafetyType.SAFE,
  +        caveat="The thread-safetyness of the given map cannot be guaranteed" 
  +             + " by this interface."
  +             + " Also, the thread-safetyness of the members of each value"
  +             + " in the map cannot be garanteed.",
  +        note="The given values in the map is guaranteed to be thread-safe"
  +           + " only if the values are Java Beans."
  +    )
       public void putAllBeanClones(Map<? extends String, ? extends V> map);
   }
  
  
  
  1.3       +8 -9      jakarta-turbine-jcs/auxiliary-builds/jdk15/yajcache/cache/src/net/sf/yajcache/core/SafeCacheManager.java
  
  Index: SafeCacheManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/auxiliary-builds/jdk15/yajcache/cache/src/net/sf/yajcache/core/SafeCacheManager.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SafeCacheManager.java	19 Jan 2005 11:22:40 -0000	1.2
  +++ SafeCacheManager.java	20 Jan 2005 08:32:59 -0000	1.3
  @@ -8,9 +8,8 @@
   import java.util.concurrent.ConcurrentHashMap;
   import java.util.concurrent.ConcurrentMap;
   
  -
  -
   import net.sf.yajcache.soft.SoftRefCacheSafe;
  +import net.sf.yajcache.annotate.*;
   
   /**
    * @author Hanson Char
  @@ -18,7 +17,8 @@
   public enum SafeCacheManager {
       inst;
       // Cache name to Cache mapping.
  -    private final ConcurrentMap<String,ICacheSafe> map = new ConcurrentHashMap<String, ICacheSafe>();
  +    private final ConcurrentMap<String,ICacheSafe> map = 
  +            new ConcurrentHashMap<String, ICacheSafe>();
       /** 
        * Returns the cache for the specified name and value type;  
        * Creates the cache if necessary.
  @@ -70,11 +70,10 @@
           }
           return c;
       }
  -    /**
  -     * This package private method is used soley to simluate a race condition 
  -     * during cache creation for testing purposes.
  -     */
  -    <V> ICacheSafe<V> testCreateCacheRaceCondition(String name, Class<V> valueType) 
  +
  +    @TestOnly("Used soley to simluate a race condition during cache creation")
  +    <V> ICacheSafe<V> testCreateCacheRaceCondition(
  +            String name, Class<V> valueType)
       {
           return this.createCache(name, valueType);
       }
  
  
  

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