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 2014/04/29 21:45:15 UTC
svn commit: r1591068 [1/2] - in /commons/proper/jcs/trunk:
commons-jcs-core/src/main/java/org/apache/commons/jcs/io/
commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/
commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/cdi/ com...
Author: tv
Date: Tue Apr 29 19:45:14 2014
New Revision: 1591068
URL: http://svn.apache.org/r1591068
Log:
Fix formatting
Modified:
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/Asserts.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/ImmutableIterable.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/ImmutableIterator.java
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/JCSCacheEntryEvent.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/JCSCachingProvider.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSConfiguration.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSElement.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSEntry.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSListener.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSMutableEntry.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/NoFilter.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/NoLoader.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/NoWriter.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/Statistics.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/TempStateCacheView.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/Times.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/cdi/CachePutInterceptor.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/cdi/CacheRemoveAllInterceptor.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/cdi/CacheRemoveInterceptor.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/cdi/CacheResultInterceptor.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/cdi/MakeJCacheCDIIntercetporFriendly.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/jmx/ConfigurableMBeanServerIdBuilder.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/jmx/JCSCacheMXBean.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/jmx/JCSCacheStatisticsMXBean.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/jmx/JMXs.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/proxy/ClassLoaderAwareHandler.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/proxy/ExceptionWrapperHandler.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/test/java/org/apache/commons/jcs/jcache/CacheTest.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/test/java/org/apache/commons/jcs/jcache/CachingProviderTest.java
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java?rev=1591068&r1=1591067&r2=1591068&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java Tue Apr 29 19:45:14 2014
@@ -6,29 +6,37 @@ import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;
import java.lang.reflect.Proxy;
-public class ObjectInputStreamClassLoaderAware extends ObjectInputStream {
+public class ObjectInputStreamClassLoaderAware extends ObjectInputStream
+{
private final ClassLoader classLoader;
- public ObjectInputStreamClassLoaderAware(final InputStream in, final ClassLoader classLoader) throws IOException {
+ public ObjectInputStreamClassLoaderAware(final InputStream in, final ClassLoader classLoader) throws IOException
+ {
super(in);
- this.classLoader = classLoader != null? classLoader : Thread.currentThread().getContextClassLoader();
+ this.classLoader = classLoader != null ? classLoader : Thread.currentThread().getContextClassLoader();
}
@Override
- protected Class<?> resolveClass(final ObjectStreamClass desc) throws ClassNotFoundException {
+ protected Class<?> resolveClass(final ObjectStreamClass desc) throws ClassNotFoundException
+ {
return Class.forName(desc.getName(), false, classLoader);
}
@Override
- protected Class resolveProxyClass(final String[] interfaces) throws IOException, ClassNotFoundException {
+ protected Class resolveProxyClass(final String[] interfaces) throws IOException, ClassNotFoundException
+ {
final Class[] cinterfaces = new Class[interfaces.length];
- for (int i = 0; i < interfaces.length; i++) {
+ for (int i = 0; i < interfaces.length; i++)
+ {
cinterfaces[i] = Class.forName(interfaces[i], false, classLoader);
}
- try {
+ try
+ {
return Proxy.getProxyClass(classLoader, cinterfaces);
- } catch (IllegalArgumentException e) {
+ }
+ catch (IllegalArgumentException e)
+ {
throw new ClassNotFoundException(null, e);
}
}
Modified: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/Asserts.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/Asserts.java?rev=1591068&r1=1591067&r2=1591068&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/Asserts.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/Asserts.java Tue Apr 29 19:45:14 2014
@@ -1,13 +1,17 @@
package org.apache.commons.jcs.jcache;
-public class Asserts {
- public static void assertNotNull(final Object value, final String name) {
- if (value == null) {
+public class Asserts
+{
+ public static void assertNotNull(final Object value, final String name)
+ {
+ if (value == null)
+ {
throw new NullPointerException(name + " is null");
}
}
- private Asserts() {
+ private Asserts()
+ {
// no-op
}
}
Modified: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/ImmutableIterable.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/ImmutableIterable.java?rev=1591068&r1=1591067&r2=1591068&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/ImmutableIterable.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/ImmutableIterable.java Tue Apr 29 19:45:14 2014
@@ -4,15 +4,18 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
-public class ImmutableIterable<T> implements Iterable<T> {
+public class ImmutableIterable<T> implements Iterable<T>
+{
private final Collection<T> delegate;
- public ImmutableIterable(final Collection<T> delegate) {
+ public ImmutableIterable(final Collection<T> delegate)
+ {
this.delegate = new ArrayList<T>(delegate);
}
@Override
- public Iterator<T> iterator() {
+ public Iterator<T> iterator()
+ {
return new ImmutableIterator<T>(delegate.iterator());
}
}
Modified: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/ImmutableIterator.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/ImmutableIterator.java?rev=1591068&r1=1591067&r2=1591068&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/ImmutableIterator.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/ImmutableIterator.java Tue Apr 29 19:45:14 2014
@@ -2,25 +2,30 @@ package org.apache.commons.jcs.jcache;
import java.util.Iterator;
-public class ImmutableIterator<T> implements Iterator<T> {
+public class ImmutableIterator<T> implements Iterator<T>
+{
private final Iterator<T> delegate;
- public ImmutableIterator(final Iterator<T> delegate) {
+ public ImmutableIterator(final Iterator<T> delegate)
+ {
this.delegate = delegate;
}
@Override
- public boolean hasNext() {
+ public boolean hasNext()
+ {
return delegate.hasNext();
}
@Override
- public T next() {
+ public T next()
+ {
return delegate.next();
}
@Override
- public void remove() {
+ public void remove()
+ {
throw new UnsupportedOperationException("this iterator is immutable");
}
}
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=1591068&r1=1591067&r2=1591068&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 19:45:14 2014
@@ -1,16 +1,17 @@
package org.apache.commons.jcs.jcache;
-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;
+
+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 javax.cache.Cache;
import javax.cache.CacheManager;
@@ -32,21 +33,22 @@ 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 static org.apache.commons.jcs.jcache.Asserts.assertNotNull;
+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;
// 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> {
+public class JCSCache<K extends Serializable, V extends Serializable, C extends CompleteConfiguration<K, V>> implements Cache<K, V>
+{
private static final String POOL_SIZE_PROPERTY = ThreadPoolManager.PROP_NAME_ROOT + ".size";
private final CacheAccess<K, JCSElement<V>> delegate;
@@ -64,138 +66,178 @@ 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) {
+ if (cacheLoaderFactory == null)
+ {
loader = NoLoader.INSTANCE;
- } else {
- loader = ExceptionWrapperHandler.newProxy(classLoader, cacheLoaderFactory.create(), CacheLoaderException.class, CacheLoader.class);
+ }
+ else
+ {
+ loader = ExceptionWrapperHandler
+ .newProxy(classLoader, cacheLoaderFactory.create(), CacheLoaderException.class, CacheLoader.class);
}
final Factory<CacheWriter<? super K, ? super V>> cacheWriterFactory = configuration.getCacheWriterFactory();
- if (cacheWriterFactory == null) {
+ if (cacheWriterFactory == null)
+ {
writer = NoWriter.INSTANCE;
- } else {
- writer = ExceptionWrapperHandler.newProxy(classLoader, cacheWriterFactory.create(), CacheWriterException.class, CacheWriter.class);
+ }
+ else
+ {
+ writer = ExceptionWrapperHandler
+ .newProxy(classLoader, cacheWriterFactory.create(), CacheWriterException.class, CacheWriter.class);
}
final Factory<ExpiryPolicy> expiryPolicyFactory = configuration.getExpiryPolicyFactory();
- if (expiryPolicyFactory == null) {
+ if (expiryPolicyFactory == null)
+ {
expiryPolicy = new EternalExpiryPolicy();
- } else {
+ }
+ else
+ {
expiryPolicy = expiryPolicyFactory.create();
}
- for (final CacheEntryListenerConfiguration<K, V> listener : config.getCacheEntryListenerConfigurations()) {
+ 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", ".");
- 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()
- );
- } catch (final Exception e) {
+ 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());
+ }
+ catch (final Exception e)
+ {
throw new IllegalArgumentException(e);
}
- if (config.isManagementEnabled()) {
+ if (config.isManagementEnabled())
+ {
JMXs.register(cacheConfigObjectName, new JCSCacheMXBean<K, V>(this));
}
- if (config.isStatisticsEnabled()) {
+ if (config.isStatisticsEnabled())
+ {
JMXs.register(cacheStatsObjectName, new JCSCacheStatisticsMXBean(statistics));
}
}
- private void assertNotClosed() {
- if (isClosed()) {
+ private void assertNotClosed()
+ {
+ if (isClosed())
+ {
throw new IllegalStateException("cache closed");
}
}
@Override
- public V get(final K key) {
+ public V get(final K key)
+ {
assertNotClosed();
assertNotNull(key, "key");
return doGetControllingExpiry(key, true, false, false, true);
}
- private V doLoad(final K key, final boolean update, final boolean propagateLoadException) {
+ private V doLoad(final K key, final boolean update, final boolean propagateLoadException)
+ {
V v = null;
- try {
+ try
+ {
v = loader.load(key);
- } catch (final CacheLoaderException e) {
- if (propagateLoadException) {
+ }
+ catch (final CacheLoaderException e)
+ {
+ if (propagateLoadException)
+ {
throw e;
}
}
- if (v != null) {
- try {
+ if (v != null)
+ {
+ try
+ {
final Duration duration = update ? expiryPolicy.getExpiryForUpdate() : expiryPolicy.getExpiryForCreation();
- if (duration == null || !duration.isZero()) {
+ if (duration == null || !duration.isZero())
+ {
delegate.put(key, new JCSElement<V>(v, duration));
}
- } catch (final CacheException e) {
+ }
+ catch (final CacheException e)
+ {
throw new IllegalStateException(e);
}
}
return v;
}
- private void touch(final K key, final JCSElement<V> elt) {
- try {
+ private void touch(final K key, final JCSElement<V> elt)
+ {
+ try
+ {
delegate.put(key, elt);
- } catch (final CacheException e) {
+ }
+ catch (final CacheException e)
+ {
// no-op
}
}
@Override
- public Map<K, V> getAll(final Set<? extends K> keys) {
+ public Map<K, V> getAll(final Set<? extends K> keys)
+ {
assertNotClosed();
- for (final K k : keys) {
- assertNotNull(k , "key");
+ for (final K k : keys)
+ {
+ assertNotNull(k, "key");
}
final Set<K> names = (Set<K>) keys;
final Map<K, V> result = new HashMap<K, V>();
- for (final Map.Entry<K, ICacheElement<K, JCSElement<V>>> k : delegate.getCacheElements(names).entrySet()) {
+ for (final Map.Entry<K, ICacheElement<K, JCSElement<V>>> k : delegate.getCacheElements(names).entrySet())
+ {
final K key = k.getKey();
assertNotNull(key, "key");
final JCSElement<V> elt = k.getValue() != null ? k.getValue().getVal() : null;
V val = elt != null ? elt.getElement() : null;
- if (val == null && config.isReadThrough()) {
+ if (val == null && config.isReadThrough())
+ {
val = doLoad(key, false, false);
- if (val != null) {
+ if (val != null)
+ {
result.put(key, val);
}
- } else if (elt != null) {
+ }
+ else if (elt != null)
+ {
elt.update(expiryPolicy.getExpiryForAccess());
touch(key, elt);
}
result.put(key, val);
}
- if (config.isReadThrough() && result.size() != keys.size()) {
- for (final K k : keys) {
- if (!result.containsKey(k)) {
+ if (config.isReadThrough() && result.size() != keys.size())
+ {
+ for (final K k : keys)
+ {
+ if (!result.containsKey(k))
+ {
final V v = doLoad(k, false, false);
- if (v != null) {
+ if (v != null)
+ {
result.put(k, v);
}
}
@@ -205,14 +247,16 @@ public class JCSCache<K extends Serializ
}
@Override
- public boolean containsKey(final K key) {
+ public boolean containsKey(final K key)
+ {
assertNotClosed();
assertNotNull(key, "key");
return delegate.get(key) != null;
}
@Override
- public void put(final K key, final V rawValue) {
+ public void put(final K key, final V rawValue)
+ {
assertNotClosed();
assertNotNull(key, "key");
assertNotNull(rawValue, "value");
@@ -220,70 +264,92 @@ public class JCSCache<K extends Serializ
final boolean statisticsEnabled = config.isStatisticsEnabled();
final long start = statisticsEnabled ? Times.now() : 0;
- try {
+ 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());
- if (element.isExpired()) {
- if (!created) {
+ final JCSElement<V> element = new JCSElement<V>(value, created ? expiryPolicy.getExpiryForCreation()
+ : expiryPolicy.getExpiryForUpdate());
+ if (element.isExpired())
+ {
+ if (!created)
+ {
delegate.remove(key);
}
- } else {
+ }
+ else
+ {
writer.write(new JCSEntry<K, V>(key, value));
delegate.put(storeByValue ? copy(key) : key, element);
- for (final JCSListener<K, V> listener : listeners.values()) {
- if (created) {
- 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)));
+ for (final JCSListener<K, V> listener : listeners.values())
+ {
+ if (created)
+ {
+ 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)));
}
}
- if (statisticsEnabled) {
+ if (statisticsEnabled)
+ {
statistics.increasePuts(1);
statistics.addPutTime(System.currentTimeMillis() - start);
}
}
- } catch (final CacheException e) {
+ }
+ catch (final CacheException e)
+ {
throw new IllegalStateException(e);
}
}
- private <T extends Serializable> T copy(final T value) {
- try {
+ private <T extends Serializable> T copy(final T value)
+ {
+ try
+ {
return serializer.deSerialize(serializer.serialize(value));
- } catch (final Exception ioe) {
+ }
+ catch (final Exception ioe)
+ {
throw new IllegalStateException(ioe.getMessage(), ioe);
}
}
@Override
- public V getAndPut(final K key, final V value) {
+ public V getAndPut(final K key, final V value)
+ {
final V v = doGetControllingExpiry(key, false, false, true, false);
put(key, value);
return v;
}
@Override
- public void putAll(final Map<? extends K, ? extends V> map) {
+ public void putAll(final Map<? extends K, ? extends V> map)
+ {
assertNotClosed();
final TempStateCacheView<K, V> view = new TempStateCacheView<K, V>(this);
- for (final Map.Entry<? extends K, ? extends V> e : map.entrySet()) {
+ for (final Map.Entry<? extends K, ? extends V> e : map.entrySet())
+ {
view.put(e.getKey(), e.getValue());
}
view.merge();
}
@Override
- public boolean putIfAbsent(final K key, final V value) {
- if (!containsKey(key)) {
+ public boolean putIfAbsent(final K key, final V value)
+ {
+ if (!containsKey(key))
+ {
put(key, value);
return true;
}
@@ -291,7 +357,8 @@ public class JCSCache<K extends Serializ
}
@Override
- public boolean remove(final K key) {
+ public boolean remove(final K key)
+ {
assertNotClosed();
assertNotNull(key, "key");
@@ -302,14 +369,17 @@ public class JCSCache<K extends Serializ
final V value = v != null && v.getElement() != null ? v.getElement() : null;
writer.delete(key);
boolean remove = delegate.getCacheControl().remove(key);
- if (v != null && v.isExpired()) {
+ if (v != null && v.isExpired())
+ {
remove = false;
}
- 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)));
+ 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)));
}
- if (remove && statisticsEnabled) {
+ if (remove && statisticsEnabled)
+ {
statistics.increaseRemovals(1);
statistics.addRemoveTime(Times.now() - start);
}
@@ -317,14 +387,16 @@ public class JCSCache<K extends Serializ
}
@Override
- public boolean remove(final K key, final V oldValue) {
+ public boolean remove(final K key, final V oldValue)
+ {
assertNotClosed();
assertNotNull(key, "key");
assertNotNull(oldValue, "oldValue");
final V v = doGetControllingExpiry(key, false, false, false, false);
- final boolean found = v != null;
- if (found) {
- if (v.equals(oldValue)) {
+ if (v != null)
+ {
+ if (v.equals(oldValue))
+ {
remove(key);
return true;
}
@@ -334,97 +406,126 @@ public class JCSCache<K extends Serializ
}
@Override
- public V getAndRemove(final K key) {
+ public V getAndRemove(final K key)
+ {
final V v = doGetControllingExpiry(key, false, false, true, false);
remove(key);
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;
- if (v == null && (config.isReadThrough() || forceDoLoad)) {
- if (!skipLoad) {
+ V v = elt != null ? elt.getElement() : null;
+ if (v == null && (config.isReadThrough() || forceDoLoad))
+ {
+ if (!skipLoad)
+ {
v = doLoad(key, false, propagateLoadException);
}
- } else if (statisticsEnabled) {
- if (v != null) {
+ }
+ else if (statisticsEnabled)
+ {
+ if (v != null)
+ {
statistics.increaseHits(1);
- } else {
+ }
+ else
+ {
statistics.increaseMisses(1);
}
}
- if (updateAcess && elt != null) {
+ if (updateAcess && elt != null)
+ {
elt.update(expiryPolicy.getExpiryForAccess());
- if (elt.isExpired()) {
+ if (elt.isExpired())
+ {
delegate.getCacheControl().remove(key);
- } else {
+ }
+ else
+ {
touch(key, elt);
}
}
- if (v != null) {
+ if (v != null)
+ {
statistics.addGetTime(Times.now() - getStart);
}
return v;
}
@Override
- public boolean replace(final K key, final V oldValue, final V newValue) {
+ public boolean replace(final K key, final V oldValue, final V newValue)
+ {
assertNotClosed();
assertNotNull(key, "key");
assertNotNull(oldValue, "oldValue");
assertNotNull(newValue, "newValue");
final boolean statisticsEnabled = config.isStatisticsEnabled();
final JCSElement<V> elt = delegate.get(key);
- if (elt != null) {
+ if (elt != null)
+ {
V value = elt.getElement();
- if (elt.isExpired()) {
+ if (elt.isExpired())
+ {
value = null;
}
- if (value != null && statisticsEnabled) {
+ if (value != null && statisticsEnabled)
+ {
statistics.increaseHits(1);
}
- if (value == null && config.isReadThrough()) {
+ if (value == null && config.isReadThrough())
+ {
value = doLoad(key, false, false);
}
- if (value != null && value.equals(oldValue)) {
+ if (value != null && value.equals(oldValue))
+ {
put(key, newValue);
return true;
- } else if (value != null) {
+ }
+ else if (value != null)
+ {
elt.update(expiryPolicy.getExpiryForAccess());
touch(key, elt);
}
- } else if (statisticsEnabled) {
+ }
+ else if (statisticsEnabled)
+ {
statistics.increaseMisses(1);
}
return false;
}
@Override
- public boolean replace(final K key, final V value) {
+ public boolean replace(final K key, final V value)
+ {
assertNotClosed();
assertNotNull(key, "key");
assertNotNull(value, "value");
boolean statisticsEnabled = config.isStatisticsEnabled();
- if (containsKey(key)) {
- if (statisticsEnabled) {
+ if (containsKey(key))
+ {
+ if (statisticsEnabled)
+ {
statistics.increaseHits(1);
}
put(key, value);
return true;
- } else if (statisticsEnabled) {
+ }
+ else if (statisticsEnabled)
+ {
statistics.increaseMisses(1);
}
return false;
}
@Override
- public V getAndReplace(final K key, final V value) {
+ public V getAndReplace(final K key, final V value)
+ {
assertNotClosed();
assertNotNull(key, "key");
assertNotNull(value, "value");
@@ -432,145 +533,192 @@ public class JCSCache<K extends Serializ
final boolean statisticsEnabled = config.isStatisticsEnabled();
final JCSElement<V> elt = delegate.get(key);
- if (elt != null) {
+ if (elt != null)
+ {
V oldValue = elt.getElement();
- if (oldValue == null && config.isReadThrough()) {
+ if (oldValue == null && config.isReadThrough())
+ {
oldValue = doLoad(key, false, false);
- } else if (statisticsEnabled) {
+ }
+ else if (statisticsEnabled)
+ {
statistics.increaseHits(1);
}
put(key, value);
return oldValue;
- } else if (statisticsEnabled) {
+ }
+ else if (statisticsEnabled)
+ {
statistics.increaseMisses(1);
}
return null;
}
@Override
- public void removeAll(final Set<? extends K> keys) {
+ public void removeAll(final Set<? extends K> keys)
+ {
assertNotClosed();
assertNotNull(keys, "keys");
- for (final K k : keys) {
+ for (final K k : keys)
+ {
remove(k);
}
}
@Override
- public void removeAll() {
+ public void removeAll()
+ {
removeAll(delegate.getCacheControl().getKeySet());
}
@Override
- public void clear() {
+ public void clear()
+ {
assertNotClosed();
- try {
+ try
+ {
delegate.clear();
- } catch (final CacheException e) {
+ }
+ catch (final CacheException e)
+ {
throw new IllegalStateException(e);
}
}
@Override
- public <C2 extends Configuration<K, V>> C2 getConfiguration(final Class<C2> clazz) {
+ public <C2 extends Configuration<K, V>> C2 getConfiguration(final Class<C2> clazz)
+ {
assertNotClosed();
return clazz.cast(config);
}
@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");
- for (final K k : keys) {
+ for (final K k : keys)
+ {
assertNotNull(k, "a key");
}
- pool.submit(new Runnable() {
+ pool.submit(new Runnable()
+ {
@Override
- public void run() {
+ public void run()
+ {
doLoadAll(keys, replaceExistingValues, completionListener);
}
});
}
- private void doLoadAll(final Set<? extends K> keys, final boolean replaceExistingValues,
- final CompletionListener completionListener) {
- try {
- for (final K k : keys) {
- if (replaceExistingValues) {
+ private void doLoadAll(final Set<? extends K> keys, final boolean replaceExistingValues, final CompletionListener completionListener)
+ {
+ try
+ {
+ for (final K k : keys)
+ {
+ if (replaceExistingValues)
+ {
doLoad(k, containsKey(k), completionListener != null);
continue;
- } else if (containsKey(k)) {
+ }
+ else if (containsKey(k))
+ {
continue;
}
doGetControllingExpiry(k, true, true, false, completionListener != null);
}
- } catch (final RuntimeException e) {
- if (completionListener != null) {
+ }
+ catch (final RuntimeException e)
+ {
+ if (completionListener != null)
+ {
completionListener.onException(e);
return;
}
}
- if (completionListener != null) {
+ if (completionListener != null)
+ {
completionListener.onCompletion();
}
}
@Override
- public <T> T invoke(final K key, final EntryProcessor<K, V, T> entryProcessor, final Object... arguments) throws EntryProcessorException {
+ public <T> T invoke(final K key, final EntryProcessor<K, V, T> entryProcessor, final Object... arguments) throws EntryProcessorException
+ {
final TempStateCacheView<K, V> view = new TempStateCacheView<K, V>(this);
final T t = doInvoke(view, key, entryProcessor, arguments);
view.merge();
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");
assertNotNull(key, "key");
- try {
- if (config.isStatisticsEnabled()) {
- if (containsKey(key)) {
+ try
+ {
+ if (config.isStatisticsEnabled())
+ {
+ if (containsKey(key))
+ {
statistics.increaseHits(1);
- } else {
+ }
+ else
+ {
statistics.increaseMisses(1);
}
}
return entryProcessor.process(new JCSMutableEntry<K, V>(view, key), arguments);
- } catch (final Exception ex) {
+ }
+ catch (final Exception ex)
+ {
return throwEntryProcessorException(ex);
}
}
- private static <T> T throwEntryProcessorException(final Exception ex) {
- if (EntryProcessorException.class.isInstance(ex)) {
+ private static <T> T throwEntryProcessorException(final Exception ex)
+ {
+ if (EntryProcessorException.class.isInstance(ex))
+ {
throw EntryProcessorException.class.cast(ex);
}
throw new EntryProcessorException(ex);
}
@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");
final Map<K, EntryProcessorResult<T>> results = new HashMap<K, EntryProcessorResult<T>>();
- for (final K k : keys) {
- try {
+ for (final K k : keys)
+ {
+ try
+ {
final T invoke = invoke(k, entryProcessor, arguments);
- if (invoke != null) {
- results.put(k, new EntryProcessorResult<T>() {
+ if (invoke != null)
+ {
+ results.put(k, new EntryProcessorResult<T>()
+ {
@Override
- public T get() throws EntryProcessorException {
+ public T get() throws EntryProcessorException
+ {
return invoke;
}
});
}
- } catch (final Exception e) {
- results.put(k, new EntryProcessorResult<T>() {
+ }
+ catch (final Exception e)
+ {
+ results.put(k, new EntryProcessorResult<T>()
+ {
@Override
- public T get() throws EntryProcessorException {
+ public T get() throws EntryProcessorException
+ {
return throwEntryProcessorException(e);
}
});
@@ -580,9 +728,11 @@ public class JCSCache<K extends Serializ
}
@Override
- public void registerCacheEntryListener(final CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) {
+ 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));
@@ -590,33 +740,40 @@ 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);
}
@Override
- public Iterator<Entry<K, V>> iterator() {
+ public Iterator<Entry<K, V>> iterator()
+ {
assertNotClosed();
final Iterator<K> keys = delegate.getCacheControl().getKeySet().iterator();
- return new Iterator<Entry<K, V>>() {
+ return new Iterator<Entry<K, V>>()
+ {
private K lastKey = null;
@Override
- public boolean hasNext() {
+ public boolean hasNext()
+ {
return keys.hasNext();
}
@Override
- public Entry<K, V> next() {
+ public Entry<K, V> next()
+ {
lastKey = keys.next();
return new JCSEntry<K, V>(lastKey, get(lastKey));
}
@Override
- public void remove() {
- if (isClosed() || lastKey == null) {
+ public void remove()
+ {
+ if (isClosed() || lastKey == null)
+ {
throw new IllegalStateException(isClosed() ? "cache closed" : "call next() before remove()");
}
JCSCache.this.remove(lastKey);
@@ -625,20 +782,24 @@ public class JCSCache<K extends Serializ
}
@Override
- public String getName() {
+ public String getName()
+ {
assertNotClosed();
return delegate.getCacheControl().getCacheName();
}
@Override
- public CacheManager getCacheManager() {
+ public CacheManager getCacheManager()
+ {
assertNotClosed();
return manager;
}
@Override
- public synchronized void close() {
- if (isClosed()) {
+ public synchronized void close()
+ {
+ if (isClosed())
+ {
return;
}
@@ -651,40 +812,48 @@ public class JCSCache<K extends Serializ
}
@Override
- public boolean isClosed() {
+ public boolean isClosed()
+ {
return closed;
}
@Override
- public <T> T unwrap(final Class<T> clazz) {
+ public <T> T unwrap(final Class<T> clazz)
+ {
assertNotClosed();
- if (clazz.isInstance(this)) {
+ if (clazz.isInstance(this))
+ {
return clazz.cast(this);
}
throw new IllegalArgumentException(clazz.getName() + " not supported in unwrap");
}
- public Statistics getStatistics() {
+ public Statistics getStatistics()
+ {
return statistics;
}
- public void enableManagement() {
+ public void enableManagement()
+ {
config.managementEnabled();
JMXs.register(cacheConfigObjectName, new JCSCacheMXBean<K, V>(this));
}
- public void disableManagement() {
+ public void disableManagement()
+ {
config.managementDisabled();
JMXs.unregister(cacheConfigObjectName);
}
- public void enableStatistics() {
+ public void enableStatistics()
+ {
config.statisticsEnabled();
statistics.setActive(true);
JMXs.register(cacheStatsObjectName, new JCSCacheStatisticsMXBean(statistics));
}
- public void disableStatistics() {
+ public void disableStatistics()
+ {
config.statisticsDisabled();
statistics.setActive(false);
JMXs.unregister(cacheStatsObjectName);
Modified: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCacheEntryEvent.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCacheEntryEvent.java?rev=1591068&r1=1591067&r2=1591068&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCacheEntryEvent.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCacheEntryEvent.java Tue Apr 29 19:45:14 2014
@@ -4,12 +4,17 @@ import javax.cache.Cache;
import javax.cache.event.CacheEntryEvent;
import javax.cache.event.EventType;
-public class JCSCacheEntryEvent<K, V> extends CacheEntryEvent<K, V> {
+public class JCSCacheEntryEvent<K, V> extends CacheEntryEvent<K, V>
+{
+ /** Serial version */
+ private static final long serialVersionUID = 4761272981003897488L;
+
private final V old;
private final K key;
private final V value;
- public JCSCacheEntryEvent(final Cache source, final EventType eventType, final V old, final K key, final V value) {
+ public JCSCacheEntryEvent(final Cache<K, V> source, final EventType eventType, final V old, final K key, final V value)
+ {
super(source, eventType);
this.old = old;
this.key = key;
@@ -17,28 +22,34 @@ public class JCSCacheEntryEvent<K, V> ex
}
@Override
- public V getOldValue() {
+ public V getOldValue()
+ {
return old;
}
@Override
- public boolean isOldValueAvailable() {
+ public boolean isOldValueAvailable()
+ {
return old != null;
}
@Override
- public K getKey() {
+ public K getKey()
+ {
return key;
}
@Override
- public V getValue() {
+ public V getValue()
+ {
return value;
}
@Override
- public <T> T unwrap(final Class<T> clazz) {
- if (clazz.isInstance(this)) {
+ public <T> T unwrap(final Class<T> clazz)
+ {
+ if (clazz.isInstance(this))
+ {
return clazz.cast(this);
}
throw new IllegalArgumentException(clazz.getName() + " not supported in unwrap");
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=1591068&r1=1591067&r2=1591068&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 19:45:14 2014
@@ -1,12 +1,7 @@
package org.apache.commons.jcs.jcache;
-import org.apache.commons.jcs.engine.control.CompositeCacheManager;
-import org.apache.commons.jcs.jcache.proxy.ClassLoaderAwareHandler;
+import static org.apache.commons.jcs.jcache.Asserts.assertNotNull;
-import javax.cache.Cache;
-import javax.cache.CacheManager;
-import javax.cache.configuration.Configuration;
-import javax.cache.spi.CachingProvider;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Proxy;
@@ -15,9 +10,16 @@ import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import static org.apache.commons.jcs.jcache.Asserts.assertNotNull;
+import javax.cache.Cache;
+import javax.cache.CacheManager;
+import javax.cache.configuration.Configuration;
+import javax.cache.spi.CachingProvider;
-public class JCSCachingManager implements CacheManager {
+import org.apache.commons.jcs.engine.control.CompositeCacheManager;
+import org.apache.commons.jcs.jcache.proxy.ClassLoaderAwareHandler;
+
+public class JCSCachingManager implements CacheManager
+{
private final CachingProvider provider;
private final URI uri;
private final ClassLoader loader;
@@ -26,8 +28,8 @@ public class JCSCachingManager implement
private final CompositeCacheManager instance;
private volatile boolean closed = false;
- public JCSCachingManager(final CachingProvider provider, final URI uri,
- final ClassLoader loader, final Properties properties) {
+ public JCSCachingManager(final CachingProvider provider, final URI uri, final ClassLoader loader, final Properties properties)
+ {
this.provider = provider;
this.uri = uri;
this.loader = loader;
@@ -36,65 +38,82 @@ public class JCSCachingManager implement
instance = CompositeCacheManager.getUnconfiguredInstance();
final Properties props = new Properties();
InputStream inStream = null;
- try {
- if (JCSCachingProvider.DEFAULT_URI == uri || uri.toURL().getProtocol().equals("jcs")) {
+ try
+ {
+ if (JCSCachingProvider.DEFAULT_URI == uri || uri.toURL().getProtocol().equals("jcs"))
+ {
inStream = loader.getResourceAsStream(uri.getPath());
- } else {
+ }
+ else
+ {
inStream = uri.toURL().openStream();
}
props.load(inStream);
- } catch (final IOException e) {
+ }
+ catch (final IOException e)
+ {
throw new IllegalArgumentException(e);
- } finally {
- if (inStream != null) {
- try {
+ }
+ finally
+ {
+ if (inStream != null)
+ {
+ try
+ {
inStream.close();
- } catch (final IOException e) {
+ }
+ catch (final IOException e)
+ {
// no-op
}
}
}
- if (properties != null) {
+ if (properties != null)
+ {
props.putAll(properties);
}
instance.configure(props);
}
- private void assertNotClosed() {
- if (isClosed()) {
+ private void assertNotClosed()
+ {
+ if (isClosed())
+ {
throw new IllegalStateException("cache manager closed");
}
}
- @Override // TODO: use configuration + handle not serializable key/values
- public <K, V, C extends Configuration<K, V>> Cache<K, V> createCache(final String cacheName, final C configuration) throws IllegalArgumentException {
+ @Override
+ // TODO: use configuration + handle not serializable key/values
+ public <K, V, C extends Configuration<K, V>> Cache<K, V> createCache(final String cacheName, final C configuration)
+ throws IllegalArgumentException
+ {
assertNotClosed();
assertNotNull(cacheName, "cacheName");
- if (!caches.containsKey(cacheName)) {
+ 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, configuration.getKeyType(), configuration
+ .getValueType()), instance.getCache(cacheName), instance.getConfigurationProperties()), Cache.class);
caches.putIfAbsent(cacheName, cache);
- } else {
+ }
+ else
+ {
throw new javax.cache.CacheException("cache " + cacheName + " already exists");
}
return getCache(cacheName, configuration.getKeyType(), configuration.getValueType());
}
@Override
- public void destroyCache(final String cacheName) {
+ public void destroyCache(final String cacheName)
+ {
assertNotClosed();
assertNotNull(cacheName, "cacheName");
final Cache<?, ?> cache = caches.remove(cacheName);
instance.freeCache(cacheName, true);
- if (cache != null && !cache.isClosed()) {
+ if (cache != null && !cache.isClosed())
+ {
cache.clear();
cache.close();
instance.freeCache(cacheName, true);
@@ -102,122 +121,153 @@ public class JCSCachingManager implement
}
@Override
- public void enableManagement(final String cacheName, final boolean enabled) {
+ public void enableManagement(final String cacheName, final boolean enabled)
+ {
assertNotClosed();
assertNotNull(cacheName, "cacheName");
final JCSCache<?, ?, ?> cache = getJCSCache(cacheName);
- if (cache != null) {
- if (enabled) {
+ if (cache != null)
+ {
+ if (enabled)
+ {
cache.enableManagement();
- } else {
+ }
+ else
+ {
cache.disableManagement();
}
}
}
- private JCSCache<?, ?, ?> getJCSCache(final String cacheName) {
+ private JCSCache<?, ?, ?> getJCSCache(final String cacheName)
+ {
final Cache<?, ?> cache = caches.get(cacheName);
return JCSCache.class.cast(ClassLoaderAwareHandler.class.cast(Proxy.getInvocationHandler(cache)).getDelegate());
}
@Override
- public void enableStatistics(final String cacheName, final boolean enabled) {
+ public void enableStatistics(final String cacheName, final boolean enabled)
+ {
assertNotClosed();
assertNotNull(cacheName, "cacheName");
final JCSCache<?, ?, ?> cache = getJCSCache(cacheName);
- if (cache != null) {
- if (enabled) {
+ if (cache != null)
+ {
+ if (enabled)
+ {
cache.enableStatistics();
- } else {
+ }
+ else
+ {
cache.disableStatistics();
}
}
}
@Override
- public synchronized void close() {
- if (isClosed()) {
+ public synchronized void close()
+ {
+ if (isClosed())
+ {
return;
}
assertNotClosed();
- for (final Cache<?, ?> c : caches.values()) {
+ for (final Cache<?, ?> c : caches.values())
+ {
c.close();
}
caches.clear();
closed = true;
- if (JCSCachingProvider.class.isInstance(provider)) {
+ if (JCSCachingProvider.class.isInstance(provider))
+ {
JCSCachingProvider.class.cast(provider).remove(this);
}
}
@Override
- public <T> T unwrap(final Class<T> clazz) {
- if (clazz.isInstance(this)) {
+ public <T> T unwrap(final Class<T> clazz)
+ {
+ if (clazz.isInstance(this))
+ {
return clazz.cast(this);
}
throw new IllegalArgumentException(clazz.getName() + " not supported in unwrap");
}
@Override
- public boolean isClosed() {
+ public boolean isClosed()
+ {
return closed;
}
@Override
- public <K, V> Cache<K, V> getCache(final String cacheName) {
+ public <K, V> Cache<K, V> getCache(final String cacheName)
+ {
assertNotClosed();
assertNotNull(cacheName, "cacheName");
return (Cache<K, V>) doGetCache(cacheName, Object.class, Object.class);
}
@Override
- public Iterable<String> getCacheNames() {
+ public Iterable<String> getCacheNames()
+ {
return new ImmutableIterable<String>(caches.keySet());
}
@Override
- public <K, V> Cache<K, V> getCache(final String cacheName, final Class<K> keyType, final Class<V> valueType) {
+ public <K, V> Cache<K, V> getCache(final String cacheName, final Class<K> keyType, final Class<V> valueType)
+ {
assertNotClosed();
assertNotNull(cacheName, "cacheName");
- try {
+ try
+ {
return doGetCache(cacheName, keyType, valueType);
- } catch (final IllegalArgumentException iae) {
+ }
+ catch (final IllegalArgumentException iae)
+ {
throw new ClassCastException(iae.getMessage());
}
}
- private <K, V> Cache<K, V> doGetCache(final String cacheName, final Class<K> keyType, final Class<V> valueType) {
+ private <K, V> Cache<K, V> doGetCache(final String cacheName, final Class<K> keyType, final Class<V> valueType)
+ {
final Cache<K, V> cache = (Cache<K, V>) caches.get(cacheName);
- if (cache == null) {
+ if (cache == null)
+ {
return null;
}
final Configuration<K, V> config = cache.getConfiguration(Configuration.class);
- if (!config.getKeyType().isAssignableFrom(keyType) || !config.getValueType().isAssignableFrom(valueType)) {
- throw new IllegalArgumentException("this cache is <" + config.getKeyType().getName() + ", " + config.getValueType().getName() + "> "
- + " and not <" + keyType.getName() + ", " + valueType.getName() + ">");
+ if (!config.getKeyType().isAssignableFrom(keyType) || !config.getValueType().isAssignableFrom(valueType))
+ {
+ throw new IllegalArgumentException("this cache is <" + config.getKeyType().getName() + ", " + config.getValueType().getName()
+ + "> " + " and not <" + keyType.getName() + ", " + valueType.getName() + ">");
}
return cache;
}
@Override
- public CachingProvider getCachingProvider() {
+ public CachingProvider getCachingProvider()
+ {
return provider;
}
@Override
- public URI getURI() {
+ public URI getURI()
+ {
return uri;
}
@Override
- public ClassLoader getClassLoader() {
+ public ClassLoader getClassLoader()
+ {
return loader;
}
@Override
- public Properties getProperties() {
+ public Properties getProperties()
+ {
return properties;
}
}
Modified: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCachingProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCachingProvider.java?rev=1591068&r1=1591067&r2=1591068&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCachingProvider.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCachingProvider.java Tue Apr 29 19:45:14 2014
@@ -9,31 +9,36 @@ import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-public class JCSCachingProvider implements CachingProvider {
+public class JCSCachingProvider implements CachingProvider
+{
public static final URI DEFAULT_URI = URI.create("jcs://jcache.ccf");
- private final ConcurrentMap<ClassLoader, ConcurrentMap<URI, CacheManager>> cacheManagersByLoader =
- new ConcurrentHashMap<ClassLoader, ConcurrentMap<URI, CacheManager>>();
+ private final ConcurrentMap<ClassLoader, ConcurrentMap<URI, CacheManager>> cacheManagersByLoader = new ConcurrentHashMap<ClassLoader, ConcurrentMap<URI, CacheManager>>();
@Override
- public CacheManager getCacheManager(final URI inUri, final ClassLoader inClassLoader, final Properties properties) {
+ public CacheManager getCacheManager(final URI inUri, final ClassLoader inClassLoader, final Properties properties)
+ {
final URI uri = inUri != null ? inUri : getDefaultURI();
final ClassLoader classLoader = inClassLoader != null ? inClassLoader : getDefaultClassLoader();
ConcurrentMap<URI, CacheManager> managers = cacheManagersByLoader.get(classLoader);
- if (managers == null) {
+ if (managers == null)
+ {
managers = new ConcurrentHashMap<URI, CacheManager>();
final ConcurrentMap<URI, CacheManager> existingManagers = cacheManagersByLoader.putIfAbsent(classLoader, managers);
- if (existingManagers != null) {
+ if (existingManagers != null)
+ {
managers = existingManagers;
}
}
CacheManager mgr = managers.get(uri);
- if (mgr == null) {
+ if (mgr == null)
+ {
mgr = new JCSCachingManager(this, uri, classLoader, properties);
final CacheManager existing = managers.putIfAbsent(uri, mgr);
- if (existing != null) {
+ if (existing != null)
+ {
mgr = existing;
}
}
@@ -42,14 +47,18 @@ public class JCSCachingProvider implemen
}
@Override
- public URI getDefaultURI() {
+ public URI getDefaultURI()
+ {
return DEFAULT_URI;
}
@Override
- public void close() {
- for (final Map<URI, CacheManager> v : cacheManagersByLoader.values()) {
- for (final CacheManager m : v.values()) {
+ public void close()
+ {
+ for (final Map<URI, CacheManager> v : cacheManagersByLoader.values())
+ {
+ for (final CacheManager m : v.values())
+ {
m.close();
}
v.clear();
@@ -58,10 +67,13 @@ public class JCSCachingProvider implemen
}
@Override
- public void close(final ClassLoader classLoader) {
+ public void close(final ClassLoader classLoader)
+ {
final Map<URI, CacheManager> cacheManagers = cacheManagersByLoader.remove(classLoader);
- if (cacheManagers != null) {
- for (final CacheManager mgr : cacheManagers.values()) {
+ if (cacheManagers != null)
+ {
+ for (final CacheManager mgr : cacheManagers.values())
+ {
mgr.close();
}
cacheManagers.clear();
@@ -69,47 +81,58 @@ public class JCSCachingProvider implemen
}
@Override
- public void close(final URI uri, final ClassLoader classLoader) {
+ public void close(final URI uri, final ClassLoader classLoader)
+ {
final Map<URI, CacheManager> cacheManagers = cacheManagersByLoader.remove(classLoader);
- if (cacheManagers != null) {
+ if (cacheManagers != null)
+ {
final CacheManager mgr = cacheManagers.remove(uri);
- if (mgr != null) {
+ if (mgr != null)
+ {
mgr.close();
}
}
}
@Override
- public CacheManager getCacheManager(final URI uri, final ClassLoader classLoader) {
+ public CacheManager getCacheManager(final URI uri, final ClassLoader classLoader)
+ {
return getCacheManager(uri, classLoader, getDefaultProperties());
}
@Override
- public CacheManager getCacheManager() {
+ public CacheManager getCacheManager()
+ {
return getCacheManager(getDefaultURI(), getDefaultClassLoader());
}
@Override
- public boolean isSupported(final OptionalFeature optionalFeature) {
+ public boolean isSupported(final OptionalFeature optionalFeature)
+ {
return false;
}
@Override
- public ClassLoader getDefaultClassLoader() {
+ public ClassLoader getDefaultClassLoader()
+ {
return JCSCachingProvider.class.getClassLoader();
}
@Override
- public Properties getDefaultProperties() {
+ public Properties getDefaultProperties()
+ {
return new Properties();
}
- void remove(final CacheManager mgr) {
+ void remove(final CacheManager mgr)
+ {
final ClassLoader classLoader = mgr.getClassLoader();
final Map<URI, CacheManager> mgrs = cacheManagersByLoader.get(classLoader);
- if (mgrs != null) {
+ if (mgrs != null)
+ {
mgrs.remove(mgr.getURI());
- if (mgrs.isEmpty()) {
+ if (mgrs.isEmpty())
+ {
cacheManagersByLoader.remove(classLoader);
}
}
Modified: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSConfiguration.java?rev=1591068&r1=1591067&r2=1591068&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSConfiguration.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSConfiguration.java Tue Apr 29 19:45:14 2014
@@ -15,7 +15,6 @@
*/
package org.apache.commons.jcs.jcache;
-
import javax.cache.configuration.CacheEntryListenerConfiguration;
import javax.cache.configuration.CompleteConfiguration;
import javax.cache.configuration.Configuration;
@@ -28,25 +27,28 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
-public class JCSConfiguration<K, V> implements CompleteConfiguration<K, V> {
+public class JCSConfiguration<K, V> implements CompleteConfiguration<K, V>
+{
private final Class<K> keyType;
private final Class<V> valueType;
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<CacheLoader<K, V>> cacheLoaderFactory;
+ private final Factory<CacheWriter<? super K, ? super V>> cacheWristerFactory;
private final Factory<ExpiryPolicy> expiryPolicyFactory;
private final Set<CacheEntryListenerConfiguration<K, V>> cacheEntryListenerConfigurations;
private volatile boolean statisticsEnabled;
private volatile boolean managementEnabled;
- public JCSConfiguration(final Configuration<K, V> configuration, final Class<K> keyType, final Class<V> valueType) {
+ public JCSConfiguration(final Configuration<K, V> configuration, final Class<K> keyType, final Class<V> valueType)
+ {
this.keyType = keyType;
this.valueType = valueType;
- if (configuration instanceof CompleteConfiguration) {
+ if (configuration instanceof CompleteConfiguration)
+ {
final CompleteConfiguration<K, V> cConfiguration = (CompleteConfiguration<K, V>) configuration;
storeByValue = configuration.isStoreByValue();
readThrough = cConfiguration.isReadThrough();
@@ -58,13 +60,18 @@ public class JCSConfiguration<K, V> impl
this.expiryPolicyFactory = cConfiguration.getExpiryPolicyFactory();
cacheEntryListenerConfigurations = new HashSet<CacheEntryListenerConfiguration<K, V>>();
- final Iterable<CacheEntryListenerConfiguration<K, V>> entryListenerConfigurations = cConfiguration.getCacheEntryListenerConfigurations();
- if (entryListenerConfigurations != null) {
- for (final CacheEntryListenerConfiguration<K, V> kvCacheEntryListenerConfiguration : entryListenerConfigurations) {
+ final Iterable<CacheEntryListenerConfiguration<K, V>> entryListenerConfigurations = cConfiguration
+ .getCacheEntryListenerConfigurations();
+ if (entryListenerConfigurations != null)
+ {
+ for (final CacheEntryListenerConfiguration<K, V> kvCacheEntryListenerConfiguration : entryListenerConfigurations)
+ {
cacheEntryListenerConfigurations.add(kvCacheEntryListenerConfiguration);
}
}
- } else {
+ }
+ else
+ {
expiryPolicyFactory = EternalExpiryPolicy.factoryOf();
storeByValue = true;
readThrough = false;
@@ -78,81 +85,98 @@ public class JCSConfiguration<K, V> impl
}
@Override
- public Class<K> getKeyType() {
- return keyType == null ? (Class<K>)Object.class : keyType;
+ public Class<K> getKeyType()
+ {
+ return keyType == null ? (Class<K>) Object.class : keyType;
}
@Override
- public Class<V> getValueType() {
- return valueType == null ? (Class<V>)Object.class : valueType;
+ public Class<V> getValueType()
+ {
+ return valueType == null ? (Class<V>) Object.class : valueType;
}
@Override
- public boolean isStoreByValue() {
+ public boolean isStoreByValue()
+ {
return storeByValue;
}
@Override
- public boolean isReadThrough() {
+ public boolean isReadThrough()
+ {
return readThrough;
}
@Override
- public boolean isWriteThrough() {
+ public boolean isWriteThrough()
+ {
return writeThrough;
}
@Override
- public boolean isStatisticsEnabled() {
+ public boolean isStatisticsEnabled()
+ {
return statisticsEnabled;
}
@Override
- public boolean isManagementEnabled() {
+ public boolean isManagementEnabled()
+ {
return managementEnabled;
}
@Override
- public Iterable<CacheEntryListenerConfiguration<K, V>> getCacheEntryListenerConfigurations() {
+ public Iterable<CacheEntryListenerConfiguration<K, V>> getCacheEntryListenerConfigurations()
+ {
return Collections.unmodifiableSet(cacheEntryListenerConfigurations);
}
@Override
- public Factory<CacheLoader<K, V>> getCacheLoaderFactory() {
+ public Factory<CacheLoader<K, V>> getCacheLoaderFactory()
+ {
return cacheLoaderFactory;
}
@Override
- public Factory<CacheWriter<? super K, ? super V>> getCacheWriterFactory() {
+ public Factory<CacheWriter<? super K, ? super V>> getCacheWriterFactory()
+ {
return cacheWristerFactory;
}
@Override
- public Factory<ExpiryPolicy> getExpiryPolicyFactory() {
+ public Factory<ExpiryPolicy> getExpiryPolicyFactory()
+ {
return expiryPolicyFactory;
}
- public synchronized void addListener(final CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) {
+ public synchronized void addListener(final CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration)
+ {
cacheEntryListenerConfigurations.add(cacheEntryListenerConfiguration);
}
- public synchronized void removeListener(final CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) {
+ public synchronized void removeListener(final CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration)
+ {
cacheEntryListenerConfigurations.remove(cacheEntryListenerConfiguration);
}
- public void statisticsEnabled() {
+ public void statisticsEnabled()
+ {
statisticsEnabled = true;
}
- public void managementEnabled() {
+ public void managementEnabled()
+ {
managementEnabled = true;
}
- public void statisticsDisabled() {
+ public void statisticsDisabled()
+ {
statisticsEnabled = false;
}
- public void managementDisabled() {
+ public void managementDisabled()
+ {
managementEnabled = false;
}
}
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=1591068&r1=1591067&r2=1591068&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 19:45:14 2014
@@ -1,31 +1,45 @@
package org.apache.commons.jcs.jcache;
-import javax.cache.expiry.Duration;
import java.io.Serializable;
-public class JCSElement<V> implements Serializable {
+import javax.cache.expiry.Duration;
+
+public class JCSElement<V> implements Serializable
+{
+ /** Serial version */
+ private static final long serialVersionUID = 6399046812336629074L;
+
private final V element;
private volatile long end;
- public JCSElement(final V element, final Duration duration) {
+ public JCSElement(final V element, final Duration duration)
+ {
this.element = element;
update(duration);
}
- public boolean isExpired() {
+ public boolean isExpired()
+ {
return end != -1 && (end == 0 || Times.now() > end);
}
- public V getElement() {
+ public V getElement()
+ {
return element;
}
- public void update(final Duration duration) {
- if (duration == null || duration.isEternal()) {
+ public void update(final Duration duration)
+ {
+ 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/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSEntry.java?rev=1591068&r1=1591067&r2=1591068&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSEntry.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSEntry.java Tue Apr 29 19:45:14 2014
@@ -2,28 +2,34 @@ package org.apache.commons.jcs.jcache;
import javax.cache.Cache;
-public class JCSEntry<K, V> implements Cache.Entry<K, V> {
+public class JCSEntry<K, V> implements Cache.Entry<K, V>
+{
private final K key;
private final V value;
- public JCSEntry(final K key, final V value) {
+ public JCSEntry(final K key, final V value)
+ {
this.key = key;
this.value = value;
}
@Override
- public K getKey() {
+ public K getKey()
+ {
return key;
}
@Override
- public V getValue() {
+ public V getValue()
+ {
return value;
}
@Override
- public <T> T unwrap(final Class<T> clazz) {
- if (clazz.isInstance(this)) {
+ public <T> T unwrap(final Class<T> clazz)
+ {
+ if (clazz.isInstance(this))
+ {
return clazz.cast(this);
}
throw new UnsupportedOperationException();
Modified: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSListener.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSListener.java?rev=1591068&r1=1591067&r2=1591068&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSListener.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSListener.java Tue Apr 29 19:45:14 2014
@@ -14,7 +14,8 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-public class JCSListener<K extends Serializable, V extends Serializable> {
+public class JCSListener<K extends Serializable, V extends Serializable>
+{
private final boolean oldValue;
private final boolean synchronous;
private final CacheEntryEventFilter<? super K, ? super V> filter;
@@ -24,14 +25,19 @@ public class JCSListener<K extends Seria
private final boolean update;
private final boolean create;
- public JCSListener(final CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) {
+ public JCSListener(final CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration)
+ {
oldValue = cacheEntryListenerConfiguration.isOldValueRequired();
synchronous = cacheEntryListenerConfiguration.isSynchronous();
- final Factory<CacheEntryEventFilter<? super K, ? super V>> filterFactory = cacheEntryListenerConfiguration.getCacheEntryEventFilterFactory();
- if (filterFactory == null) {
+ final Factory<CacheEntryEventFilter<? super K, ? super V>> filterFactory = cacheEntryListenerConfiguration
+ .getCacheEntryEventFilterFactory();
+ if (filterFactory == null)
+ {
filter = NoFilter.INSTANCE;
- } else {
+ }
+ else
+ {
filter = filterFactory.create();
}
@@ -42,46 +48,59 @@ public class JCSListener<K extends Seria
create = CacheEntryCreatedListener.class.isInstance(delegate);
}
- public void onRemoved(final List<CacheEntryEvent<? extends K, ? extends V>> events) throws CacheEntryListenerException {
- if (remove) {
+ public void onRemoved(final List<CacheEntryEvent<? extends K, ? extends V>> events) throws CacheEntryListenerException
+ {
+ if (remove)
+ {
CacheEntryRemovedListener.class.cast(delegate).onRemoved(filter(events));
}
}
-
- public void onExpired(final List<CacheEntryEvent<? extends K, ? extends V>> events) throws CacheEntryListenerException {
- if (expire) {
+ public void onExpired(final List<CacheEntryEvent<? extends K, ? extends V>> events) throws CacheEntryListenerException
+ {
+ if (expire)
+ {
CacheEntryExpiredListener.class.cast(delegate).onExpired(filter(events));
}
}
- public void onUpdated(final List<CacheEntryEvent<? extends K, ? extends V>> events) throws CacheEntryListenerException {
- if (update) {
+ public void onUpdated(final List<CacheEntryEvent<? extends K, ? extends V>> events) throws CacheEntryListenerException
+ {
+ if (update)
+ {
CacheEntryUpdatedListener.class.cast(delegate).onUpdated(filter(events));
}
}
- public void onCreated(final List<CacheEntryEvent<? extends K, ? extends V>> events) throws CacheEntryListenerException {
- if (create) {
+ public void onCreated(final List<CacheEntryEvent<? extends K, ? extends V>> events) throws CacheEntryListenerException
+ {
+ if (create)
+ {
CacheEntryCreatedListener.class.cast(delegate).onCreated(filter(events));
}
}
- private Iterable<CacheEntryEvent<? extends K, ? extends V>> filter(final List<CacheEntryEvent<? extends K, ? extends V>> events) {
- if (filter == NoFilter.INSTANCE) {
+ private Iterable<CacheEntryEvent<? extends K, ? extends V>> filter(final List<CacheEntryEvent<? extends K, ? extends V>> events)
+ {
+ if (filter == NoFilter.INSTANCE)
+ {
return events;
}
- final List<CacheEntryEvent<? extends K, ? extends V>> filtered = new ArrayList<CacheEntryEvent<? extends K, ? extends V>>(events.size());
- for (final CacheEntryEvent<? extends K, ? extends V> event : events) {
- if (filter.evaluate(event)) {
+ final List<CacheEntryEvent<? extends K, ? extends V>> filtered = new ArrayList<CacheEntryEvent<? extends K, ? extends V>>(
+ events.size());
+ for (final CacheEntryEvent<? extends K, ? extends V> event : events)
+ {
+ if (filter.evaluate(event))
+ {
filtered.add(event);
}
}
return filtered;
}
- public void close() {
+ public void close()
+ {
// no-op
}
}
Modified: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSMutableEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSMutableEntry.java?rev=1591068&r1=1591067&r2=1591068&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSMutableEntry.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSMutableEntry.java Tue Apr 29 19:45:14 2014
@@ -3,43 +3,52 @@ package org.apache.commons.jcs.jcache;
import javax.cache.Cache;
import javax.cache.processor.MutableEntry;
-public class JCSMutableEntry<K, V> implements MutableEntry<K, V> {
+public class JCSMutableEntry<K, V> implements MutableEntry<K, V>
+{
private final Cache<K, V> cache;
private final K key;
- public JCSMutableEntry(final Cache<K, V> cache, final K key) {
+ public JCSMutableEntry(final Cache<K, V> cache, final K key)
+ {
this.cache = cache;
this.key = key;
}
@Override
- public boolean exists() {
+ public boolean exists()
+ {
return cache.containsKey(key);
}
@Override
- public void remove() {
+ public void remove()
+ {
cache.remove(key);
}
@Override
- public void setValue(final V value) {
+ public void setValue(final V value)
+ {
cache.put(key, value);
}
@Override
- public K getKey() {
+ public K getKey()
+ {
return key;
}
@Override
- public V getValue() {
+ public V getValue()
+ {
return cache.get(key);
}
@Override
- public <T> T unwrap(final Class<T> clazz) {
- if (clazz.isInstance(this)) {
+ public <T> T unwrap(final Class<T> clazz)
+ {
+ if (clazz.isInstance(this))
+ {
return clazz.cast(this);
}
throw new IllegalArgumentException(clazz.getName() + " not supported in unwrap");
Modified: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/NoFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/NoFilter.java?rev=1591068&r1=1591067&r2=1591068&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/NoFilter.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/NoFilter.java Tue Apr 29 19:45:14 2014
@@ -4,15 +4,18 @@ import javax.cache.event.CacheEntryEvent
import javax.cache.event.CacheEntryEventFilter;
import javax.cache.event.CacheEntryListenerException;
-public class NoFilter implements CacheEntryEventFilter<Object, Object> {
- public static final CacheEntryEventFilter INSTANCE = new NoFilter();
+public class NoFilter implements CacheEntryEventFilter<Object, Object>
+{
+ public static final CacheEntryEventFilter<Object, Object> INSTANCE = new NoFilter();
- private NoFilter() {
+ private NoFilter()
+ {
// no-op
}
@Override
- public boolean evaluate(final CacheEntryEvent<?, ?> event) throws CacheEntryListenerException {
+ public boolean evaluate(final CacheEntryEvent<?, ?> event) throws CacheEntryListenerException
+ {
return true;
}
}
Modified: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/NoLoader.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/NoLoader.java?rev=1591068&r1=1591067&r2=1591068&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/NoLoader.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/NoLoader.java Tue Apr 29 19:45:14 2014
@@ -5,22 +5,27 @@ import javax.cache.integration.CacheLoad
import java.util.HashMap;
import java.util.Map;
-public class NoLoader<K, V> implements CacheLoader<K, V> {
+public class NoLoader<K, V> implements CacheLoader<K, V>
+{
public static final NoLoader INSTANCE = new NoLoader();
- private NoLoader() {
+ private NoLoader()
+ {
// no-op
}
@Override
- public V load(K key) throws CacheLoaderException {
+ public V load(K key) throws CacheLoaderException
+ {
return null;
}
@Override
- public Map<K, V> loadAll(final Iterable<? extends K> keys) throws CacheLoaderException {
+ public Map<K, V> loadAll(final Iterable<? extends K> keys) throws CacheLoaderException
+ {
final Map<K, V> entries = new HashMap<K, V>();
- for (final K k : keys) {
+ for (final K k : keys)
+ {
entries.put(k, null);
}
return entries;