commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1590529 - in /commons/proper/jcs/trunk: src/java/org/apache/commons/jcs/jcache/JCSCache.java src/java/org/apache/commons/jcs/jcache/JCSConfiguration.java src/java/org/apache/commons/jcs/jcache/JCSListener.java tck.sh
Date Sun, 27 Apr 2014 23:47:57 GMT
Author: olamy
Date: Sun Apr 27 23:47:56 2014
New Revision: 1590529

URL: http://svn.apache.org/r1590529
Log:
one more hack for a tck

Modified:
    commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSCache.java
    commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSConfiguration.java
    commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSListener.java
    commons/proper/jcs/trunk/tck.sh   (contents, props changed)

Modified: commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSCache.java?rev=1590529&r1=1590528&r2=1590529&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSCache.java Sun Apr
27 23:47:56 2014
@@ -41,7 +41,7 @@ import static org.apache.commons.jcs.jca
 public class JCSCache<K extends Serializable, V extends Serializable, C extends CompleteConfiguration<K,
V>> implements Cache<K, V> {
     private final CacheAccess<K, JCSElement<V>> delegate;
     private final CacheManager manager;
-    private final C config;
+    private final JCSConfiguration<K, V> config;
     private final CacheLoader<K, V> loader;
     private final CacheWriter<? super K, ? super V> writer;
     private final ExpiryPolicy expiryPolicy;
@@ -51,7 +51,7 @@ public class JCSCache<K extends Serializ
     private final Map<CacheEntryListenerConfiguration<K, V>, JCSListener<K, V>>
listeners = new ConcurrentHashMap<CacheEntryListenerConfiguration<K, V>, JCSListener<K,
V>>();
     private final Statistics statistics = new Statistics();
 
-    public JCSCache(final CacheManager mgr, final C configuration, final CompositeCache<K,
JCSElement<V>> cache) {
+    public JCSCache(final CacheManager mgr, final JCSConfiguration<K, V> configuration,
final CompositeCache<K, JCSElement<V>> cache) {
         manager = mgr;
         delegate = new CacheAccess<K, JCSElement<V>>(cache);
         config = configuration;
@@ -77,6 +77,10 @@ public class JCSCache<K extends Serializ
             expiryPolicy = expiryPolicyFactory.create();
         }
 
+        for (final CacheEntryListenerConfiguration<K, V> listener : config.getCacheEntryListenerConfigurations())
{
+            listeners.put(listener, new JCSListener<K, V>(listener));
+        }
+
         statistics.setActive(config.isStatisticsEnabled());
 
         final String mgrStr = manager.getURI().toString().replaceAll(",|:|=|\n", ".");
@@ -253,10 +257,12 @@ public class JCSCache<K extends Serializ
         assertNotClosed();
         assertNotNull(key, "key");
 
+        final JCSElement<V> v = delegate.get(key);
+        final V value = v != null && v.getElement() != null ? v.getElement() : null;
         final boolean remove = delegate.getCacheControl().remove(key);
         for (final JCSListener<K, V> listener : listeners.values()) {
             listener.onRemoved(Arrays.<CacheEntryEvent<? extends K, ? extends V>>asList(
-                    new JCSCacheEntryEvent<K, V>(this, EventType.REMOVED, null, key,
null)));
+                    new JCSCacheEntryEvent<K, V>(this, EventType.REMOVED, null, key,
value)));
         }
         return remove;
     }
