Permalink
Browse files

ISPN-2639 Integrate JCache 0.6 version and integrate TCK testing

* Use Maven Invoker Plugin to run TCK automatically in each build.
avoid leaking classloaders.
* Cache manager name for Infinispan JMX configuration should be
composed of the cache manager name and classloader information in
order to guarantee uniqueness. Otherwise, TCK fails with a lot of
JMX domain conflict errors, and there's no real reason for allowing
duplicate domains whose name would be more confusing.
* Infinispan cache manager implementation has a finalize() method to
avoid cache managers being garbage collected without proper shutdown.
* Move to a weak key map for cache manager collections, keyed on
class loader that avoids leaks.
* Make all other references to class loaders weak to avoid keeping
strong references.
* Implement support for UserTransaction
* Use jcache as module name
* Added support for Cache writers.
* Add an assertion to Infinispan Cache so that old values are checked
for null.
* Implement removeAll().
* Some operations should skip loading from cache.
* If cache non transactional, return STATUS_NO_TRANSACTION.
  • Loading branch information...
1 parent b0636a7 commit 7889c2d940c8be410f8fb294e9496ef0765660d7 @galderz galderz committed with maniksurtani Feb 8, 2013
Showing with 2,156 additions and 827 deletions.
  1. +57 −56 core/src/main/java/org/infinispan/DecoratedCache.java
  2. +4 −3 core/src/main/java/org/infinispan/configuration/cache/Configuration.java
  3. +7 −5 core/src/main/java/org/infinispan/configuration/cache/ConfigurationBuilder.java
  4. +4 −3 core/src/main/java/org/infinispan/configuration/global/GlobalConfiguration.java
  5. +7 −6 core/src/main/java/org/infinispan/configuration/global/GlobalConfigurationBuilder.java
  6. +4 −3 core/src/main/java/org/infinispan/configuration/parsing/ConfigurationBuilderHolder.java
  7. +6 −5 core/src/main/java/org/infinispan/configuration/parsing/ParserRegistry.java
  8. +5 −3 core/src/main/java/org/infinispan/context/impl/AbstractInvocationContext.java
  9. +3 −2 core/src/main/java/org/infinispan/factories/ComponentRegistry.java
  10. +3 −2 core/src/main/java/org/infinispan/factories/GlobalComponentRegistry.java
  11. +6 −3 core/src/main/java/org/infinispan/factories/InternalCacheFactory.java
  12. +5 −3 core/src/main/java/org/infinispan/marshall/jboss/DefaultContextClassResolver.java
  13. +4 −3 core/src/main/java/org/infinispan/notifications/AbstractListenerImpl.java
  14. +345 −0 core/src/main/java/org/infinispan/util/WeakValueHashMap.java
  15. +137 −0 jcache/pom.xml
  16. +209 −0 jcache/src/it/tck-runner/pom.xml
  17. +35 −0 jcache/src/it/tck-runner/src/test/java/org/infinispan/jcache/test/tck/DummyTestListener.java
  18. +6 −0 jcache/src/it/tck-runner/src/test/resources/ExcludeList
  19. +3 −0 jcache/src/it/tck-runner/src/test/resources/unwrap.properties
  20. +21 −10 ...g/infinispan/jsr107/cache → jcache/src/main/java/org/infinispan/jcache}/ConfigurationAdapter.java
  21. +588 −0 jcache/src/main/java/org/infinispan/jcache/JCache.java
  22. +9 −9 ...107/cache/InfinispanCacheEntry.java → jcache/src/main/java/org/infinispan/jcache/JCacheEntry.java
  23. +5 −5 ...CacheListenerAdapter.java → jcache/src/main/java/org/infinispan/jcache/JCacheListenerAdapter.java
  24. +74 −8 ...spanCacheLoaderAdapter.java → jcache/src/main/java/org/infinispan/jcache/JCacheLoaderAdapter.java
  25. +106 −35 ...cache/InfinispanCacheManager.java → jcache/src/main/java/org/infinispan/jcache/JCacheManager.java
  26. +185 −0 jcache/src/main/java/org/infinispan/jcache/JCacheManagerFactory.java
  27. +86 −0 jcache/src/main/java/org/infinispan/jcache/JCacheUserTransaction.java
  28. +11 −8 ...spanCacheWriterAdapter.java → jcache/src/main/java/org/infinispan/jcache/JCacheWriterAdapter.java
  29. +5 −5 ...InfinispanCachingProvider.java → jcache/src/main/java/org/infinispan/jcache/JCachingProvider.java
  30. +2 −2 ...InfinispanStatusConverter.java → jcache/src/main/java/org/infinispan/jcache/JStatusConverter.java
  31. +62 −0 jcache/src/main/java/org/infinispan/jcache/MutableJCacheEntry.java
  32. +1 −1 .../org/infinispan/jsr107/cache → jcache/src/main/java/org/infinispan/jcache}/RICacheEntryEvent.java
  33. +1 −1 ...sr107/cache → jcache/src/main/java/org/infinispan/jcache}/RICacheEntryEventFilteringIterable.java
  34. +1 −1 ...sr107/cache → jcache/src/main/java/org/infinispan/jcache}/RICacheEntryEventFilteringIterator.java
  35. +1 −1 .../jsr107/cache → jcache/src/main/java/org/infinispan/jcache}/RICacheEntryListenerRegistration.java
  36. +5 −5 .../org/infinispan/jsr107/cache → jcache/src/main/java/org/infinispan/jcache}/RICacheStatistics.java
  37. +64 −0 jcache/src/main/java/org/infinispan/jcache/RIDelegatingCacheMXBean.java
  38. +66 −0 jcache/src/main/java/org/infinispan/jcache/logging/Log.java
  39. +1 −0 jcache/src/main/resources/META-INF/services/javax.cache.spi.CachingProvider
  40. +0 −98 jsr107impl/pom.xml
  41. +0 −398 jsr107impl/src/main/java/org/infinispan/jsr107/cache/InfinispanCache.java
  42. +0 −141 jsr107impl/src/main/java/org/infinispan/jsr107/cache/InfinispanCacheManagerFactory.java
  43. +0 −1 jsr107impl/src/main/resources/META-INF/services/javax.cache.spi.CachingProvider
  44. +11 −1 parent/pom.xml
  45. +1 −0 pom.xml

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -18,14 +18,15 @@
*/
package org.infinispan.configuration.cache;
+import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Configuration {
- private final ClassLoader classLoader; //TODO remove this
+ private final WeakReference<ClassLoader> classLoader; //TODO remove this
private final ClusteringConfiguration clusteringConfiguration;
private final CustomInterceptorsConfiguration customInterceptorsConfiguration;
private final DataContainerConfiguration dataContainerConfiguration;
@@ -75,15 +76,15 @@
}
this.moduleConfiguration = Collections.unmodifiableMap(modulesMap);
this.sites = sites;
- this.classLoader = cl;
+ this.classLoader = new WeakReference<ClassLoader>(cl);
}
/**
* Will be removed with no replacement
*/
@Deprecated
public ClassLoader classLoader() {
- return classLoader;
+ return classLoader == null ? null : classLoader.get();
}
public ClusteringConfiguration clustering() {
@@ -20,6 +20,7 @@
import static java.util.Arrays.asList;
+import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.LinkedList;
@@ -31,7 +32,7 @@
public class ConfigurationBuilder implements ConfigurationChildBuilder {
- private ClassLoader classLoader;
+ private WeakReference<ClassLoader> classLoader;
private final ClusteringConfigurationBuilder clustering;
private final CustomInterceptorsConfigurationBuilder customInterceptors;
private final DataContainerConfigurationBuilder dataContainer;
@@ -70,12 +71,12 @@ public ConfigurationBuilder() {
}
public ConfigurationBuilder classLoader(ClassLoader cl) {
- this.classLoader = cl;
+ this.classLoader = new WeakReference<ClassLoader>(cl);
return this;
}
ClassLoader classLoader() {
- return classLoader;
+ return classLoader.get();
}
@Override
@@ -209,11 +210,12 @@ public Configuration build(boolean validate) {
dataContainer.create(), deadlockDetection.create(), eviction.create(),
expiration.create(), indexing.create(), invocationBatching.create(),
jmxStatistics.create(), loaders.create(), locking.create(), storeAsBinary.create(),
- transaction.create(), unsafe.create(), versioning.create(), modulesConfig,sites.create() , classLoader);
+ transaction.create(), unsafe.create(), versioning.create(), modulesConfig,sites.create() ,
+ classLoader == null ? null : classLoader.get());
}
public ConfigurationBuilder read(Configuration template) {
- this.classLoader = template.classLoader();
+ this.classLoader = new WeakReference<ClassLoader>(template.classLoader());
this.clustering.read(template.clustering());
this.customInterceptors.read(template.customInterceptors());
this.dataContainer.read(template.dataContainer());
@@ -22,6 +22,7 @@
*/
package org.infinispan.configuration.global;
+import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -67,7 +68,7 @@
private final ShutdownConfiguration shutdown;
private final Map<Class<?>, ?> modules;
private final SiteConfiguration site;
- private final ClassLoader cl;
+ private final WeakReference<ClassLoader> cl;
GlobalConfiguration(ExecutorFactoryConfiguration asyncListenerExecutor,
ExecutorFactoryConfiguration asyncTransportExecutor, ScheduledExecutorFactoryConfiguration evictionScheduledExecutor,
@@ -88,7 +89,7 @@
}
this.modules = Collections.unmodifiableMap(moduleMap);
this.site = site;
- this.cl = cl;
+ this.cl = new WeakReference<ClassLoader>(cl);
}
public ExecutorFactoryConfiguration asyncListenerExecutor() {
@@ -136,7 +137,7 @@ public ShutdownConfiguration shutdown() {
* Get the classloader in use by this configuration.
*/
public ClassLoader classLoader() {
- return cl;
+ return cl.get();
}
public SiteConfiguration sites() {
@@ -23,6 +23,7 @@
package org.infinispan.configuration.global;
+import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.LinkedList;
@@ -35,7 +36,7 @@
public class GlobalConfigurationBuilder implements GlobalConfigurationChildBuilder {
- private ClassLoader cl;
+ private WeakReference<ClassLoader> cl;
private final TransportConfigurationBuilder transport;
private final GlobalJmxStatisticsConfigurationBuilder globalJmxStatistics;
private final SerializationConfigurationBuilder serialization;
@@ -48,7 +49,7 @@
private final SiteConfigurationBuilder site;
public GlobalConfigurationBuilder() {
- this.cl = Thread.currentThread().getContextClassLoader();
+ this.cl = new WeakReference<ClassLoader>(Thread.currentThread().getContextClassLoader());
this.transport = new TransportConfigurationBuilder(this);
this.globalJmxStatistics = new GlobalJmxStatisticsConfigurationBuilder(this);
this.serialization = new SerializationConfigurationBuilder(this);
@@ -88,11 +89,11 @@ public GlobalConfigurationBuilder nonClusteredDefault() {
}
protected ClassLoader getClassLoader() {
- return cl;
+ return cl.get();
}
public GlobalConfigurationBuilder classLoader(ClassLoader cl) {
- this.cl = cl;
+ this.cl = new WeakReference<ClassLoader>(cl);
return this;
}
@@ -194,12 +195,12 @@ public GlobalConfiguration build() {
shutdown.create(),
modulesConfig,
site.create(),
- cl
+ cl.get()
);
}
public GlobalConfigurationBuilder read(GlobalConfiguration template) {
- this.cl = template.classLoader();
+ this.cl = new WeakReference<ClassLoader>(template.classLoader());
for (Object c : template.modules().values()) {
BuiltBy builtBy = c.getClass().getAnnotation(BuiltBy.class);
@@ -18,6 +18,7 @@
*/
package org.infinispan.configuration.parsing;
+import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
@@ -31,7 +32,7 @@
private final Map<String, ConfigurationBuilder> namedConfigurationBuilders;
private ConfigurationBuilder currentConfigurationBuilder;
private final Map<Class<? extends ConfigurationParser<?>>, ParserContext> parserContexts;
- private final ClassLoader classLoader;
+ private final WeakReference<ClassLoader> classLoader;
public ConfigurationBuilderHolder() {
this(Thread.currentThread().getContextClassLoader());
@@ -43,7 +44,7 @@ public ConfigurationBuilderHolder(ClassLoader classLoader) {
this.namedConfigurationBuilders = new HashMap<String, ConfigurationBuilder>();
this.currentConfigurationBuilder = defaultConfigurationBuilder;
this.parserContexts = new HashMap<Class<? extends ConfigurationParser<?>>, ParserContext>();
- this.classLoader = classLoader;
+ this.classLoader = new WeakReference<ClassLoader>(classLoader);
}
public GlobalConfigurationBuilder getGlobalConfigurationBuilder() {
@@ -82,7 +83,7 @@ public void setParserContext(Class<? extends ConfigurationParser<?>> parserClass
}
public ClassLoader getClassLoader() {
- return classLoader;
+ return classLoader.get();
}
Map<Class<? extends ConfigurationParser<?>>, ParserContext> getParserContexts() {
@@ -22,6 +22,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.ref.WeakReference;
import java.util.ServiceLoader;
import javax.xml.namespace.QName;
@@ -43,12 +44,12 @@
*/
public class ParserRegistry {
private final XMLMapper xmlMapper;
- private final ClassLoader cl;
+ private final WeakReference<ClassLoader> cl;
public ParserRegistry(ClassLoader classLoader) {
xmlMapper = XMLMapper.Factory.create();
- this.cl = classLoader;
- ServiceLoader<ConfigurationParser> parsers = ServiceLoader.load(ConfigurationParser.class, cl);
+ this.cl = new WeakReference<ClassLoader>(classLoader);
+ ServiceLoader<ConfigurationParser> parsers = ServiceLoader.load(ConfigurationParser.class, cl.get());
for (ConfigurationParser<?> parser : parsers) {
for (Namespace ns : parser.getSupportedNamespaces()) {
xmlMapper.registerRootElement(new QName(ns.getUri(), ns.getRootElement()), parser);
@@ -58,7 +59,7 @@ public ParserRegistry(ClassLoader classLoader) {
public ConfigurationBuilderHolder parseFile(String filename) throws IOException {
FileLookup fileLookup = FileLookupFactory.newInstance();
- InputStream is = fileLookup.lookupFile(filename, cl);
+ InputStream is = fileLookup.lookupFile(filename, cl.get());
if(is==null) {
throw new FileNotFoundException(filename);
}
@@ -73,7 +74,7 @@ public ConfigurationBuilderHolder parse(InputStream is) {
try {
BufferedInputStream input = new BufferedInputStream(is);
XMLStreamReader streamReader = XMLInputFactory.newInstance().createXMLStreamReader(input);
- ConfigurationBuilderHolder holder = new ConfigurationBuilderHolder(cl);
+ ConfigurationBuilderHolder holder = new ConfigurationBuilderHolder(cl.get());
xmlMapper.parseDocument(holder, streamReader);
streamReader.close();
// Fire all parsingComplete events if any
@@ -27,6 +27,8 @@
import org.infinispan.context.InvocationContext;
import org.infinispan.remoting.transport.Address;
+import java.lang.ref.WeakReference;
+
/**
* Common features of transaction and invocation contexts
*
@@ -41,7 +43,7 @@
protected byte contextFlags = 0;
private Address origin;
// Class loader associated with this invocation which supports AdvancedCache.with() functionality
- private ClassLoader classLoader;
+ private WeakReference<ClassLoader> classLoader;
// if this or any context subclass ever needs to store a boolean, always use a context flag instead. This is far
// more space-efficient. Note that this value will be stored in a byte, which means up to 8 flags can be stored in
@@ -134,12 +136,12 @@ public AbstractInvocationContext clone() {
@Override
public ClassLoader getClassLoader() {
- return classLoader;
+ return classLoader.get();
}
@Override
public void setClassLoader(ClassLoader classLoader) {
- this.classLoader = classLoader;
+ this.classLoader = new WeakReference<ClassLoader>(classLoader);
}
@Override
@@ -41,6 +41,7 @@
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
+import java.lang.ref.WeakReference;
import java.util.Map;
import static org.infinispan.factories.KnownComponentNames.MODULE_COMMAND_INITIALIZERS;
@@ -64,7 +65,7 @@
private ResponseGenerator responseGenerator;
private CommandsFactory commandsFactory;
- protected final ClassLoader defaultClassLoader;
+ protected final WeakReference<ClassLoader> defaultClassLoader;
@Inject
public void setCacheManagerNotifier(CacheManagerNotifier cacheManagerNotifier) {
@@ -80,7 +81,7 @@ public void setCacheManagerNotifier(CacheManagerNotifier cacheManagerNotifier) {
*/
public ComponentRegistry(String cacheName, Configuration configuration, AdvancedCache<?, ?> cache,
GlobalComponentRegistry globalComponents, ClassLoader defaultClassLoader) {
- this.defaultClassLoader = defaultClassLoader;
+ this.defaultClassLoader = new WeakReference<ClassLoader>(defaultClassLoader);
try {
this.cacheName = cacheName;
if (cacheName == null) throw new ConfigurationException("Cache name cannot be null!");
@@ -50,6 +50,7 @@
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
+import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -96,7 +97,7 @@
final ConcurrentMap<String, ComponentRegistry> namedComponents = new ConcurrentHashMap<String, ComponentRegistry>(4);
- protected final ClassLoader defaultClassLoader;
+ protected final WeakReference<ClassLoader> defaultClassLoader;
/**
* Creates an instance of the component registry. The configuration passed in is automatically registered.
@@ -114,7 +115,7 @@ public GlobalComponentRegistry(GlobalConfiguration configuration,
// Load up the component metadata
componentMetadataRepo.initialize(moduleProperties.getModuleMetadataFiles(configuredClassLoader), configuredClassLoader);
- defaultClassLoader = registerDefaultClassLoader(configuredClassLoader);
+ defaultClassLoader = new WeakReference<ClassLoader>(registerDefaultClassLoader(configuredClassLoader));
try {
// this order is important ...
@@ -33,6 +33,8 @@
import org.infinispan.transaction.xa.recovery.RecoveryAdminOperations;
import org.infinispan.xsite.XSiteAdminOperations;
+import java.lang.ref.WeakReference;
+
/**
* An internal factory for constructing Caches. Used by the {@link DefaultCacheManager}, this is not intended as public
* API.
@@ -45,7 +47,7 @@
* @since 4.0
*/
public class InternalCacheFactory<K, V> extends AbstractNamedCacheComponentFactory {
- private ClassLoader defaultClassLoader;
+ private WeakReference<ClassLoader> defaultClassLoader;
/**
* This implementation clones the configuration passed in before using it.
@@ -89,7 +91,8 @@ private void bootstrap(String cacheName, AdvancedCache<?, ?> cache, Configuratio
this.configuration = configuration;
// injection bootstrap stuff
- componentRegistry = new ComponentRegistry(cacheName, configuration, cache, globalComponentRegistry, defaultClassLoader);
+ componentRegistry = new ComponentRegistry(cacheName, configuration, cache, globalComponentRegistry,
+ defaultClassLoader == null ? null : defaultClassLoader.get());
/*
--------------------------------------------------------------------------------------------------------------
@@ -116,7 +119,7 @@ private void bootstrap(String cacheName, AdvancedCache<?, ?> cache, Configuratio
* @param loader class loader to use as a default.
*/
public void setDefaultClassLoader(ClassLoader loader) {
- this.defaultClassLoader = loader;
+ this.defaultClassLoader = new WeakReference<ClassLoader>(loader);
}
@Override
@@ -21,6 +21,8 @@
import org.jboss.marshalling.ContextClassResolver;
+import java.lang.ref.WeakReference;
+
/**
* This class refines <code>ContextClassLoader</code> to add a default class loader
* in case the context class loader is <code>null</code>.
@@ -30,15 +32,15 @@
*/
public class DefaultContextClassResolver extends ContextClassResolver {
- private ClassLoader defaultClassLoader;
+ private WeakReference<ClassLoader> defaultClassLoader;
public DefaultContextClassResolver(ClassLoader defaultClassLoader) {
- this.defaultClassLoader = defaultClassLoader;
+ this.defaultClassLoader = new WeakReference<ClassLoader>(defaultClassLoader);
}
@Override
protected ClassLoader getClassLoader() {
ClassLoader loader = super.getClassLoader();
- return loader != null ? loader : defaultClassLoader;
+ return loader != null ? loader : defaultClassLoader.get();
}
}
Oops, something went wrong.

0 comments on commit 7889c2d

Please sign in to comment.