commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1591120 - in /commons/proper/jcs/trunk: ./ commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/
Date Tue, 29 Apr 2014 22:02:23 GMT
Author: struberg
Date: Tue Apr 29 22:02:23 2014
New Revision: 1591120

URL: http://svn.apache.org/r1591120
Log:
JCS-120 fix broken tests and add some ALv2 headers

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

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=1591120&r1=1591119&r2=1591120&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
Tue Apr 29 22:02:23 2014
@@ -1,17 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.commons.jcs.jcache;
 
-import static org.apache.commons.jcs.jcache.Asserts.assertNotNull;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
+import org.apache.commons.jcs.access.CacheAccess;
+import org.apache.commons.jcs.access.exception.CacheException;
+import org.apache.commons.jcs.engine.behavior.ICacheElement;
+import org.apache.commons.jcs.engine.behavior.IElementSerializer;
+import org.apache.commons.jcs.engine.control.CompositeCache;
+import org.apache.commons.jcs.jcache.jmx.JCSCacheMXBean;
+import org.apache.commons.jcs.jcache.jmx.JCSCacheStatisticsMXBean;
+import org.apache.commons.jcs.jcache.jmx.JMXs;
+import org.apache.commons.jcs.jcache.proxy.ExceptionWrapperHandler;
+import org.apache.commons.jcs.utils.serialization.StandardSerializer;
+import org.apache.commons.jcs.utils.threadpool.ThreadPoolManager;
 
 import javax.cache.Cache;
 import javax.cache.CacheManager;
@@ -33,18 +50,18 @@ import javax.cache.processor.EntryProces
 import javax.cache.processor.EntryProcessorException;
 import javax.cache.processor.EntryProcessorResult;
 import javax.management.ObjectName;
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
-import org.apache.commons.jcs.access.CacheAccess;
-import org.apache.commons.jcs.access.exception.CacheException;
-import org.apache.commons.jcs.engine.behavior.ICacheElement;
-import org.apache.commons.jcs.engine.behavior.IElementSerializer;
-import org.apache.commons.jcs.engine.control.CompositeCache;
-import org.apache.commons.jcs.jcache.jmx.JCSCacheMXBean;
-import org.apache.commons.jcs.jcache.jmx.JCSCacheStatisticsMXBean;
-import org.apache.commons.jcs.jcache.jmx.JMXs;
-import org.apache.commons.jcs.jcache.proxy.ExceptionWrapperHandler;
-import org.apache.commons.jcs.utils.serialization.StandardSerializer;
-import org.apache.commons.jcs.utils.threadpool.ThreadPoolManager;
+import static org.apache.commons.jcs.jcache.Asserts.assertNotNull;
 
 // TODO: get statistics locally correct then correct even if distributed
 public class JCSCache<K extends Serializable, V extends Serializable, C extends CompleteConfiguration<K,
V>> implements Cache<K, V>
@@ -66,14 +83,14 @@ public class JCSCache<K extends Serializ
     private final ExecutorService pool;
 
     public JCSCache(final ClassLoader classLoader, final CacheManager mgr, final JCSConfiguration<K,
V> configuration,
-            final CompositeCache<K, JCSElement<V>> cache, final Properties properties)
+                    final CompositeCache<K, JCSElement<V>> cache, final Properties
properties)
     {
         manager = mgr;
         delegate = new CacheAccess<K, JCSElement<V>>(cache);
         config = configuration;
-        pool = properties != null && properties.containsKey(POOL_SIZE_PROPERTY) ?
Executors.newFixedThreadPool(
-                Integer.parseInt(properties.getProperty(POOL_SIZE_PROPERTY)), new ThreadPoolManager.MyThreadFactory())
: Executors
-                .newCachedThreadPool(new ThreadPoolManager.MyThreadFactory());
+        pool = properties != null && properties.containsKey(POOL_SIZE_PROPERTY)?
+                Executors.newFixedThreadPool(Integer.parseInt(properties.getProperty(POOL_SIZE_PROPERTY)),
new ThreadPoolManager.MyThreadFactory()) :
+                Executors.newCachedThreadPool(new ThreadPoolManager.MyThreadFactory());
 
         final Factory<CacheLoader<K, V>> cacheLoaderFactory = configuration.getCacheLoaderFactory();
         if (cacheLoaderFactory == null)
@@ -82,8 +99,7 @@ public class JCSCache<K extends Serializ
         }
         else
         {
-            loader = ExceptionWrapperHandler
-                    .newProxy(classLoader, cacheLoaderFactory.create(), CacheLoaderException.class,
CacheLoader.class);
+            loader = ExceptionWrapperHandler.newProxy(classLoader, cacheLoaderFactory.create(),
CacheLoaderException.class, CacheLoader.class);
         }
 
         final Factory<CacheWriter<? super K, ? super V>> cacheWriterFactory =
