commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1721147 - in /commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file: FileDiskCache.java FileDiskCacheAttributes.java FileDiskCacheFactory.java FileDiskCacheManager.java
Date Mon, 21 Dec 2015 13:19:11 GMT
Author: tv
Date: Mon Dec 21 13:19:11 2015
New Revision: 1721147

URL: http://svn.apache.org/viewvc?rev=1721147&view=rev
Log:
Make code compile again

Modified:
    commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCache.java
    commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheAttributes.java
    commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheFactory.java
    commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheManager.java

Modified: commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCache.java?rev=1721147&r1=1721146&r2=1721147&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCache.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCache.java
Mon Dec 21 13:19:11 2015
@@ -19,16 +19,6 @@ package org.apache.commons.jcs.auxiliary
  * under the License.
  */
 
-import org.apache.commons.jcs.auxiliary.AuxiliaryCacheAttributes;
-import org.apache.commons.jcs.auxiliary.disk.AbstractDiskCache;
-import org.apache.commons.jcs.engine.behavior.ICacheElement;
-import org.apache.commons.jcs.engine.behavior.IElementSerializer;
-import org.apache.commons.jcs.engine.logging.behavior.ICacheEvent;
-import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
-import org.apache.commons.jcs.utils.timing.SleepUtil;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -36,10 +26,19 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.Serializable;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.commons.jcs.auxiliary.AuxiliaryCacheAttributes;
+import org.apache.commons.jcs.auxiliary.disk.AbstractDiskCache;
+import org.apache.commons.jcs.engine.behavior.ICacheElement;
+import org.apache.commons.jcs.engine.behavior.IElementSerializer;
+import org.apache.commons.jcs.engine.logging.behavior.ICacheEvent;
+import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
+import org.apache.commons.jcs.utils.timing.SleepUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 /**
  * This disk cache writes each item to a separate file. This is for regions with very few
items,
  * perhaps big ones.
@@ -47,12 +46,9 @@ import java.util.Set;
  * This is a fairly simple implementation. All the disk writing is handled right here. It's
not
  * clear that anything more complicated is needed.
  */
-public class FileDiskCache<K extends Serializable, V extends Serializable>
+public class FileDiskCache<K, V>
     extends AbstractDiskCache<K, V>
 {
-    /** Don't change */
-    private static final long serialVersionUID = 1L;
-
     /** The logger. */
     private static final Log log = LogFactory.getLog( FileDiskCache.class );
 
@@ -88,7 +84,7 @@ public class FileDiskCache<K extends Ser
         setElementSerializer( elementSerializer );
         this.diskFileCacheAttributes = cattr;
         this.logCacheName = "Region [" + getCacheName() + "] ";
-        alive = initializeFileSystem( cattr );
+        setAlive(initializeFileSystem( cattr ));
     }
 
     /**
@@ -126,7 +122,7 @@ public class FileDiskCache<K extends Ser
      * @param key
      * @return the file for the key
      */
