Author: olamy
Date: Sun Apr 27 23:48:21 2014
New Revision: 1590530
URL: http://svn.apache.org/r1590530
Log:
another bunch of tcks passing
Added:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/io/
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java
(with props)
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/Times.java
(with props)
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/proxy/
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/proxy/ClassLoaderAwareHandler.java
(with props)
Modified:
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/http/broadcast/LateralCacheThread.java
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/http/broadcast/LateralCacheUnicaster.java
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/http/server/LateralCacheServletReciever.java
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/socket/udp/LateralUDPReceiver.java
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/xmlrpc/LateralXMLRPCReceiverConnection.java
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskKeyStore.java
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPSender.java
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/server/RemoteHttpCacheServlet.java
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSCache.java
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSCachingManager.java
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSConfiguration.java
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSElement.java
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/TempStateCacheView.java
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryReceiver.java
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/utils/serialization/CompressingSerializer.java
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/utils/serialization/StandardSerializer.java
commons/proper/jcs/trunk/tck.sh
commons/proper/jcs/trunk/tck.xml
Modified:
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/http/broadcast/LateralCacheThread.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/http/broadcast/LateralCacheThread.java?rev=1590530&r1=1590529&r2=1590530&view=diff
==============================================================================
---
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/http/broadcast/LateralCacheThread.java
(original)
+++
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/http/broadcast/LateralCacheThread.java
Sun Apr 27 23:48:21 2014
@@ -198,7 +198,7 @@ public class LateralCacheThread extends
String result = "";
try
{
- ObjectInputStream is = new ObjectInputStream(
connection.getInputStream() );
+ ObjectInputStream is = new ObjectInputStreamClassLoaderAware(
connection.getInputStream(), null );
result = ( String ) is.readObject();
is.close();
Modified:
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/http/broadcast/LateralCacheUnicaster.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/http/broadcast/LateralCacheUnicaster.java?rev=1590530&r1=1590529&r2=1590530&view=diff
==============================================================================
---
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/http/broadcast/LateralCacheUnicaster.java
(original)
+++
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/http/broadcast/LateralCacheUnicaster.java
Sun Apr 27 23:48:21 2014
@@ -188,7 +188,7 @@ public class LateralCacheUnicaster
String result = "";
try
{
- ObjectInputStream is = new ObjectInputStream(
conn.getInputStream() );
+ ObjectInputStream is = new ObjectInputStreamClassLoaderAware(
conn.getInputStream(), null );
try
{
result = ( String ) is.readObject();
Modified:
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/http/server/LateralCacheServletReciever.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/http/server/LateralCacheServletReciever.java?rev=1590530&r1=1590529&r2=1590530&view=diff
==============================================================================
---
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/http/server/LateralCacheServletReciever.java
(original)
+++
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/http/server/LateralCacheServletReciever.java
Sun Apr 27 23:48:21 2014
@@ -77,7 +77,7 @@ public class LateralCacheServletReciever
// Create the ObjectInputStream with
// the Request InputStream.
- ObjectInputStream ois = new ObjectInputStream(
request.getInputStream() );
+ ObjectInputStream ois = new ObjectInputStreamClassLoaderAware(
request.getInputStream(), null );
if ( log.isDebugEnabled() )
{
Modified:
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/socket/udp/LateralUDPReceiver.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/socket/udp/LateralUDPReceiver.java?rev=1590530&r1=1590529&r2=1590530&view=diff
==============================================================================
---
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/socket/udp/LateralUDPReceiver.java
(original)
+++
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/socket/udp/LateralUDPReceiver.java
Sun Apr 27 23:48:21 2014
@@ -108,7 +108,7 @@ public class LateralUDPReceiver implemen
final ByteArrayInputStream byteStream = new ByteArrayInputStream(
m_buffer, 0, packet.getLength() );
- final ObjectInputStream objectStream = new ObjectInputStream(
byteStream );
+ final ObjectInputStream objectStream = new
ObjectInputStreamClassLoaderAware( byteStream, null );
obj = objectStream.readObject();
Modified:
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/xmlrpc/LateralXMLRPCReceiverConnection.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/xmlrpc/LateralXMLRPCReceiverConnection.java?rev=1590530&r1=1590529&r2=1590530&view=diff
==============================================================================
---
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/xmlrpc/LateralXMLRPCReceiverConnection.java
(original)
+++
commons/proper/jcs/trunk/src/experimental/org/apache/commons/jcs/auxiliary/lateral/xmlrpc/LateralXMLRPCReceiverConnection.java
Sun Apr 27 23:48:21 2014
@@ -85,7 +85,7 @@ public class LateralXMLRPCReceiverConnec
byte[] data = ( byte[] ) params.firstElement();
ByteArrayInputStream bais = new ByteArrayInputStream( data );
BufferedInputStream bis = new BufferedInputStream( bais );
- ObjectInputStream ois = new ObjectInputStream( bis );
+ ObjectInputStream ois = new ObjectInputStreamClassLoaderAware(
bis, null );
try
{
led = ( LateralElementDescriptor ) ois.readObject();
Modified:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskKeyStore.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskKeyStore.java?rev=1590530&r1=1590529&r2=1590530&view=diff
==============================================================================
---
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskKeyStore.java
(original)
+++
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskKeyStore.java
Sun Apr 27 23:48:21 2014
@@ -34,6 +34,7 @@ import java.util.Map;
import java.util.Set;
import org.apache.commons.jcs.auxiliary.disk.LRUMapJCS;
+import org.apache.commons.jcs.io.ObjectInputStreamClassLoaderAware;
import org.apache.commons.jcs.utils.timing.ElapsedTimer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -230,7 +231,7 @@ public class BlockDiskKeyStore<K extends
{
FileInputStream fis = new FileInputStream( keyFile );
BufferedInputStream bis = new BufferedInputStream( fis );
- ObjectInputStream ois = new ObjectInputStream( bis );
+ ObjectInputStream ois = new ObjectInputStreamClassLoaderAware(
bis , null);
try
{
while ( true )
Modified:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java?rev=1590530&r1=1590529&r2=1590530&view=diff
==============================================================================
---
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java
(original)
+++
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPListener.java
Sun Apr 27 23:48:21 2014
@@ -44,6 +44,7 @@ import org.apache.commons.jcs.engine.beh
import org.apache.commons.jcs.engine.behavior.IShutdownObserver;
import org.apache.commons.jcs.engine.control.CompositeCache;
import org.apache.commons.jcs.engine.control.CompositeCacheManager;
+import org.apache.commons.jcs.io.ObjectInputStreamClassLoaderAware;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -601,7 +602,7 @@ public class LateralTCPListener<K extend
try
{
- ois = new ObjectInputStream( socket.getInputStream() );
+ ois = new ObjectInputStreamClassLoaderAware(
socket.getInputStream(), null );
}
catch ( Exception e )
{
Modified:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPSender.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPSender.java?rev=1590530&r1=1590529&r2=1590530&view=diff
==============================================================================
---
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPSender.java
(original)
+++
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPSender.java
Sun Apr 27 23:48:21 2014
@@ -29,6 +29,7 @@ import java.net.Socket;
import org.apache.commons.jcs.auxiliary.lateral.LateralElementDescriptor;
import
org.apache.commons.jcs.auxiliary.lateral.socket.tcp.behavior.ITCPLateralCacheAttributes;
+import org.apache.commons.jcs.io.ObjectInputStreamClassLoaderAware;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -283,7 +284,7 @@ public class LateralTCPSender
{
// TODO make configurable
// socket.setSoTimeout( 2000 );
- ObjectInputStream ois = new ObjectInputStream(
socket.getInputStream() );
+ ObjectInputStream ois = new
ObjectInputStreamClassLoaderAware( socket.getInputStream(), null );
response = ois.readObject();
}
catch ( IOException ioe )
Modified:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/server/RemoteHttpCacheServlet.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/server/RemoteHttpCacheServlet.java?rev=1590530&r1=1590529&r2=1590530&view=diff
==============================================================================
---
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/server/RemoteHttpCacheServlet.java
(original)
+++
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/auxiliary/remote/http/server/RemoteHttpCacheServlet.java
Sun Apr 27 23:48:21 2014
@@ -35,6 +35,7 @@ import org.apache.commons.jcs.access.exc
import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheRequest;
import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheResponse;
import org.apache.commons.jcs.engine.control.CompositeCacheManager;
+import org.apache.commons.jcs.io.ObjectInputStreamClassLoaderAware;
import org.apache.commons.jcs.utils.serialization.StandardSerializer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -155,7 +156,7 @@ public class RemoteHttpCacheServlet
protected RemoteCacheRequest<Serializable, Serializable>
readRequestFromStream( InputStream inputStream )
throws IOException, ClassNotFoundException
{
- ObjectInputStream ois = new ObjectInputStream( inputStream );
+ ObjectInputStream ois = new ObjectInputStreamClassLoaderAware(
inputStream, null );
@SuppressWarnings("unchecked") // Need to cast from Object
RemoteCacheRequest<Serializable, Serializable> remoteRequest
Added:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java?rev=1590530&view=auto
==============================================================================
---
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java
(added)
+++
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java
Sun Apr 27 23:48:21 2014
@@ -0,0 +1,36 @@
+package org.apache.commons.jcs.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+import java.lang.reflect.Proxy;
+
+public class ObjectInputStreamClassLoaderAware extends ObjectInputStream {
+ private final ClassLoader classLoader;
+
+ public ObjectInputStreamClassLoaderAware(final InputStream in, final
ClassLoader classLoader) throws IOException {
+ super(in);
+ this.classLoader = classLoader != null? classLoader :
Thread.currentThread().getContextClassLoader();
+ }
+
+ @Override
+ 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 {
+ final Class[] cinterfaces = new Class[interfaces.length];
+ for (int i = 0; i < interfaces.length; i++) {
+ cinterfaces[i] = Class.forName(interfaces[i], false, classLoader);
+ }
+
+ try {
+ return Proxy.getProxyClass(classLoader, cinterfaces);
+ } catch (IllegalArgumentException e) {
+ throw new ClassNotFoundException(null, e);
+ }
+ }
+
+}
Propchange:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSCache.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSCache.java?rev=1590530&r1=1590529&r2=1590530&view=diff
==============================================================================
---
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSCache.java
(original)
+++
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSCache.java
Sun Apr 27 23:48:21 2014
@@ -3,10 +3,12 @@ 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.utils.serialization.StandardSerializer;
import javax.cache.Cache;
import javax.cache.CacheManager;
@@ -16,9 +18,11 @@ import javax.cache.configuration.Configu
import javax.cache.configuration.Factory;
import javax.cache.event.CacheEntryEvent;
import javax.cache.event.EventType;
+import javax.cache.expiry.Duration;
import javax.cache.expiry.EternalExpiryPolicy;
import javax.cache.expiry.ExpiryPolicy;
import javax.cache.integration.CacheLoader;
+import javax.cache.integration.CacheLoaderException;
import javax.cache.integration.CacheWriter;
import javax.cache.integration.CompletionListener;
import javax.cache.processor.EntryProcessor;
@@ -35,9 +39,7 @@ import java.util.concurrent.ConcurrentHa
import static org.apache.commons.jcs.jcache.Asserts.assertNotNull;
-// TODO: get statistics distributed?
-// TODO:: get configuration and CompleteConfiguration to get CacheLoader
needed for get()
-// TODO:: optimize touch()
+// 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> {
private final CacheAccess<K, JCSElement<V>> delegate;
private final CacheManager manager;
@@ -50,6 +52,7 @@ public class JCSCache<K extends Serializ
private volatile boolean closed = false;
private final Map<CacheEntryListenerConfiguration<K, V>, JCSListener<K,
V>> listeners = new ConcurrentHashMap<CacheEntryListenerConfiguration<K, V>,
JCSListener<K, V>>();
private final Statistics statistics = new Statistics();
+ private final IElementSerializer serializer = new StandardSerializer();
public JCSCache(final CacheManager mgr, final JCSConfiguration<K, V>
configuration, final CompositeCache<K, JCSElement<V>> cache) {
manager = mgr;
@@ -98,16 +101,11 @@ public class JCSCache<K extends Serializ
} catch (final Exception e) {
throw new IllegalArgumentException(e);
}
- JMXs.register(cacheConfigObjectName, new JCSCacheMXBean<K, V>(this));
- JMXs.register(cacheStatsObjectName, new
JCSCacheStatisticsMXBean(statistics));
- }
-
- private void registerJMXBeans() {
- try {
- JMXs.register(cacheStatsObjectName, new
JCSCacheStatisticsMXBean(statistics));
+ if (config.isManagementEnabled()) {
JMXs.register(cacheConfigObjectName, new JCSCacheMXBean<K,
V>(this));
- } catch (final Exception e) {
- throw new IllegalArgumentException(e.getMessage(), e);
+ }
+ if (config.isStatisticsEnabled()) {
+ JMXs.register(cacheStatsObjectName, new
JCSCacheStatisticsMXBean(statistics));
}
}
@@ -121,25 +119,23 @@ public class JCSCache<K extends Serializ
public V get(final K key) {
assertNotClosed();
assertNotNull(key, "key");
-
- final JCSElement<V> elt = delegate.get(key);
- V v = elt != null? elt.getElement() : null;
- if (v == null && config.isReadThrough()) {
- v = doLoad(key);
- } else if (elt != null) {
- elt.update(expiryPolicy.getExpiryForAccess());
- touch(key, elt);
- }
-
- return v;
+ return doGetControllingExpiry(key, true, false, false, true);
}
- private V doLoad(final K key) {
- final V v = loader.load(key);
+ private V doLoad(final K key, final boolean forceDoLoad, final boolean
propagateLoadException) {
+ V v = null;
+ try {
+ v = loader.load(key);
+ } catch (final RuntimeException e) {
+ if (propagateLoadException) {
+ throw new CacheLoaderException(e);
+ }
+ }
if (v != null) {
try {
- if (!expiryPolicy.getExpiryForCreation().isZero()) {
- delegate.put(key, new JCSElement<V>(v,
expiryPolicy.getExpiryForCreation()));
+ final Duration duration = forceDoLoad ?
expiryPolicy.getExpiryForUpdate() : expiryPolicy.getExpiryForCreation();
+ if (duration == null || !duration.isZero()) {
+ delegate.put(key, new JCSElement<V>(v, duration));
}
} catch (final CacheException e) {
throw new IllegalStateException(e);
@@ -160,6 +156,9 @@ public class JCSCache<K extends Serializ
@Override
public Map<K, V> getAll(final Set<? extends K> keys) {
assertNotClosed();
+ for (final K k : keys) {
+ assertNotNull(k , "key");
+ }
final Set<K> names = (Set<K>) keys;
final Map<K, V> result = new HashMap<K, V>();
@@ -170,7 +169,7 @@ public class JCSCache<K extends Serializ
final JCSElement<V> elt = k.getValue() != null ?
k.getValue().getVal() : null;
V val = elt != null ? elt.getElement() : null;
if (val == null && config.isReadThrough()) {
- val = doLoad(key);
+ val = doLoad(key, false, false);
if (val != null) {
result.put(key, val);
}
@@ -180,6 +179,14 @@ public class JCSCache<K extends Serializ
}
result.put(key, val);
}
+ for (final K k : keys) {
+ if (!result.containsKey(k)) {
+ final V v = doLoad(k, false, true);
+ if (v != null) {
+ result.put(k, v);
+ }
+ }
+ }
return result;
}
@@ -191,21 +198,28 @@ public class JCSCache<K extends Serializ
}
@Override
- public void put(final K key, final V value) {
+ public void put(final K key, final V rawValue) {
assertNotClosed();
assertNotNull(key, "key");
- assertNotNull(value, "value");
+ assertNotNull(rawValue, "value");
+
+ final long start = config.isStatisticsEnabled() ? Times.now() : 0;
try {
final JCSElement<V> oldElt = delegate.get(key);
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()) {
- delegate.remove(key);
+ if (!created) {
+ delegate.remove(key);
+ }
} else {
- delegate.put(key, element);
+ delegate.put(storeByValue ? copy(key) : key, element);
writer.write(new JCSEntry<K, V>(key, value));
for (final JCSListener<K, V> listener : listeners.values()) {
if (created) {
@@ -216,19 +230,28 @@ public class JCSCache<K extends Serializ
new JCSCacheEntryEvent<K, V>(this,
EventType.UPDATED, old, key, value)));
}
}
- }
- if (config.isStatisticsEnabled()) {
- statistics.increasePuts(1);
+ if (config.isStatisticsEnabled()) {
+ statistics.increasePuts(1);
+ statistics.addPutTime(System.currentTimeMillis() - start);
+ }
}
} catch (final CacheException e) {
throw new IllegalStateException(e);
}
}
+ private <T extends Serializable> T copy(final T value) {
+ try {
+ return serializer.deSerialize(serializer.serialize(value));
+ } catch (final Exception ioe) {
+ throw new IllegalStateException(ioe.getMessage(), ioe);
+ }
+ }
+
@Override
public V getAndPut(final K key, final V value) {
- final V v = get(key);
+ final V v = doGetControllingExpiry(key, false, false, true, false);
put(key, value);
return v;
}
@@ -257,13 +280,22 @@ public class JCSCache<K extends Serializ
assertNotClosed();
assertNotNull(key, "key");
+ final long start = config.isStatisticsEnabled() ? Times.now() : 0;
+
final JCSElement<V> v = delegate.get(key);
final V value = v != null && v.getElement() != null ? v.getElement() :
null;
- final boolean remove = delegate.getCacheControl().remove(key);
+ boolean remove = delegate.getCacheControl().remove(key);
+ 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)));
}
+ if (remove && config.isStatisticsEnabled()) {
+ statistics.increaseRemovals(1);
+ statistics.addRemoveTime(Times.now() - start);
+ }
return remove;
}
@@ -272,36 +304,85 @@ public class JCSCache<K extends Serializ
assertNotClosed();
assertNotNull(key, "key");
assertNotNull(oldValue, "oldValue");
- if (containsKey(key) && get(key).equals(oldValue)) {
- remove(key);
- return true;
+ final V v = doGetControllingExpiry(key, false, false, false, false);
+ final boolean found = v != null;
+ if (found) {
+ if (v.equals(oldValue)) {
+ remove(key);
+ return true;
+ }
+ delegate.get(key).update(expiryPolicy.getExpiryForAccess());
}
return false;
}
@Override
public V getAndRemove(final K key) {
- final V v = get(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) {
+ final long getStart = Times.now();
+ final JCSElement<V> elt = delegate.get(key);
+ V v = elt != null? elt.getElement() : null;
+ if (v == null && config.isReadThrough()) {
+ if (!skipLoad) {
+ v = doLoad(key, forceDoLoad, propagateLoadException);
+ }
+ } else if (config.isStatisticsEnabled()) {
+ if (elt != null) {
+ statistics.increaseHits(1);
+ } else {
+ statistics.increaseMisses(1);
+ statistics.addGetTime(Times.now() - getStart);
+ }
+ }
+ if (updateAcess && elt != null) {
+ elt.update(expiryPolicy.getExpiryForAccess());
+ if (elt.isExpired()) {
+ delegate.getCacheControl().remove(key);
+ } else {
+ touch(key, elt);
+ }
+ }
+ if (v != null) {
+ statistics.addGetTime(Times.now() - getStart);
+ }
+ return v;
+ }
+
@Override
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) {
V value = elt.getElement();
+ if (elt.isExpired()) {
+ value = null;
+ }
+ if (value != null && statisticsEnabled) {
+ statistics.increaseHits(1);
+ }
if (value == null && config.isReadThrough()) {
- value = doLoad(key);
+ value = doLoad(key, false, false);
}
if (value != null && value.equals(oldValue)) {
put(key, newValue);
return true;
+ } else if (value != null) {
+ elt.update(expiryPolicy.getExpiryForAccess());
+ touch(key, elt);
}
+ } else if (statisticsEnabled) {
+ statistics.increaseMisses(1);
}
return false;
}
@@ -311,9 +392,15 @@ public class JCSCache<K extends Serializ
assertNotClosed();
assertNotNull(key, "key");
assertNotNull(value, "value");
+ boolean statisticsEnabled = config.isStatisticsEnabled();
if (containsKey(key)) {
+ if (statisticsEnabled) {
+ statistics.increaseHits(1);
+ }
put(key, value);
return true;
+ } else if (statisticsEnabled) {
+ statistics.increaseMisses(1);
}
return false;
}
@@ -324,14 +411,20 @@ public class JCSCache<K extends Serializ
assertNotNull(key, "key");
assertNotNull(value, "value");
+ final boolean statisticsEnabled = config.isStatisticsEnabled();
+
final JCSElement<V> elt = delegate.get(key);
if (elt != null) {
V oldValue = elt.getElement();
if (oldValue == null && config.isReadThrough()) {
- oldValue = doLoad(key);
+ oldValue = doLoad(key, false, false);
+ } else if (statisticsEnabled) {
+ statistics.increaseHits(1);
}
put(key, value);
return oldValue;
+ } else if (statisticsEnabled) {
+ statistics.increaseMisses(1);
}
return null;
}
@@ -348,7 +441,14 @@ public class JCSCache<K extends Serializ
@Override
public void removeAll() {
if (config.isStatisticsEnabled()) {
- statistics.increaseRemovals(delegate.getCacheControl().getSize());
+ int i = 0;
+ final CompositeCache<K, JCSElement<V>> underlying =
delegate.getCacheControl();
+ for (final K elt : underlying.getKeySet()) {
+ if (!underlying.get(elt).getVal().isExpired()) {
+ i++;
+ }
+ }
+ statistics.increaseRemovals(i);
}
clear();
}
@@ -373,18 +473,29 @@ public class JCSCache<K extends Serializ
public void loadAll(final Set<? extends K> keys, final boolean
replaceExistingValues,
final CompletionListener completionListener) {
assertNotClosed();
+ assertNotNull(keys, "keys");
+ for (final K k : keys) {
+ assertNotNull(k, "a key");
+ }
// TODO: async
try {
for (final K k : keys) {
- if (!containsKey(k) || replaceExistingValues) {
- get(k); // will trigger cacheloader and init
+ final boolean removed;
+ if (replaceExistingValues) {
+ removed = delegate.getCacheControl().remove(k);
+ } else if (containsKey(k)) {
+ continue;
+ } else {
+ removed = false;
}
+ doGetControllingExpiry(k, true, removed, false,
completionListener != null); // will trigger cacheloader and init
}
- } catch (final Exception e) {
+ } catch (final RuntimeException e) {
if (completionListener != null) {
completionListener.onException(e);
+ return;
}
- return;
+ throw e;
}
if (completionListener != null) {
completionListener.onCompletion();
@@ -404,6 +515,13 @@ public class JCSCache<K extends Serializ
assertNotNull(entryProcessor, "entryProcessor");
assertNotNull(key, "key");
try {
+ if (config.isStatisticsEnabled()) {
+ if (containsKey(key)) {
+ statistics.increaseHits(1);
+ } else {
+ statistics.increaseMisses(1);
+ }
+ }
return entryProcessor.process(new JCSMutableEntry<K, V>(view,
key), arguments);
} catch (final Exception ex) {
return throwEntryProcessorException(ex);
@@ -422,15 +540,19 @@ public class JCSCache<K extends Serializ
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 {
- results.put(k, new EntryProcessorResult<T>() {
- @Override
- public T get() throws EntryProcessorException {
- return invoke(k, entryProcessor, arguments);
- }
- });
+ final T invoke = invoke(k, entryProcessor, arguments);
+ if (invoke != null) {
+ results.put(k, new EntryProcessorResult<T>() {
+ @Override
+ public T get() throws EntryProcessorException {
+ return invoke;
+ }
+ });
+ }
} catch (final Exception e) {
results.put(k, new EntryProcessorResult<T>() {
@Override
@@ -531,4 +653,26 @@ public class JCSCache<K extends Serializ
public Statistics getStatistics() {
return statistics;
}
+
+ public void enableManagement() {
+ config.managementEnabled();
+ JMXs.register(cacheConfigObjectName, new JCSCacheMXBean<K, V>(this));
+ }
+
+ public void disableManagement() {
+ config.managementDisabled();
+ JMXs.unregister(cacheConfigObjectName);
+ }
+
+ public void enableStatistics() {
+ config.statisticsEnabled();
+ statistics.setActive(true);
+ JMXs.register(cacheStatsObjectName, new
JCSCacheStatisticsMXBean(statistics));
+ }
+
+ public void disableStatistics() {
+ config.statisticsDisabled();
+ statistics.setActive(false);
+ JMXs.unregister(cacheStatsObjectName);
+ }
}
Modified:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSCachingManager.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSCachingManager.java?rev=1590530&r1=1590529&r2=1590530&view=diff
==============================================================================
---
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSCachingManager.java
(original)
+++
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSCachingManager.java
Sun Apr 27 23:48:21 2014
@@ -2,6 +2,7 @@ package org.apache.commons.jcs.jcache;
import org.apache.commons.jcs.access.exception.CacheException;
import org.apache.commons.jcs.engine.control.CompositeCacheManager;
+import org.apache.commons.jcs.jcache.proxy.ClassLoaderAwareHandler;
import javax.cache.Cache;
import javax.cache.CacheManager;
@@ -9,6 +10,7 @@ import javax.cache.configuration.Configu
import javax.cache.spi.CachingProvider;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.reflect.Proxy;
import java.net.URI;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
@@ -74,11 +76,15 @@ public class JCSCachingManager implement
assertNotClosed();
assertNotNull(cacheName, "cacheName");
if (!caches.containsKey(cacheName)) {
- caches.putIfAbsent(cacheName,
+ final Cache<K, V> cache = ClassLoaderAwareHandler.newProxy(
+ loader,
new JCSCache/*<K, V, C>*/(
this,
new JCSConfiguration(configuration,
configuration.getKeyType(), configuration.getValueType()),
- instance.getCache(cacheName)));
+ instance.getCache(cacheName)),
+ Cache.class
+ );
+ caches.putIfAbsent(cacheName, cache);
} else {
throw new javax.cache.CacheException("cache " + cacheName + "
already exists");
}
@@ -102,14 +108,33 @@ public class JCSCachingManager implement
public void enableManagement(final String cacheName, final boolean
enabled) {
assertNotClosed();
assertNotNull(cacheName, "cacheName");
- throw new UnsupportedOperationException();
+ final JCSCache<?, ?, ?> cache = getJCSCache(cacheName);
+ if (cache != null) {
+ if (enabled) {
+ cache.enableManagement();
+ } else {
+ cache.disableManagement();
+ }
+ }
+ }
+
+ 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) {
assertNotClosed();
assertNotNull(cacheName, "cacheName");
- throw new UnsupportedOperationException();
+ final JCSCache<?, ?, ?> cache = getJCSCache(cacheName);
+ if (cache != null) {
+ if (enabled) {
+ cache.enableStatistics();
+ } else {
+ cache.disableStatistics();
+ }
+ }
}
@Override
Modified:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSConfiguration.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSConfiguration.java?rev=1590530&r1=1590529&r2=1590530&view=diff
==============================================================================
---
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSConfiguration.java
(original)
+++
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSConfiguration.java
Sun Apr 27 23:48:21 2014
@@ -40,8 +40,8 @@ public class JCSConfiguration<K, V> impl
private final Factory<ExpiryPolicy> expiryPolicyFactory;
private final Set<CacheEntryListenerConfiguration<K, V>>
cacheEntryListenerConfigurations;
- private boolean statisticsEnabled = true;
- private boolean managementEnabled = true;
+ private volatile boolean statisticsEnabled;
+ private volatile boolean managementEnabled;
public JCSConfiguration(final Configuration<K, V> configuration, final
Class<K> keyType, final Class<V> valueType) {
this.keyType = keyType;
@@ -69,6 +69,8 @@ public class JCSConfiguration<K, V> impl
storeByValue = true;
readThrough = false;
writeThrough = false;
+ statisticsEnabled = false;
+ managementEnabled = false;
cacheLoaderFactory = null;
cacheWristerFactory = null;
cacheEntryListenerConfigurations = new
HashSet<CacheEntryListenerConfiguration<K, V>>();
@@ -137,4 +139,20 @@ public class JCSConfiguration<K, V> impl
public synchronized void removeListener(final
CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) {
cacheEntryListenerConfigurations.remove(cacheEntryListenerConfiguration);
}
+
+ public void statisticsEnabled() {
+ statisticsEnabled = true;
+ }
+
+ public void managementEnabled() {
+ managementEnabled = true;
+ }
+
+ public void statisticsDisabled() {
+ statisticsEnabled = false;
+ }
+
+ public void managementDisabled() {
+ managementEnabled = false;
+ }
}
Modified:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSElement.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSElement.java?rev=1590530&r1=1590529&r2=1590530&view=diff
==============================================================================
---
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSElement.java
(original)
+++
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/JCSElement.java
Sun Apr 27 23:48:21 2014
@@ -12,12 +12,8 @@ public class JCSElement<V> implements Se
update(duration);
}
- private static long now() {
- return System.currentTimeMillis();
- }
-
public boolean isExpired() {
- return end != -1 && (end == 0 || now() > end);
+ return end != -1 && (end == 0 || Times.now() > end);
}
public V getElement() {
@@ -30,7 +26,7 @@ public class JCSElement<V> implements Se
} else if (duration.isZero()) {
end = 0;
} else {
- end = duration.getAdjustedTime(now());
+ end = duration.getAdjustedTime(Times.now());
}
}
}
Modified:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/TempStateCacheView.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/TempStateCacheView.java?rev=1590530&r1=1590529&r2=1590530&view=diff
==============================================================================
---
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/TempStateCacheView.java
(original)
+++
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/TempStateCacheView.java
Sun Apr 27 23:48:21 2014
@@ -3,11 +3,13 @@ package org.apache.commons.jcs.jcache;
import javax.cache.Cache;
import javax.cache.CacheManager;
import javax.cache.configuration.CacheEntryListenerConfiguration;
+import javax.cache.configuration.CompleteConfiguration;
import javax.cache.configuration.Configuration;
import javax.cache.integration.CompletionListener;
import javax.cache.processor.EntryProcessor;
import javax.cache.processor.EntryProcessorException;
import javax.cache.processor.EntryProcessorResult;
+import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -18,14 +20,14 @@ import java.util.Set;
import static org.apache.commons.jcs.jcache.Asserts.assertNotNull;
-public class TempStateCacheView<K, V> implements Cache<K, V> {
- private final Cache<K, V> cache;
+public class TempStateCacheView<K extends Serializable, V extends
Serializable> implements Cache<K, V> {
+ private final JCSCache<K, V, ?> cache;
private final Map<K, V> put = new HashMap<K, V>();
private final Collection<K> remove = new LinkedList<K>();
private boolean removeAll = false;
private boolean clear = false;
- public TempStateCacheView(final Cache<K, V> entries) {
+ public TempStateCacheView(final JCSCache<K, V, ?> entries) {
this.cache = entries;
}
@@ -38,6 +40,16 @@ public class TempStateCacheView<K, V> im
if (v != null) {
return v;
}
+
+ // for an EntryProcessor we already incremented stats
+ if
(cache.getConfiguration(CompleteConfiguration.class).isStatisticsEnabled()) {
+ final Statistics statistics = cache.getStatistics();
+ if (cache.containsKey(key)) {
+ statistics.increaseHits(-1);
+ } else {
+ statistics.increaseMisses(-1);
+ }
+ }
return cache.get(key);
}
@@ -63,7 +75,7 @@ public class TempStateCacheView<K, V> im
}
public boolean containsKey(final K key) {
- return !ignoreKey(key) && put.containsKey(key) ||
cache.containsKey(key);
+ return !ignoreKey(key) && (put.containsKey(key) ||
cache.containsKey(key));
}
public void loadAll(final Set<? extends K> keys, final boolean
replaceExistingValues, final CompletionListener completionListener) {
Added:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/Times.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/Times.java?rev=1590530&view=auto
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/Times.java
(added)
+++ commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/Times.java
Sun Apr 27 23:48:21 2014
@@ -0,0 +1,11 @@
+package org.apache.commons.jcs.jcache;
+
+public class Times {
+ public static long now() {
+ return System.currentTimeMillis();
+ }
+
+ private Times() {
+ // no-op
+ }
+}
Propchange:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/Times.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/Times.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/proxy/ClassLoaderAwareHandler.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/proxy/ClassLoaderAwareHandler.java?rev=1590530&view=auto
==============================================================================
---
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/proxy/ClassLoaderAwareHandler.java
(added)
+++
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/proxy/ClassLoaderAwareHandler.java
Sun Apr 27 23:48:21 2014
@@ -0,0 +1,60 @@
+package org.apache.commons.jcs.jcache.proxy;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+public class ClassLoaderAwareHandler implements InvocationHandler {
+ private final ClassLoader loader;
+ private final Object delegate;
+
+ public ClassLoaderAwareHandler(final ClassLoader loader, final Object
delegate) {
+ this.loader = loader;
+ this.delegate = delegate;
+ }
+
+ @Override
+ public Object invoke(final Object proxy, final Method method, final
Object[] args) throws Throwable {
+ final Thread th = Thread.currentThread();
+ final ClassLoader old = th.getContextClassLoader();
+ th.setContextClassLoader(loader);
+ try {
+ if (Object.class == method.getDeclaringClass()) {
+ if (isEquals(method, args)) {
+ return doEquals(method, args);
+ }
+ }
+ return method.invoke(delegate, args);
+ } catch (final InvocationTargetException ite) {
+ throw ite.getCause();
+ } finally {
+ th.setContextClassLoader(old);
+ }
+ }
+
+ private Object doEquals(final Method method, final Object[] args) throws
IllegalAccessException, InvocationTargetException {
+ if (args[0] == null) {
+ return false;
+ }
+ if (Proxy.isProxyClass(args[0].getClass())) {
+ final InvocationHandler handler =
Proxy.getInvocationHandler(args[0]);
+ if (ClassLoaderAwareHandler.class.isInstance(handler)) {
+ return
delegate.equals(ClassLoaderAwareHandler.class.cast(handler).delegate);
+ }
+ }
+ return method.invoke(delegate, args);
+ }
+
+ private boolean isEquals(Method method, Object[] args) {
+ return "equals".equals(method.getName()) && args != null &&
args.length == 1;
+ }
+
+ public static <T> T newProxy(final ClassLoader loader, final Object
delegate, final Class<?>...apis) {
+ return (T) Proxy.newProxyInstance(loader, apis, new
ClassLoaderAwareHandler(loader, delegate));
+ }
+
+ public Object getDelegate() {
+ return delegate;
+ }
+}
Propchange:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/proxy/ClassLoaderAwareHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/jcache/proxy/ClassLoaderAwareHandler.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryReceiver.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryReceiver.java?rev=1590530&r1=1590529&r2=1590530&view=diff
==============================================================================
---
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryReceiver.java
(original)
+++
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryReceiver.java
Sun Apr 27 23:48:21 2014
@@ -31,6 +31,7 @@ import java.util.concurrent.ThreadPoolEx
import org.apache.commons.jcs.engine.CacheInfo;
import org.apache.commons.jcs.engine.behavior.IShutdownObserver;
+import org.apache.commons.jcs.io.ObjectInputStreamClassLoaderAware;
import
org.apache.commons.jcs.utils.discovery.UDPDiscoveryMessage.BroadcastType;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -165,7 +166,7 @@ public class UDPDiscoveryReceiver
}
final ByteArrayInputStream byteStream = new ByteArrayInputStream(
mBuffer, 0, packet.getLength() );
- final ObjectInputStream objectStream = new ObjectInputStream(
byteStream );
+ final ObjectInputStream objectStream = new
ObjectInputStreamClassLoaderAware( byteStream, null );
obj = objectStream.readObject();
if ( obj != null && obj instanceof UDPDiscoveryMessage )
Modified:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/utils/serialization/CompressingSerializer.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/utils/serialization/CompressingSerializer.java?rev=1590530&r1=1590529&r2=1590530&view=diff
==============================================================================
---
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/utils/serialization/CompressingSerializer.java
(original)
+++
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/utils/serialization/CompressingSerializer.java
Sun Apr 27 23:48:21 2014
@@ -28,6 +28,7 @@ import java.io.ObjectOutputStream;
import java.io.Serializable;
import org.apache.commons.jcs.engine.behavior.IElementSerializer;
+import org.apache.commons.jcs.io.ObjectInputStreamClassLoaderAware;
import org.apache.commons.jcs.utils.zip.CompressionUtil;
/**
@@ -110,7 +111,7 @@ public class CompressingSerializer
{
ByteArrayInputStream bais = new ByteArrayInputStream(
decompressedByteArray );
BufferedInputStream bis = new BufferedInputStream( bais );
- ObjectInputStream ois = new ObjectInputStream( bis );
+ ObjectInputStream ois = new ObjectInputStreamClassLoaderAware( bis,
null );
try
{
Modified:
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/utils/serialization/StandardSerializer.java
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/utils/serialization/StandardSerializer.java?rev=1590530&r1=1590529&r2=1590530&view=diff
==============================================================================
---
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/utils/serialization/StandardSerializer.java
(original)
+++
commons/proper/jcs/trunk/src/java/org/apache/commons/jcs/utils/serialization/StandardSerializer.java
Sun Apr 27 23:48:21 2014
@@ -19,6 +19,9 @@ package org.apache.commons.jcs.utils.ser
* under the License.
*/
+import org.apache.commons.jcs.engine.behavior.IElementSerializer;
+import org.apache.commons.jcs.io.ObjectInputStreamClassLoaderAware;
+
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -27,8 +30,6 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
-import org.apache.commons.jcs.engine.behavior.IElementSerializer;
-
/**
* Performs default serialization and de-serialization.
* <p>
@@ -76,7 +77,7 @@ public class StandardSerializer
{
ByteArrayInputStream bais = new ByteArrayInputStream( data );
BufferedInputStream bis = new BufferedInputStream( bais );
- ObjectInputStream ois = new ObjectInputStream( bis );
+ ObjectInputStream ois = new ObjectInputStreamClassLoaderAware( bis,
null );
try
{
@SuppressWarnings("unchecked") // Need to cast from Object
Modified: commons/proper/jcs/trunk/tck.sh
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/tck.sh?rev=1590530&r1=1590529&r2=1590530&view=diff
==============================================================================
--- commons/proper/jcs/trunk/tck.sh (original)
+++ commons/proper/jcs/trunk/tck.sh Sun Apr 27 23:48:21 2014
@@ -1,3 +1,8 @@
#! /bin/bash
-mvn clean -f tck.xml test $@
+
+# build [jcs] first
+mvn clean install -Dmaven.test.skip=true
+
+# then run tck against freshly built binaries
+mvn clean -f tck.xml test surefire-report:report-only
-Dmaven.test.failure.ignore=true $@
Modified: commons/proper/jcs/trunk/tck.xml
URL:
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/tck.xml?rev=1590530&r1=1590529&r2=1590530&view=diff
==============================================================================
--- commons/proper/jcs/trunk/tck.xml (original)
+++ commons/proper/jcs/trunk/tck.xml Sun Apr 27 23:48:21 2014
@@ -11,6 +11,8 @@
-P test-optional-cache
-P test-basic-cache
+ to run from an IDE a JMX test add:
+ -Dorg.jsr107.tck.management.agentId=MBeanServerJCS
-Djavax.management.builder.initial=org.apache.commons.jcs.jcache.jmx.ConfigurableMBeanServerIdBuilder
-->
<groupId>org.apache.commons</groupId>
@@ -110,6 +112,7 @@
<executions>
<execution>
<id>copy-cache-tests</id>
+ <phase>generate-test-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
@@ -123,6 +126,7 @@
</execution>
<execution>
<id>copy-domain</id>
+ <phase>generate-test-resources</phase>
<goals>
<goal>copy</goal>
</goals>