configuration.getCacheWriterFactory();
@@ -93,8 +109,7 @@ public class JCSCache<K extends Serializ
         }
         else
         {
-            writer = ExceptionWrapperHandler
-                    .newProxy(classLoader, cacheWriterFactory.create(), CacheWriterException.class,
CacheWriter.class);
+            writer = ExceptionWrapperHandler.newProxy(classLoader, cacheWriterFactory.create(),
CacheWriterException.class, CacheWriter.class);
         }
 
         final Factory<ExpiryPolicy> expiryPolicyFactory = configuration.getExpiryPolicyFactory();
@@ -117,10 +132,16 @@ public class JCSCache<K extends Serializ
         final String mgrStr = manager.getURI().toString().replaceAll(",|:|=|\n", ".");
         try
         {
-            cacheConfigObjectName = new ObjectName("javax.cache:type=CacheConfiguration,"
+ "CacheManager=" + mgrStr + "," + "Cache="
-                    + cache.getCacheName());
-            cacheStatsObjectName = new ObjectName("javax.cache:type=CacheStatistics," + "CacheManager="
+ mgrStr + "," + "Cache="
-                    + cache.getCacheName());
+            cacheConfigObjectName = new ObjectName(
+                    "javax.cache:type=CacheConfiguration," +
+                            "CacheManager=" + mgrStr + "," +
+                            "Cache=" + cache.getCacheName()
+            );
+            cacheStatsObjectName = new ObjectName(
+                    "javax.cache:type=CacheStatistics," +
+                            "CacheManager=" + mgrStr + "," +
+                            "Cache=" + cache.getCacheName()
+            );
         }
         catch (final Exception e)
         {
@@ -202,7 +223,7 @@ public class JCSCache<K extends Serializ
         assertNotClosed();
         for (final K k : keys)
         {
-            assertNotNull(k, "key");
+            assertNotNull(k , "key");
         }
 
         final Set<K> names = (Set<K>) keys;
@@ -267,14 +288,13 @@ public class JCSCache<K extends Serializ
         try
         {
             final JCSElement<V> oldElt = delegate.get(key);
-            final V old = oldElt != null ? oldElt.getElement() : null;
+            final V old = oldElt != null? oldElt.getElement() : null;
 
             final boolean storeByValue = config.isStoreByValue();
             final V value = storeByValue ? copy(rawValue) : rawValue;
 
             final boolean created = old == null;
-            final JCSElement<V> element = new JCSElement<V>(value, created ?
expiryPolicy.getExpiryForCreation()
-                    : expiryPolicy.getExpiryForUpdate());
+            final JCSElement<V> element = new JCSElement<V>(value, created ?
expiryPolicy.getExpiryForCreation() : expiryPolicy.getExpiryForUpdate());
             if (element.isExpired())
             {
                 if (!created)
@@ -290,13 +310,13 @@ public class JCSCache<K extends Serializ
                 {
                     if (created)
                     {
-                        listener.onCreated(Arrays.<CacheEntryEvent<? extends K, ? extends
V>> asList(new JCSCacheEntryEvent<K, V>(this,
-                                EventType.CREATED, null, key, value)));
+                        listener.onCreated(Arrays.<CacheEntryEvent<? extends K, ? extends
V>>asList(
+                                new JCSCacheEntryEvent<K, V>(this, EventType.CREATED,
null, key, value)));
                     }
                     else
                     {
-                        listener.onUpdated(Arrays.<CacheEntryEvent<? extends K, ? extends
V>> asList(new JCSCacheEntryEvent<K, V>(this,
-                                EventType.UPDATED, old, key, value)));
+                        listener.onUpdated(Arrays.<CacheEntryEvent<? extends K, ? extends
V>>asList(
+                                new JCSCacheEntryEvent<K, V>(this, EventType.UPDATED,
old, key, value)));
                     }
                 }
 
@@ -375,8 +395,8 @@ public class JCSCache<K extends Serializ
         }
         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, value)));
