commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1593837 - /commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCache.java
Date Sun, 11 May 2014 18:43:51 GMT
Author: rmannibucau
Date: Sun May 11 18:43:51 2014
New Revision: 1593837

URL: http://svn.apache.org/r1593837
Log:
cleaning up CacheEvictor before trying to merge jcache and jcs modules

Modified:
    commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCache.java

Modified: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCache.java?rev=1593837&r1=1593836&r2=1593837&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCache.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCache.java
Sun May 11 18:43:51 2014
@@ -80,6 +80,7 @@ public class JCSCache<K, V, C extends Co
     private final String name;
     private final long maxSize;
     private final long maxDelete;
+    private final CacheEvictor<K, V> evictor;
     private volatile boolean closed = false;
     private final Map<CacheEntryListenerConfiguration<K, V>, JCSListener<K, V>>
listeners = new ConcurrentHashMap<CacheEntryListenerConfiguration<K, V>, JCSListener<K,
V>>();
     private final Statistics statistics = new Statistics();
@@ -109,26 +110,25 @@ public class JCSCache<K, V, C extends Co
         maxSize = Long.parseLong(property(properties, cacheName, "maxSize", "1000"));
         maxDelete = Long.parseLong(property(properties, cacheName, "maxDeleteByEvictionRun",
"100"));
         final long evictionPause = Long.parseLong(properties.getProperty(cacheName + ".evictionPause",
properties.getProperty("evictionPause", "30000")));
-        if (evictionPause > 0)
+        final String evictorClass = property(properties, cacheName, "evictor", null);
+        if (evictorClass != null)
         {
-            final CacheEvictor<K, V> evictor;
-            final String evictorClass = property(properties, cacheName, "evictor", null);
-            if (evictorClass != null)
+            try
             {
-                try
-                {
-                    evictor = CacheEvictor.class.cast(classLoader.loadClass(evictorClass).newInstance());
-                }
-                catch (final Exception e)
-                {
-                    throw new IllegalStateException(e);
-                }
+                evictor = CacheEvictor.class.cast(classLoader.loadClass(evictorClass).newInstance());
             }
-            else
+            catch (final Exception e)
             {
-                evictor = null;
+                throw new IllegalStateException(e);
             }
-            pool.submit(new EvictionThread<K, V>(this, evictionPause, evictor));
+        }
+        else
+        {
+            evictor = null;
+        }
+        if (evictionPause > 0)
+        {
+            pool.submit(new EvictionThread<K, V>(this, evictionPause));
         }
 
         final Factory<CacheLoader<K, V>> cacheLoaderFactory = configuration.getCacheLoaderFactory();
@@ -935,13 +935,11 @@ public class JCSCache<K, V, C extends Co
     {
         private final long pause;
         private final JCSCache<K, V, ?> cache;
-        private final CacheEvictor<K, V> evictor;
 
-        public EvictionThread(final JCSCache<K, V, ?> cache, final long evictionPause,
final CacheEvictor<K, V> evictor)
+        public EvictionThread(final JCSCache<K, V, ?> cache, final long evictionPause)
         {
             this.cache = cache;
             this.pause = evictionPause;
-            this.evictor = evictor;
         }
 
         @Override
@@ -949,14 +947,7 @@ public class JCSCache<K, V, C extends Co
         {
             while (!cache.isClosed())
             {
-                if (evictor != null)
-                {
-                    evictor.evict(cache);
-                }
-                else
-                {
-                    cache.evict();
-                }
+                cache.evict();
                 try
                 {
                     Thread.sleep(pause);
@@ -992,6 +983,18 @@ public class JCSCache<K, V, C extends Co
             return;
         }
 
+        if (evictor != null)
+        {
+            evictor.evict(this);
+        }
+        else
+        {
+            defaultEviction();
+        }
+    }
+
+    private void defaultEviction()
+    {
         final ConcurrentMap<JCSKey<K>, ? extends JCSElement<?>> map = delegate;
         try
         {



Mime
View raw message