You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tv...@apache.org on 2011/11/05 20:11:26 UTC

svn commit: r1198019 - in /commons/proper/jcs/trunk/src/java/org/apache/jcs: JCS.java access/CacheAccess.java access/GroupCacheAccess.java

Author: tv
Date: Sat Nov  5 19:11:25 2011
New Revision: 1198019

URL: http://svn.apache.org/viewvc?rev=1198019&view=rev
Log:
Clean up hierarchy

Modified:
    commons/proper/jcs/trunk/src/java/org/apache/jcs/JCS.java
    commons/proper/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java
    commons/proper/jcs/trunk/src/java/org/apache/jcs/access/GroupCacheAccess.java

Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/JCS.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/JCS.java?rev=1198019&r1=1198018&r2=1198019&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/JCS.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/JCS.java Sat Nov  5 19:11:25 2011
@@ -66,9 +66,7 @@ public class JCS
     public static JCS getInstance( String region )
         throws CacheException
     {
-        ensureCacheManager();
-
-        return new JCS( cacheMgr.getCache( region ) );
+        return new JCS( getCacheManager().getCache( region ) );
     }
 
     /**
@@ -82,9 +80,7 @@ public class JCS
     public static JCS getInstance( String region, ICompositeCacheAttributes icca )
         throws CacheException
     {
-        ensureCacheManager();
-
-        return new JCS( cacheMgr.getCache( region, icca ) );
+        return new JCS( getCacheManager().getCache( region, icca ) );
     }
 
     /**
@@ -94,24 +90,29 @@ public class JCS
      *
      * @throws CacheException if the configuration cannot be loaded
      */
-    protected static synchronized void ensureCacheManager() throws CacheException
+    protected static CompositeCacheManager getCacheManager() throws CacheException
     {
-        if ( cacheMgr == null )
+        synchronized ( JCS.class )
         {
-            if ( configProps != null )
-            {
-                cacheMgr = CompositeCacheManager.getUnconfiguredInstance();
-                cacheMgr.configure( configProps );
-            }
-            else if ( configFilename != null )
+            if ( cacheMgr == null )
             {
-                cacheMgr = CompositeCacheManager.getUnconfiguredInstance();
-                cacheMgr.configure( configFilename );
-            }
-            else
-            {
-                cacheMgr = CompositeCacheManager.getInstance();
+                if ( configProps != null )
+                {
+                    cacheMgr = CompositeCacheManager.getUnconfiguredInstance();
+                    cacheMgr.configure( configProps );
+                }
+                else if ( configFilename != null )
+                {
+                    cacheMgr = CompositeCacheManager.getUnconfiguredInstance();
+                    cacheMgr.configure( configFilename );
+                }
+                else
+                {
+                    cacheMgr = CompositeCacheManager.getInstance();
+                }
             }
+
+            return cacheMgr;
         }
     }
 

Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java?rev=1198019&r1=1198018&r2=1198019&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java Sat Nov  5 19:11:25 2011
@@ -93,9 +93,9 @@ public class CacheAccess
     public static CacheAccess defineRegion( String name )
         throws CacheException
     {
-        ensureCacheManager();
+        getCacheManager();
 
-        return new CacheAccess( cacheMgr.getCache( name ) );
+        return new CacheAccess( getCacheManager().getCache( name ) );
     }
 
     /**
@@ -109,9 +109,7 @@ public class CacheAccess
     public static CacheAccess defineRegion( String name, ICompositeCacheAttributes cattr )
         throws CacheException
     {
-        ensureCacheManager();
-
-        return new CacheAccess( cacheMgr.getCache( name, cattr ) );
+        return new CacheAccess( getCacheManager().getCache( name, cattr ) );
     }
 
     /**
@@ -127,9 +125,7 @@ public class CacheAccess
     public static CacheAccess defineRegion( String name, ICompositeCacheAttributes cattr, IElementAttributes attr )
         throws CacheException
     {
-        ensureCacheManager();
-
-        return new CacheAccess( cacheMgr.getCache( name, cattr, attr ) );
+        return new CacheAccess( getCacheManager().getCache( name, cattr, attr ) );
     }
 
     /**
@@ -142,9 +138,7 @@ public class CacheAccess
     public static CacheAccess getAccess( String region )
         throws CacheException
     {
-        ensureCacheManager();
-
-        return new CacheAccess( cacheMgr.getCache( region ) );
+        return new CacheAccess( getCacheManager().getCache( region ) );
     }
 
     /**
@@ -158,9 +152,7 @@ public class CacheAccess
     public static CacheAccess getAccess( String region, ICompositeCacheAttributes icca )
         throws CacheException
     {
-        ensureCacheManager();
-
-        return new CacheAccess( cacheMgr.getCache( region, icca ) );
+        return new CacheAccess( getCacheManager().getCache( region, icca ) );
     }
 
     /**
@@ -169,7 +161,7 @@ public class CacheAccess
      *
      * @throws CacheException if the configuration cannot be loaded
      */
-    protected static void ensureCacheManager() throws CacheException
+    protected static CompositeCacheManager getCacheManager() throws CacheException
     {
         synchronized ( CacheAccess.class )
         {
@@ -177,6 +169,8 @@ public class CacheAccess
             {
                 cacheMgr = CompositeCacheManager.getInstance();
             }
+
+            return cacheMgr;
         }
     }
 

Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/access/GroupCacheAccess.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/access/GroupCacheAccess.java?rev=1198019&r1=1198018&r2=1198019&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/access/GroupCacheAccess.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/access/GroupCacheAccess.java Sat Nov  5 19:11:25 2011
@@ -28,7 +28,6 @@ import org.apache.jcs.engine.behavior.IC
 import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
 import org.apache.jcs.engine.behavior.IElementAttributes;
 import org.apache.jcs.engine.control.CompositeCache;
-import org.apache.jcs.engine.control.CompositeCacheManager;
 import org.apache.jcs.engine.control.group.GroupAttrName;
 import org.apache.jcs.engine.control.group.GroupId;
 
@@ -39,9 +38,6 @@ public class GroupCacheAccess
     extends CacheAccess
     implements IGroupCacheAccess<Serializable, Serializable>
 {
-    /** The underlying cache manager. */
-    private static CompositeCacheManager cacheMgr;
-
     /**
      * Constructor for the GroupCacheAccess object
      * <p>
@@ -62,14 +58,7 @@ public class GroupCacheAccess
     public static GroupCacheAccess getGroupAccess( String region )
         throws CacheException
     {
-        synchronized ( GroupCacheAccess.class )
-        {
-            if ( cacheMgr == null )
-            {
-                cacheMgr = CompositeCacheManager.getInstance();
-            }
-        }
-        return new GroupCacheAccess( cacheMgr.getCache( region ) );
+        return new GroupCacheAccess( getCacheManager().getCache( region ) );
     }
 
     /**
@@ -83,15 +72,7 @@ public class GroupCacheAccess
     public static GroupCacheAccess getGroupAccess( String region, ICompositeCacheAttributes icca )
         throws CacheException
     {
-        synchronized ( GroupCacheAccess.class )
-        {
-            if ( cacheMgr == null )
-            {
-                cacheMgr = CompositeCacheManager.getInstance();
-            }
-        }
-
-        return new GroupCacheAccess( cacheMgr.getCache( region, icca ) );
+        return new GroupCacheAccess( getCacheManager().getCache( region, icca ) );
     }
 
     /**