-    protected <KK extends Serializable> File file( KK key )
+    protected <KK> File file( KK key )
     {
         StringBuilder fileNameBuffer = new StringBuilder();
 
@@ -203,17 +199,17 @@ public class FileDiskCache<K extends Ser
     protected synchronized void processDispose()
         throws IOException
     {
-        ICacheEvent<String> cacheEvent = createICacheEvent( cacheName, "none", ICacheEventLogger.DISPOSE_EVENT
);
+        ICacheEvent<String> cacheEvent = createICacheEvent( getCacheName(), "none",
ICacheEventLogger.DISPOSE_EVENT );
         try
         {
-            if ( !alive )
+            if ( !isAlive() )
             {
                 log.error( logCacheName + "Not alive and dispose was called, directgory:
" + getDirectory() );
                 return;
             }
 
             // Prevents any interaction with the cache while we're shutting down.
-            alive = false;
+            setAlive(false);
 
             // TODO consider giving up the handle on the directory.
             if ( log.isInfoEnabled() )
@@ -273,7 +269,7 @@ public class FileDiskCache<K extends Ser
                 throw new IOException( "Could not completely read file " + file.getName()
);
             }
 
-            element = getElementSerializer().deSerialize( bytes );
+            element = getElementSerializer().deSerialize( bytes, null );
 
             // test that the retrieved object has equal key
             if ( element != null && !key.equals( element.getKey() ) )
@@ -342,7 +338,7 @@ public class FileDiskCache<K extends Ser
      * @return true if the item was removed
      * @throws IOException
      */
-    private <T extends Serializable> boolean _processRemove( T key )
+    private <T> boolean _processRemove( T key )
         throws IOException
     {
         File file = file( key );

Modified: commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheAttributes.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheAttributes.java?rev=1721147&r1=1721146&r2=1721147&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheAttributes.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheAttributes.java
Mon Dec 21 13:19:11 2015
@@ -19,7 +19,6 @@ package org.apache.commons.jcs.auxiliary
  * under the License.
  */
 
-import org.apache.commons.jcs.auxiliary.AuxiliaryCacheAttributes;
 import org.apache.commons.jcs.auxiliary.disk.AbstractDiskCacheAttributes;
 
 /**
@@ -60,25 +59,6 @@ public class FileDiskCacheAttributes
     private boolean touchOnGet = DEFAULT_TOUCH_ON_GET;
 
     /**
-     * Returns a copy of the attributes.
-     * <p>
-     * @return AuxiliaryCacheAttributes
-     */
-    @Override
-    public AuxiliaryCacheAttributes copy()
-    {
-        try
-        {
-            return (AuxiliaryCacheAttributes) this.clone();
-        }
-        catch ( Exception e )
-        {
-            // swallow
-        }
-        return this;
-    }
-
-    /**
      * @param maxNumberOfFiles the maxNumberOfFiles to set
      */
     public void setMaxNumberOfFiles( int maxNumberOfFiles )

Modified: commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheFactory.java?rev=1721147&r1=1721146&r2=1721147&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheFactory.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheFactory.java
Mon Dec 21 13:19:11 2015
@@ -27,8 +27,6 @@ import org.apache.commons.jcs.engine.log
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.io.Serializable;
-
 /** Create Disk File Caches */
 public class FileDiskCacheFactory
     implements AuxiliaryCacheFactory
@@ -54,7 +52,7 @@ public class FileDiskCacheFactory
      * @return AuxiliaryCache
      */
     @Override
-    public <K extends Serializable, V extends Serializable> FileDiskCache<K, V>
createCache(
+    public <K, V> FileDiskCache<K, V> createCache(
             AuxiliaryCacheAttributes attr, ICompositeCacheManager cacheMgr,
            ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer )
     {
@@ -98,4 +96,24 @@ public class FileDiskCacheFactory
     {
         this.name = name;
     }
+
+    /**
+     * @see org.apache.commons.jcs.auxiliary.AuxiliaryCacheFactory#initialize()
+     */
+    @Override
+    public void initialize()
+    {
+        // TODO Auto-generated method stub
+
+    }
+
+    /**
+     * @see org.apache.commons.jcs.auxiliary.AuxiliaryCacheFactory#dispose()
+     */
+    @Override
+    public void dispose()
+    {
+        // TODO Auto-generated method stub
+
+    }
 }

Modified: commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheManager.java?rev=1721147&r1=1721146&r2=1721147&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheManager.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheManager.java
Mon Dec 21 13:19:11 2015
@@ -19,35 +19,40 @@ package org.apache.commons.jcs.auxiliary
  * under the License.
  */
 
-import org.apache.commons.jcs.auxiliary.disk.AbstractDiskCacheManager;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
 import org.apache.commons.jcs.engine.behavior.IElementSerializer;
 import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.io.Serializable;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
 /**
  * This is a non singleton. It creates caches on a per region basis.
  */
 public class FileDiskCacheManager
-    extends AbstractDiskCacheManager
 {
-    /** Don't change */
-    private static final long serialVersionUID = -4153287154512264626L;
-
     /** The logger */
     private static final Log log = LogFactory.getLog( FileDiskCacheManager.class );
 
     /** Each region has an entry here. */
-    private final Map<String, FileDiskCache<? extends Serializable, ? extends Serializable>>
caches =
-        new ConcurrentHashMap<String, FileDiskCache<? extends Serializable, ? extends
Serializable>>();
+    private final ConcurrentMap<String, FileDiskCache<?, ?>> caches =
+        new ConcurrentHashMap<String, FileDiskCache<?, ?>>();
+
+    /** Lock cache initialization */
+    private final Lock lock = new ReentrantLock();
 
     /** User configurable attributes */
     private final FileDiskCacheAttributes defaultCacheAttributes;
 
+    /** Event logger */
+    private final ICacheEventLogger eventLogger;
+
+    /** Custom serializer */
+    private final IElementSerializer elementSerializer;
+
     /**
      * Constructor for the DiskFileCacheManager object
      * <p>
@@ -59,8 +64,8 @@ public class FileDiskCacheManager
                                   IElementSerializer elementSerializer )
     {
         this.defaultCacheAttributes = defaultCacheAttributes;
-        setElementSerializer( elementSerializer );
-        setCacheEventLogger( cacheEventLogger );
+        this.elementSerializer = elementSerializer;
+        this.eventLogger = cacheEventLogger;
     }
 
     /**
@@ -69,10 +74,9 @@ public class FileDiskCacheManager
      * @param cacheName Name that will be used when creating attributes.
      * @return A cache.
      */
-    @Override
-    public <K extends Serializable, V extends Serializable> FileDiskCache<K, V>
getCache( String cacheName )
+    public <K, V> FileDiskCache<K, V> getCache( String cacheName )
     {
-        FileDiskCacheAttributes cacheAttributes = (FileDiskCacheAttributes) defaultCacheAttributes.copy();
+        FileDiskCacheAttributes cacheAttributes = (FileDiskCacheAttributes) defaultCacheAttributes.clone();
 
         cacheAttributes.setCacheName( cacheName );
 
@@ -86,7 +90,8 @@ public class FileDiskCacheManager
      * @param cacheAttributes Attributes the cache should have.
      * @return A cache, either from the existing set or newly created.
      */
-    public <K extends Serializable, V extends Serializable> FileDiskCache<K, V>
getCache( FileDiskCacheAttributes cacheAttributes )
+    @SuppressWarnings("unchecked") // Need to cast because of common map for all caches
+    public <K, V> FileDiskCache<K, V> getCache( FileDiskCacheAttributes cacheAttributes
)
     {
         FileDiskCache<K, V> cache = null;
 
@@ -94,23 +99,30 @@ public class FileDiskCacheManager
 
         log.debug( "Getting cache named: " + cacheName );
 
-        synchronized ( caches )
-        {
-            // Try to load the cache from the set that have already been
-            // created. This only looks at the name attribute.
+        // Try to load the cache from the set that have already been
+        // created. This only looks at the name attribute.
+        cache = (FileDiskCache<K, V>) caches.get( cacheName );
 
-            @SuppressWarnings("unchecked") // Need to cast because of common map for all
caches
-            FileDiskCache<K, V> fileDiskCache = (FileDiskCache<K, V>) caches.get(
cacheName );
-            cache = fileDiskCache;
+        if (cache == null)
+        {
+            lock.lock();
 
-            // If it was not found, create a new one using the supplied
-            // attributes
+            try
+            {
+                cache = (FileDiskCache<K, V>) caches.get( cacheName );
 
-            if ( cache == null )
+                // If it was not found, create a new one using the supplied
+                // attributes
+                if ( cache == null )
+                {
+                    cache = new FileDiskCache<K, V>( cacheAttributes, elementSerializer
);
+                    cache.setCacheEventLogger( eventLogger );
+                    caches.put( cacheName, cache );
+                }
+            }
+            finally
             {
-                cache = new FileDiskCache<K, V>( cacheAttributes, getElementSerializer()
);
-                cache.setCacheEventLogger( getCacheEventLogger() );
-                caches.put( cacheName, cache );
+                lock.unlock();
             }
         }
 



Mime
View raw message