@@ -440,13 +446,18 @@ public class JCSCache<K extends Serializ
     @Override
     public void registerCacheEntryListener(final CacheEntryListenerConfiguration<K, V>
cacheEntryListenerConfiguration) {
         assertNotClosed();
+        if (listeners.containsKey(cacheEntryListenerConfiguration)) {
+            throw new IllegalArgumentException(cacheEntryListenerConfiguration + " already
registered");
+        }
         listeners.put(cacheEntryListenerConfiguration, new JCSListener<K, V>(cacheEntryListenerConfiguration));
+        config.addListener(cacheEntryListenerConfiguration);
     }
 
     @Override
     public void deregisterCacheEntryListener(final CacheEntryListenerConfiguration<K,
V> cacheEntryListenerConfiguration) {
         assertNotClosed();
         listeners.remove(cacheEntryListenerConfiguration);
+        config.removeListener(cacheEntryListenerConfiguration);
     }
 
     @Override

Modified: commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSConfiguration.java?rev=1590529&r1=1590528&r2=1590529&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSConfiguration.java
(original)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSConfiguration.java
Sun Apr 27 23:47:56 2014
@@ -26,23 +26,19 @@ import javax.cache.integration.CacheLoad
 import javax.cache.integration.CacheWriter;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Properties;
 import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
 
 public class JCSConfiguration<K, V> implements CompleteConfiguration<K, V> {
 
     private final Class<K> keyType;
     private final Class<V> valueType;
-    private final ConcurrentMap<CacheEntryListenerConfiguration<K,V>, Object>
cacheEntryListenerConfigurations = new ConcurrentHashMap<CacheEntryListenerConfiguration<K,
V>, Object>();
     private final boolean storeByValue;
     private final boolean readThrough;
     private final boolean writeThrough;
     private final Factory<CacheLoader<K,V>> cacheLoaderFactory;
     private final Factory<CacheWriter<? super K,? super V>> cacheWristerFactory;
     private final Factory<ExpiryPolicy> expiryPolicyFactory;
-    private final Set<CacheEntryListenerConfiguration<K, V>> initialCacheEntryListenerConfigurations;
+    private final Set<CacheEntryListenerConfiguration<K, V>> cacheEntryListenerConfigurations;
 
     private boolean statisticsEnabled = true;
     private boolean managementEnabled = true;
@@ -60,15 +56,14 @@ public class JCSConfiguration<K, V> impl
             cacheLoaderFactory = cConfiguration.getCacheLoaderFactory();
             cacheWristerFactory = cConfiguration.getCacheWriterFactory();
             this.expiryPolicyFactory = cConfiguration.getExpiryPolicyFactory();
-            final HashSet<CacheEntryListenerConfiguration<K, V>> set = new HashSet<CacheEntryListenerConfiguration<K,
V>>();
+            cacheEntryListenerConfigurations = new HashSet<CacheEntryListenerConfiguration<K,
V>>();
 
             final Iterable<CacheEntryListenerConfiguration<K, V>> entryListenerConfigurations
= cConfiguration.getCacheEntryListenerConfigurations();
             if (entryListenerConfigurations != null) {
                 for (final CacheEntryListenerConfiguration<K, V> kvCacheEntryListenerConfiguration
: entryListenerConfigurations) {
-                    set.add(kvCacheEntryListenerConfiguration);
+                    cacheEntryListenerConfigurations.add(kvCacheEntryListenerConfiguration);
                 }
             }
-            initialCacheEntryListenerConfigurations = Collections.unmodifiableSet(set);
         } else {
             expiryPolicyFactory = EternalExpiryPolicy.factoryOf();
             storeByValue = true;
@@ -76,7 +71,7 @@ public class JCSConfiguration<K, V> impl
             writeThrough = false;
             cacheLoaderFactory = null;
             cacheWristerFactory = null;
-            initialCacheEntryListenerConfigurations = new HashSet<CacheEntryListenerConfiguration<K,
V>>();
+            cacheEntryListenerConfigurations = new HashSet<CacheEntryListenerConfiguration<K,
V>>();
         }
     }
 
@@ -117,7 +112,7 @@ public class JCSConfiguration<K, V> impl
 
     @Override
     public Iterable<CacheEntryListenerConfiguration<K, V>> getCacheEntryListenerConfigurations()
{
-        return cacheEntryListenerConfigurations.keySet();
+        return Collections.unmodifiableSet(cacheEntryListenerConfigurations);
     }
 
     @Override
@@ -134,4 +129,12 @@ public class JCSConfiguration<K, V> impl
     public Factory<ExpiryPolicy> getExpiryPolicyFactory() {
         return expiryPolicyFactory;
     }
+
+    public synchronized void addListener(final CacheEntryListenerConfiguration<K, V>
cacheEntryListenerConfiguration) {
+        cacheEntryListenerConfigurations.add(cacheEntryListenerConfiguration);
+    }
+
+    public synchronized void removeListener(final CacheEntryListenerConfiguration<K, V>
cacheEntryListenerConfiguration) {
+        cacheEntryListenerConfigurations.remove(cacheEntryListenerConfiguration);
+    }
 }

Modified: commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSListener.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSListener.java?rev=1590529&r1=1590528&r2=1590529&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSListener.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSListener.java Sun Apr
27 23:47:56 2014
@@ -82,6 +82,6 @@ public class JCSListener<K extends Seria
     }
 
     public void close() {
-
+        // no-op
     }
 }

Modified: commons/proper/jcs/trunk/tck.sh
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/tck.sh?rev=1590529&r1=1590528&r2=1590529&view=diff
==============================================================================
    (empty)

Propchange: commons/proper/jcs/trunk/tck.sh
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message