+            listener.onRemoved(Arrays.<CacheEntryEvent<? extends K, ? extends V>>asList(
+                    new JCSCacheEntryEvent<K, V>(this, EventType.REMOVED, null, key,
value)));
         }
         if (remove && statisticsEnabled)
         {
@@ -393,7 +413,8 @@ public class JCSCache<K extends Serializ
         assertNotNull(key, "key");
         assertNotNull(oldValue, "oldValue");
         final V v = doGetControllingExpiry(key, false, false, false, false);
-        if (v != null)
+        final boolean found = v != null;
+        if (found)
         {
             if (v.equals(oldValue))
             {
@@ -413,13 +434,14 @@ public class JCSCache<K extends Serializ
         return v;
     }
 
-    private V doGetControllingExpiry(final K key, final boolean updateAcess, final boolean
forceDoLoad, final boolean skipLoad,
-            final boolean propagateLoadException)
+    private V doGetControllingExpiry(final K key, final boolean updateAcess,
+                                     final boolean forceDoLoad, final boolean skipLoad,
+                                     final boolean propagateLoadException)
     {
         final boolean statisticsEnabled = config.isStatisticsEnabled();
         final long getStart = Times.now();
         final JCSElement<V> elt = delegate.get(key);
-        V v = elt != null ? elt.getElement() : null;
+        V v = elt != null? elt.getElement() : null;
         if (v == null && (config.isReadThrough() || forceDoLoad))
         {
             if (!skipLoad)
@@ -593,7 +615,8 @@ public class JCSCache<K extends Serializ
     }
 
     @Override
-    public void loadAll(final Set<? extends K> keys, final boolean replaceExistingValues,
final CompletionListener completionListener)
+    public void loadAll(final Set<? extends K> keys, final boolean replaceExistingValues,
+                        final CompletionListener completionListener)
     {
         assertNotClosed();
         assertNotNull(keys, "keys");
@@ -611,7 +634,8 @@ public class JCSCache<K extends Serializ
         });
     }
 
-    private void doLoadAll(final Set<? extends K> keys, final boolean replaceExistingValues,
final CompletionListener completionListener)
+    private void doLoadAll(final Set<? extends K> keys, final boolean replaceExistingValues,
+                           final CompletionListener completionListener)
     {
         try
         {
@@ -652,8 +676,7 @@ public class JCSCache<K extends Serializ
         return t;
     }
 
-    private <T> T doInvoke(final TempStateCacheView<K, V> view, final K key,
final EntryProcessor<K, V, T> entryProcessor,
-            final Object... arguments)
+    private <T> T doInvoke(final TempStateCacheView<K, V> view, final K key,
final EntryProcessor<K, V, T> entryProcessor, final Object... arguments)
     {
         assertNotClosed();
         assertNotNull(entryProcessor, "entryProcessor");
@@ -689,8 +712,9 @@ public class JCSCache<K extends Serializ
     }
 
     @Override
-    public <T> Map<K, EntryProcessorResult<T>> invokeAll(final Set<?
extends K> keys, final EntryProcessor<K, V, T> entryProcessor,
-            final Object... arguments)
+    public <T> Map<K, EntryProcessorResult<T>> invokeAll(final Set<?
extends K> keys,
+                                                         final EntryProcessor<K, V, T>
entryProcessor,
+                                                         final Object... arguments)
     {
         assertNotClosed();
         assertNotNull(entryProcessor, "entryProcessor");
@@ -731,8 +755,7 @@ public class JCSCache<K extends Serializ
     public void registerCacheEntryListener(final CacheEntryListenerConfiguration<K, V>
cacheEntryListenerConfiguration)
     {
         assertNotClosed();
-        if (listeners.containsKey(cacheEntryListenerConfiguration))
-        {
+        if (listeners.containsKey(cacheEntryListenerConfiguration)) {
             throw new IllegalArgumentException(cacheEntryListenerConfiguration + " already
registered");
         }
         listeners.put(cacheEntryListenerConfiguration, new JCSListener<K, V>(cacheEntryListenerConfiguration));
@@ -740,8 +763,7 @@ public class JCSCache<K extends Serializ
     }
 
     @Override
-    public void deregisterCacheEntryListener(final CacheEntryListenerConfiguration<K,
V> cacheEntryListenerConfiguration)
-    {
+    public void deregisterCacheEntryListener(final CacheEntryListenerConfiguration<K,
V> cacheEntryListenerConfiguration) {
         assertNotClosed();
         listeners.remove(cacheEntryListenerConfiguration);
         config.removeListener(cacheEntryListenerConfiguration);

Modified: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCachingManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCachingManager.java?rev=1591120&r1=1591119&r2=1591120&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCachingManager.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCachingManager.java
Tue Apr 29 22:02:23 2014
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.commons.jcs.jcache;
 
 import static org.apache.commons.jcs.jcache.Asserts.assertNotNull;
@@ -90,19 +108,21 @@ public class JCSCachingManager implement
     {
         assertNotClosed();
         assertNotNull(cacheName, "cacheName");
+        final Class<?> keyType = configuration == null ? Object.class : configuration.getKeyType();
+        final Class<?> valueType = configuration == null ? Object.class : configuration.getValueType();
         if (!caches.containsKey(cacheName))
         {
             final Cache<K, V> cache = ClassLoaderAwareHandler.newProxy(
                     loader,
-                    new JCSCache/* <K, V, C> */(loader, this, new JCSConfiguration(configuration,
configuration.getKeyType(), configuration
-                            .getValueType()), instance.getCache(cacheName), instance.getConfigurationProperties()),
Cache.class);
+                    new JCSCache/* <K, V, C> */(loader, this, new JCSConfiguration(configuration,
keyType, valueType),
+                                                instance.getCache(cacheName), instance.getConfigurationProperties()),
Cache.class);
             caches.putIfAbsent(cacheName, cache);
         }
         else
         {
             throw new javax.cache.CacheException("cache " + cacheName + " already exists");
         }
-        return getCache(cacheName, configuration.getKeyType(), configuration.getValueType());
+        return (Cache<K, V>) getCache(cacheName, keyType, valueType);
     }
 
     @Override
@@ -183,6 +203,7 @@ public class JCSCachingManager implement
         {
             JCSCachingProvider.class.cast(provider).remove(this);
         }
+		instance.shutDown();
     }
 
     @Override
@@ -239,7 +260,8 @@ public class JCSCachingManager implement
         }
 
         final Configuration<K, V> config = cache.getConfiguration(Configuration.class);
-        if (!config.getKeyType().isAssignableFrom(keyType) || !config.getValueType().isAssignableFrom(valueType))
+        if ((keyType != null && !config.getKeyType().isAssignableFrom(keyType))
+            || (valueType != null && !config.getValueType().isAssignableFrom(valueType)))
         {
             throw new IllegalArgumentException("this cache is <" + config.getKeyType().getName()
+ ", " + config.getValueType().getName()
                     + "> " + " and not <" + keyType.getName() + ", " + valueType.getName()
+ ">");

Modified: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSElement.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSElement.java?rev=1591120&r1=1591119&r2=1591120&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSElement.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSElement.java
Tue Apr 29 22:02:23 2014
@@ -1,14 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.commons.jcs.jcache;
 
-import java.io.Serializable;
-
 import javax.cache.expiry.Duration;
+import java.io.Serializable;
 
 public class JCSElement<V> implements Serializable
 {
-    /** Serial version */
-    private static final long serialVersionUID = 6399046812336629074L;
-
     private final V element;
     private volatile long end;
 
@@ -33,12 +47,10 @@ public class JCSElement<V> implements Se
         if (duration == null || duration.isEternal())
         {
             end = -1;
-        }
-        else if (duration.isZero())
+        } else if (duration.isZero())
         {
             end = 0;
-        }
-        else
+        } else
         {
             end = duration.getAdjustedTime(Times.now());
         }

Modified: commons/proper/jcs/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/pom.xml?rev=1591120&r1=1591119&r2=1591120&view=diff
==============================================================================
--- commons/proper/jcs/trunk/pom.xml (original)
+++ commons/proper/jcs/trunk/pom.xml Tue Apr 29 22:02:23 2014
@@ -26,7 +26,6 @@
     <version>33</version>
   </parent>
 
-  <groupId>org.apache.commons</groupId>
   <artifactId>commons-jcs</artifactId>
   <packaging>pom</packaging>
   <version>2.0-SNAPSHOT</version>
@@ -244,7 +243,7 @@
       </dependency>
       <dependency>
         <groupId>org.hamcrest</groupId>
-        <artifactId>hamcrest-all</artifactId>
+        <artifactId>hamcrest-library</artifactId>
         <version>1.3</version>
         <scope>test</scope>
       </dependency>



Mime
View raw message