Author: dkuleshov
Date: 2012-03-20 09:45:55 -0400 (Tue, 20 Mar 2012)
New Revision: 5922
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/pom.xml
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/AbstractExoCache.java
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreator.java
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/distributed/DistributedExoCache.java
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/ispn/DistributedCacheManager.java
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/ispn/Utils.java
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/resources/conf/portal/cache-configuration-template.xml
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestAbstractExoCache.java
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheCreator.java
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/distributed/TestDistributedExoCache.java
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/cache-configuration-template.xml
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/distributed-cache-configuration-template.xml
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/distributed-cache-configuration.xml
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/test-configuration.xml
kernel/trunk/exo.kernel.component.ext.rpc.impl.jgroups.v3/pom.xml
kernel/trunk/pom.xml
Log:
EXOJCR-1739: ported EXOJCR-1682
Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/pom.xml
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/pom.xml 2012-03-20
11:47:42 UTC (rev 5921)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/pom.xml 2012-03-20
13:45:55 UTC (rev 5922)
@@ -24,13 +24,17 @@
<artifactId>exo.kernel.component.cache</artifactId>
</dependency>
<dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.component.common</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
</dependency>
<dependency>
<groupId>org.jgroups</groupId>
<artifactId>jgroups</artifactId>
- <version>3.0.0.Final</version>
+ <version>3.0.2.Final</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/AbstractExoCache.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/AbstractExoCache.java 2012-03-20
11:47:42 UTC (rev 5921)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/AbstractExoCache.java 2012-03-20
13:45:55 UTC (rev 5922)
@@ -62,7 +62,7 @@
/**
* Logger.
*/
- private static final Log LOG =
ExoLogger.getLogger("exo.kernel.component.ext.cache.impl.infinispan.v5.AbstractExoCache");
+ private static final Log LOG =
ExoLogger.getLogger("exo.kernel.component.ext.cache.impl.infinispan.v5.AbstractExoCache");
//NOSONAR
private final AtomicInteger hits = new AtomicInteger(0);
@@ -227,6 +227,11 @@
{
throw new IllegalArgumentException("No null cache key accepted");
}
+ else if (value == null)
+ {
+ // ignore null values
+ return;
+ }
SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
{
@@ -285,7 +290,7 @@
onPut(entry.getKey(), entry.getValue());
}
}
- catch (Exception e)
+ catch (Exception e) //NOSONAR
{
cache.endBatch(false);
LOG.warn("An error occurs while executing the putMap method",
e);
@@ -416,7 +421,7 @@
{
context.onExpire(key, obj);
}
- catch (Exception e)
+ catch (Exception e)//NOSONAR
{
if (LOG.isWarnEnabled())
LOG.warn("Cannot execute the CacheListener properly", e);
@@ -436,7 +441,7 @@
{
context.onRemove(key, obj);
}
- catch (Exception e)
+ catch (Exception e)//NOSONAR
{
if (LOG.isWarnEnabled())
LOG.warn("Cannot execute the CacheListener properly", e);
@@ -455,7 +460,7 @@
{
context.onPut(key, obj);
}
- catch (Exception e)
+ catch (Exception e)//NOSONAR
{
if (LOG.isWarnEnabled())
LOG.warn("Cannot execute the CacheListener properly", e);
@@ -473,7 +478,7 @@
{
context.onGet(key, obj);
}
- catch (Exception e)
+ catch (Exception e)//NOSONAR
{
if (LOG.isWarnEnabled())
LOG.warn("Cannot execute the CacheListener properly", e);
@@ -491,7 +496,7 @@
{
context.onClearCache();
}
- catch (Exception e)
+ catch (Exception e)//NOSONAR
{
if (LOG.isWarnEnabled())
LOG.warn("Cannot execute the CacheListener properly", e);
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreator.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreator.java 2012-03-20
11:47:42 UTC (rev 5921)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheCreator.java 2012-03-20
13:45:55 UTC (rev 5922)
@@ -22,7 +22,7 @@
import org.exoplatform.services.cache.ExoCacheConfig;
import org.exoplatform.services.cache.ExoCacheInitException;
import org.infinispan.Cache;
-import org.infinispan.config.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
import java.io.Serializable;
import java.util.Set;
@@ -41,11 +41,11 @@
/**
* Creates an eXo cache according to the given configuration {@link
org.exoplatform.services.cache.ExoCacheConfig}
* @param config the configuration of the cache to apply
- * @param cacheConfig the configuration of the infinispan cache
+ * @param confBuilder the configuration builder of the infinispan cache
* @param cacheGetter a {@link Callable} instance from which we can get the cache
* @exception ExoCacheInitException if an exception happens while initializing the
cache
*/
- public ExoCache<Serializable, Object> create(ExoCacheConfig config,
Configuration cacheConfig,
+ public ExoCache<Serializable, Object> create(ExoCacheConfig config,
ConfigurationBuilder confBuilder,
Callable<Cache<Serializable, Object>> cacheGetter) throws
ExoCacheInitException;
/**
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java 2012-03-20
11:47:42 UTC (rev 5921)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java 2012-03-20
13:45:55 UTC (rev 5922)
@@ -34,12 +34,19 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.infinispan.Cache;
-import org.infinispan.config.Configuration;
-import org.infinispan.config.Configuration.CacheMode;
-import org.infinispan.config.GlobalConfiguration;
+import org.infinispan.configuration.cache.CacheMode;
+import org.infinispan.configuration.cache.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
+import org.infinispan.configuration.global.GlobalConfiguration;
+import org.infinispan.configuration.global.GlobalConfigurationBuilder;
+import org.infinispan.configuration.parsing.ConfigurationBuilderHolder;
+import org.infinispan.configuration.parsing.Parser;
+import org.infinispan.distribution.ch.ConsistentHash;
+import org.infinispan.distribution.ch.DefaultConsistentHash;
import org.infinispan.eviction.EvictionStrategy;
import org.infinispan.jmx.MBeanServerLookup;
import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.util.Util;
import java.io.InputStream;
import java.io.Serializable;
@@ -67,8 +74,8 @@
/**
* The logger
*/
- private static final Log LOG = ExoLogger
-
.getLogger("exo.kernel.component.ext.cache.impl.infinispan.v5.ExoCacheFactoryImpl");
+ private static final Log LOG = ExoLogger //NOSONAR
+
.getLogger("exo.kernel.component.ext.cache.impl.infinispan.v5.ExoCacheFactoryImpl");//NOSONAR
/**
* The initial parameter key that defines the full path of the configuration template
@@ -113,10 +120,10 @@
private final Map<String, String> mappingCacheNameConfig = new
HashMap<String, String>();
/**
- * The mapping between the global configuration and the cache managers
+ * The mapping between the cluster name and the cache managers
*/
- private final Map<GlobalConfiguration, DefaultCacheManager>
mappingGlobalConfigCacheManager =
- new HashMap<GlobalConfiguration, DefaultCacheManager>();
+ private final Map<String, DefaultCacheManager> mappingGlobalConfigCacheManager
=
+ new HashMap<String, DefaultCacheManager>();
/**
* The default creator
@@ -157,12 +164,13 @@
this.configManager = configManager;
if (cacheConfigTemplate == null)
{
- throw new RuntimeException("The parameter '" +
CACHE_CONFIG_TEMPLATE_KEY + "' must be set");
+ throw new IllegalArgumentException("The parameter '" +
CACHE_CONFIG_TEMPLATE_KEY + "' must be set");
}
// Initialize the main cache manager
this.cacheManager = initCacheManager(cacheConfigTemplate);
// Register the main cache manager
- mappingGlobalConfigCacheManager.put(cacheManager.getGlobalConfiguration(),
cacheManager);
+
mappingGlobalConfigCacheManager.put(cacheManager.getCacheManagerConfiguration().transport().clusterName(),
+ cacheManager);
}
/**
@@ -183,7 +191,7 @@
// Read the configuration file of the cache
is = configManager.getInputStream(cacheConfigTemplate);
}
- catch (Exception e)
+ catch (Exception e)//NOSONAR
{
throw new ExoCacheInitException("The configuration of the
CacheManager cannot be loaded from '"
+ cacheConfigTemplate + "'", e);
@@ -193,24 +201,32 @@
throw new ExoCacheInitException("The configuration of the
CacheManager cannot be found at '"
+ cacheConfigTemplate + "'");
}
- DefaultCacheManager cacheManager = null;
+ GlobalConfigurationBuilder configBuilder;
+ Configuration config;
try
{
- // Create the CacheManager from the input stream
- cacheManager = new DefaultCacheManager(is, false);
+ Parser parser = new
Parser(Thread.currentThread().getContextClassLoader());
+ // Loads the configuration from the input stream
+ ConfigurationBuilderHolder holder = parser.parse(is);
+ configBuilder = holder.getGlobalConfigurationBuilder();
+ config = holder.getDefaultConfigurationBuilder().build();
}
- catch (Exception e)
+ catch (RuntimeException e) //NOSONAR
{
+ throw new ExoCacheInitException("Cannot parse the configuration
'" + cacheConfigTemplate + "'", e);
+ }
+ configureCacheManager(configBuilder);
+ try
+ {
+ // Create the CacheManager from the new configuration
+ return new DefaultCacheManager(configBuilder.build(), config);
+ }
+ catch (RuntimeException e) //NOSONAR
+ {
throw new ExoCacheInitException(
"Cannot initialize the CacheManager corresponding to the
configuration '" + cacheConfigTemplate
+ "'", e);
}
-
- GlobalConfiguration config = cacheManager.getGlobalConfiguration();
-
- configureCacheManager(config);
- cacheManager.start();
- return cacheManager;
}
});
}
@@ -219,7 +235,7 @@
Throwable cause = e.getCause();
if (cause instanceof ExoCacheInitException)
{
- throw (ExoCacheInitException)cause;
+ throw (ExoCacheInitException)cause;//NOSONAR
}
else
{
@@ -231,16 +247,18 @@
/**
* Configure the cache manager
*
- * @param config
+ * @param configBuilder the configuration builder on which we applied all the required
changes
* @throws ExoCacheInitException
*/
- private void configureCacheManager(GlobalConfiguration config) throws
ExoCacheInitException
+ private void configureCacheManager(GlobalConfigurationBuilder configBuilder) throws
ExoCacheInitException
{
+ GlobalConfiguration config = configBuilder.build();
// Configure JGroups
- configureJGroups(config);
+ configureJGroups(config, configBuilder);
// Configure the name of the cache manager
- config.fluent().globalJmxStatistics().cacheManagerName(config.getCacheManagerName()
+ "_" + ctx.getName()).
- // Configure the MBeanServerLookup
+ configBuilder.globalJmxStatistics().enable()
+ .cacheManagerName(config.globalJmxStatistics().cacheManagerName() +
"_" + ctx.getName()).
+ // Configure the MBeanServerLookup
mBeanServerLookup(MBEAN_SERVER_LOOKUP);
}
@@ -249,27 +267,31 @@
* the cluster name by adding as suffix the name of the {@link ExoContainerContext}
*
* @param config the global configuration from which the JGroups config will be
extracted
+ * @param configBuilder the related configuration builder
* @throws ExoCacheInitException if any exception occurs while configuring JGroups
*/
- private void configureJGroups(GlobalConfiguration config) throws
ExoCacheInitException
+ private void configureJGroups(GlobalConfiguration config, GlobalConfigurationBuilder
configBuilder)
+ throws ExoCacheInitException
{
- if (loadJGroupsConfig(config))
+ if (loadJGroupsConfig(config, configBuilder))
{
// The JGroups Config could be loaded which means that the configuration is for
a cluster
- config.fluent().transport().clusterName(config.getClusterName() + "-"
+ ctx.getName());
+ configBuilder.transport().clusterName(config.transport().clusterName() +
"-" + ctx.getName());
}
}
/**
* Load the JGroups configuration file thanks to the {@link ConfigurationManager}
* @param config the global configuration from which the JGroups config will be
extracted
+ * @param configBuilder the related configuration builder
* @return <code>true</code> if the JGoups config could be loaded
successfully,
* <code>false</code> if there were no JGroups config to load
* @throws ExoCacheInitException if the JGroups config could not be loaded
*/
- private boolean loadJGroupsConfig(GlobalConfiguration config) throws
ExoCacheInitException
+ private boolean loadJGroupsConfig(GlobalConfiguration config,
GlobalConfigurationBuilder configBuilder)
+ throws ExoCacheInitException
{
- return Utils.loadJGroupsConfig(configManager, config);
+ return Utils.loadJGroupsConfig(configManager, config, configBuilder);
}
/**
@@ -289,7 +311,7 @@
final DefaultCacheManager cacheManager;
try
{
- final Configuration conf;
+ final ConfigurationBuilder confBuilder = new ConfigurationBuilder();
if (customConfig != null)
{
try
@@ -302,24 +324,34 @@
// A custom configuration has been set
if (LOG.isInfoEnabled())
LOG.info("A custom configuration has been set for the
cache '" + region + "'.");
- // Create the CacheManager by loading the configuration
- DefaultCacheManager customCacheManager =
- new
DefaultCacheManager(configManager.getInputStream(customConfig), false);
- GlobalConfiguration gc =
customCacheManager.getGlobalConfiguration();
+ Parser parser = new
Parser(Thread.currentThread().getContextClassLoader());
+ // Load the configuration
+ ConfigurationBuilderHolder holder =
parser.parse(configManager.getInputStream(customConfig));
+ GlobalConfigurationBuilder configBuilder =
holder.getGlobalConfigurationBuilder();
// Configure JGroups and JMX since it could affect the state of
the Global Config
- configureCacheManager(gc);
+ configureCacheManager(configBuilder);
+ GlobalConfiguration gc = configBuilder.build();
+
// Check if a CacheManager with the same GlobalConfiguration
exists
- DefaultCacheManager currentCacheManager =
mappingGlobalConfigCacheManager.get(gc);
+ DefaultCacheManager currentCacheManager =
+
mappingGlobalConfigCacheManager.get(gc.transport().clusterName());
if (currentCacheManager == null)
{
+ // Use a different cache manager name to prevent naming
conflict
+ configBuilder.globalJmxStatistics().cacheManagerName(
+ gc.globalJmxStatistics().cacheManagerName() + "_"
+ region + "_" + ctx.getName());
// No cache manager has been defined so far for this Cache
Configuration
- currentCacheManager = customCacheManager;
- // Use a different cache manager name to prevent naming
conflict
- gc.fluent().globalJmxStatistics()
- .cacheManagerName(gc.getCacheManagerName() + "_"
+ region + "_" + ctx.getName());
+ currentCacheManager =
+ new DefaultCacheManager(configBuilder.build(),
holder.getDefaultConfigurationBuilder()
+ .build(), false);
+ for (ConfigurationBuilder b :
holder.getConfigurationBuilders())
+ {
+ Configuration c = b.build();
+ currentCacheManager.defineConfiguration(c.name(), c);
+ }
currentCacheManager.start();
// We register this new cache manager
- mappingGlobalConfigCacheManager.put(gc, customCacheManager);
+
mappingGlobalConfigCacheManager.put(gc.transport().clusterName(), currentCacheManager);
}
return currentCacheManager;
}
@@ -330,14 +362,23 @@
Throwable cause = e.getCause();
if (cause instanceof Exception)
{
- throw (Exception)cause;
+ throw (Exception)cause;//NOSONAR
}
else
{
throw new Exception(e);
}
}
- conf = cacheManager.getDefaultConfiguration().clone();
+ confBuilder.read(cacheManager.getDefaultCacheConfiguration());
+ //TODO remove it once ISPN-1687 will be fixed
+ confBuilder.storeAsBinary().enabled(false);
+ //TODO remove it once ISPN-1689 will be fixed
+ confBuilder
+ .clustering()
+ .hash()
+ .consistentHash(
+ Util.<ConsistentHash>
getInstance(DefaultConsistentHash.class.getName(), Thread.currentThread()
+ .getContextClassLoader()));
}
else if (config.isDistributed())
{
@@ -357,20 +398,28 @@
// No custom configuration has been found, a configuration template will be
used
if (LOG.isInfoEnabled())
LOG.info("The configuration template will be used for the the cache
'" + region + "'.");
- conf = cacheManager.getDefaultConfiguration().clone();
+ confBuilder.read(cacheManager.getDefaultCacheConfiguration());
+ //TODO remove it once ISPN-1687 will be fixed
+ confBuilder.storeAsBinary().enabled(false);
+ //TODO remove it once ISPN-1689 will be fixed
+ confBuilder
+ .clustering()
+ .hash()
+ .consistentHash(
+ Util.<ConsistentHash>
getInstance(DefaultConsistentHash.class.getName(), Thread.currentThread()
+ .getContextClassLoader()));
if (!config.isRepicated())
{
// The cache is local
- conf.fluent().clustering().mode(CacheMode.LOCAL);
+ confBuilder.clustering().cacheMode(CacheMode.LOCAL);
}
}
// Reset the configuration to avoid conflicts
- resetConfiguration(conf);
+ resetConfiguration(confBuilder);
final ExoCacheCreator creator = getExoCacheCreator(config);
// Create the cache
- eXoCache = creator.create(config, conf, new Callable<Cache<Serializable,
Object>>()
+ eXoCache = creator.create(config, confBuilder, new
Callable<Cache<Serializable, Object>>()
{
- @Override
public Cache<Serializable, Object> call() throws Exception
{
try
@@ -381,7 +430,7 @@
public Cache<Serializable, Object> run() throws Exception
{
// Define the configuration
- cacheManager.defineConfiguration(region, conf);
+ cacheManager.defineConfiguration(region,
confBuilder.build());
// create and start the cache
return cacheManager.getCache(region);
}
@@ -392,7 +441,7 @@
Throwable cause = e.getCause();
if (cause instanceof Exception)
{
- throw (Exception)cause;
+ throw (Exception)cause;//NOSONAR
}
else
{
@@ -402,7 +451,7 @@
}
});
}
- catch (Exception e)
+ catch (Exception e) //NOSONAR
{
throw new ExoCacheInitException("The cache '" + region +
"' could not be initialized", e);
}
@@ -486,9 +535,9 @@
/**
* Clean the configuration template to prevent conflicts
*/
- protected void resetConfiguration(Configuration config)
+ protected void resetConfiguration(ConfigurationBuilder confBuilder)
{
-
config.fluent().invocationBatching().eviction().strategy(EvictionStrategy.NONE).maxEntries(-1).expiration()
+
confBuilder.invocationBatching().enable().eviction().strategy(EvictionStrategy.NONE).maxEntries(-1).expiration()
.lifespan(-1L).maxIdle(-1L).wakeUpInterval(60000L);
}
}
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/distributed/DistributedExoCache.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/distributed/DistributedExoCache.java 2012-03-20
11:47:42 UTC (rev 5921)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/distributed/DistributedExoCache.java 2012-03-20
13:45:55 UTC (rev 5922)
@@ -48,7 +48,6 @@
import org.infinispan.notifications.cachelistener.event.CacheEntriesEvictedEvent;
import org.infinispan.notifications.cachelistener.event.CacheEntryModifiedEvent;
import org.infinispan.notifications.cachelistener.event.CacheEntryRemovedEvent;
-import org.infinispan.util.concurrent.locks.LockManager;
import java.io.Externalizable;
import java.io.IOException;
@@ -58,12 +57,9 @@
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -80,8 +76,8 @@
/**
* Logger.
*/
- private static final Log LOG = ExoLogger
-
.getLogger("exo.kernel.component.ext.cache.impl.infinispan.v5.DistributedExoCache");
+ private static final Log LOG = ExoLogger//NOSONAR
+
.getLogger("exo.kernel.component.ext.cache.impl.infinispan.v5.DistributedExoCache");//NOSONAR
public static final String CACHE_NAME = "eXoCache";
@@ -123,6 +119,14 @@
{
return cache;
}
+
+ /**
+ * @return the fullName
+ */
+ String getFullName()
+ {
+ return fullName;
+ }
/**
* {@inheritDoc}
@@ -199,9 +203,9 @@
@Override
public Void run()
{
- MapReduceTask<CacheKey<K>, V, String, CacheKey<K>> task =
- new MapReduceTask<CacheKey<K>, V, String,
CacheKey<K>>(cache);
- task.mappedWith(new ClearCacheMapper<K, V>(fullName)).reducedWith(new
ClearCacheReducer<String, V, K>());
+ MapReduceTask<CacheKey<K>, V, Void, Void> task =
+ new MapReduceTask<CacheKey<K>, V, Void, Void>(cache);
+ task.mappedWith(new ClearCacheMapper<K, V>(fullName)).reducedWith(new
ClearCacheReducer());
task.execute();
return null;
}
@@ -362,6 +366,11 @@
{
throw new IllegalArgumentException("No null cache key accepted");
}
+ else if (value == null)
+ {
+ // ignore null values
+ return;
+ }
SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
{
@@ -421,7 +430,7 @@
onPut(entry.getKey(), entry.getValue());
}
}
- catch (Exception e)
+ catch (Exception e)//NOSONAR
{
cache.endBatch(false);
LOG.warn("An error occurs while executing the putMap method",
e);
@@ -561,7 +570,7 @@
{
context.onExpire(key.getKey(), obj);
}
- catch (Exception e)
+ catch (Exception e)//NOSONAR
{
if (LOG.isWarnEnabled())
LOG.warn("Cannot execute the CacheListener properly", e);
@@ -583,7 +592,7 @@
{
context.onRemove(key, obj);
}
- catch (Exception e)
+ catch (Exception e)//NOSONAR
{
if (LOG.isWarnEnabled())
LOG.warn("Cannot execute the CacheListener properly", e);
@@ -615,7 +624,7 @@
{
context.onPut(key, obj);
}
- catch (Exception e)
+ catch (Exception e)//NOSONAR
{
if (LOG.isWarnEnabled())
LOG.warn("Cannot execute the CacheListener properly", e);
@@ -637,7 +646,7 @@
{
context.onGet(key, obj);
}
- catch (Exception e)
+ catch (Exception e)//NOSONAR
{
if (LOG.isWarnEnabled())
LOG.warn("Cannot execute the CacheListener properly", e);
@@ -659,7 +668,7 @@
{
context.onClearCache();
}
- catch (Exception e)
+ catch (Exception e)//NOSONAR
{
if (LOG.isWarnEnabled())
LOG.warn("Cannot execute the CacheListener properly", e);
@@ -790,7 +799,7 @@
@ManagedDescription("Maximum number of entries in a cache instance. -1 means no
limit.")
public int getMaxSize()
{
- return cache.getConfiguration().getEvictionMaxEntries();
+ return cache.getCacheConfiguration().eviction().maxEntries();
}
@ManagedName("Lifespan")
@@ -798,7 +807,7 @@
+ " -1 means the entries never expire.")
public long getLiveTime()
{
- return cache.getConfiguration().getExpirationLifespan();
+ return cache.getCacheConfiguration().expiration().lifespan();
}
@Managed
@@ -807,7 +816,7 @@
+ "If the idle time is exceeded, the entry will be expired cluster-wide. -1
means the entries never expire.")
public long getMaxIdle()
{
- return cache.getConfiguration().getExpirationMaxIdle();
+ return cache.getCacheConfiguration().expiration().maxIdle();
}
@Managed
@@ -816,7 +825,7 @@
+ "process altogether, set wakeupInterval to -1.")
public long getWakeUpInterval()
{
- return cache.getConfiguration().getExpirationWakeUpInterval();
+ return cache.getCacheConfiguration().expiration().wakeUpInterval();
}
public static class CacheKey<K> implements Externalizable
@@ -1074,7 +1083,7 @@
}
}
- public static class ClearCacheMapper<K, V> extends AbstractExoCacheMapper<K,
V, String, CacheKey<K>>
+ public static class ClearCacheMapper<K, V> extends AbstractExoCacheMapper<K,
V, Void, Void>
{
public ClearCacheMapper()
@@ -1090,14 +1099,27 @@
* {@inheritDoc}
*/
@Override
- protected void _map(CacheKey<K> key, V value, Collector<String,
CacheKey<K>> collector)
+ protected void _map(CacheKey<K> key, V value, Collector<Void, Void>
collector)
{
- collector.emit("keys", key);
+ ExoContainer container = ExoContainerContext.getTopContainer();
+ if (container == null)
+ {
+ LOG.error("The top container could not be found");
+ return;
+ }
+ DistributedCacheManager dcm =
+
(DistributedCacheManager)container.getComponentInstanceOfType(DistributedCacheManager.class);
+ if (dcm == null)
+ {
+ LOG.error("The DistributedCacheManager could not be found at top
container level, please configure it.");
+ return;
+ }
+ Cache<CacheKey<K>, V> cache = dcm.getCache(CACHE_NAME);
+ cache.getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP,
Flag.FAIL_SILENTLY).remove(key);
}
-
}
- public static class ClearCacheReducer<K, V, KIn> implements Reducer<K,
CacheKey<KIn>>
+ public static class ClearCacheReducer implements Reducer<Void, Void>
{
/**
@@ -1109,46 +1131,8 @@
* @see org.infinispan.distexec.mapreduce.Reducer#reduce(java.lang.Object,
java.util.Iterator)
*/
@Override
- public CacheKey<KIn> reduce(K reducedKey, Iterator<CacheKey<KIn>>
iter)
+ public Void reduce(Void reducedKey, Iterator<Void> iter)
{
- CacheKey<KIn> firstKey;
- if (iter == null || !iter.hasNext() || (firstKey = iter.next()) == null)
- {
- return null;
- }
- ExoContainer container = ExoContainerContext.getTopContainer();
- if (container == null)
- {
- LOG.error("The top container could not be found");
- return null;
- }
- DistributedCacheManager dcm =
-
(DistributedCacheManager)container.getComponentInstanceOfType(DistributedCacheManager.class);
- if (dcm == null)
- {
- LOG.error("The DistributedCacheManager could not be found at top
container level, please configure it.");
- return null;
- }
- Cache<CacheKey<K>, V> cache = dcm.getCache(CACHE_NAME);
- final LockManager lm = cache.getAdvancedCache().getLockManager();
- // Sort the keys to prevent deadlocks
- Set<CacheKey<KIn>> keys = new TreeSet<CacheKey<KIn>>(new
Comparator<CacheKey<KIn>>()
- {
- public int compare(CacheKey<KIn> o1, CacheKey<KIn> o2)
- {
- int result = lm.getLockId(o1) - lm.getLockId(o2);
- return result == 0 ? System.identityHashCode(o1) -
System.identityHashCode(o2) : result;
- }
- });
- keys.add(firstKey);
- while (iter.hasNext())
- {
- keys.add(iter.next());
- }
- for (CacheKey<KIn> key : keys)
- {
- cache.getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP,
Flag.FAIL_SILENTLY).remove(key);
- }
return null;
}
}
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java 2012-03-20
11:47:42 UTC (rev 5921)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/cache/impl/infinispan/generic/GenericExoCacheCreator.java 2012-03-20
13:45:55 UTC (rev 5922)
@@ -27,7 +27,7 @@
import org.exoplatform.services.cache.impl.infinispan.AbstractExoCache;
import org.exoplatform.services.cache.impl.infinispan.ExoCacheCreator;
import org.infinispan.Cache;
-import org.infinispan.config.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.eviction.EvictionStrategy;
import java.io.Serializable;
@@ -84,20 +84,20 @@
/**
* {@inheritDoc}
*/
- public ExoCache<Serializable, Object> create(ExoCacheConfig config,
Configuration cacheConfig,
+ public ExoCache<Serializable, Object> create(ExoCacheConfig config,
ConfigurationBuilder confBuilder,
Callable<Cache<Serializable, Object>> cacheGetter) throws
ExoCacheInitException
{
if (config instanceof GenericExoCacheConfig)
{
final GenericExoCacheConfig gConfig = (GenericExoCacheConfig)config;
- return create(config, cacheConfig, cacheGetter, gConfig.getStrategy(),
gConfig.getMaxEntries(),
+ return create(config, confBuilder, cacheGetter, gConfig.getStrategy(),
gConfig.getMaxEntries(),
gConfig.getLifespan(), gConfig.getMaxIdle() == 0 ? defaultMaxIdle :
gConfig.getMaxIdle(),
gConfig.getWakeUpInterval() == 0 ? defaultWakeUpInterval :
gConfig.getWakeUpInterval());
}
else
{
final long period = config.getLiveTime();
- return create(config, cacheConfig, cacheGetter,
+ return create(config, confBuilder, cacheGetter,
config.getImplementation() == null ? defaultStrategy :
config.getImplementation(), config.getMaxSize(),
period > 0 ? period * 1000 : -1, defaultMaxIdle, defaultWakeUpInterval);
}
@@ -107,7 +107,7 @@
* Creates a new ExoCache instance with the relevant parameters
* @throws ExoCacheInitException If any exception occurs while creating the cache
*/
- private ExoCache<Serializable, Object> create(ExoCacheConfig config,
Configuration cacheConfig,
+ private ExoCache<Serializable, Object> create(ExoCacheConfig config,
ConfigurationBuilder confBuilder,
Callable<Cache<Serializable, Object>> cacheGetter, String strategy, int
maxEntries, long lifespan, long maxIdle,
long wakeUpInterval) throws ExoCacheInitException
{
@@ -118,13 +118,13 @@
{
es = EvictionStrategy.LRU;
}
-
cacheConfig.fluent().eviction().strategy(EvictionStrategy.valueOf(strategy)).maxEntries(maxEntries).expiration()
+
confBuilder.eviction().strategy(EvictionStrategy.valueOf(strategy)).maxEntries(maxEntries).expiration()
.lifespan(lifespan).maxIdle(maxIdle).wakeUpInterval(wakeUpInterval);
try
{
- return new GenericExoCache(cacheConfig, config, cacheGetter.call());
+ return new GenericExoCache(config, cacheGetter.call());
}
- catch (Exception e)
+ catch (Exception e)//NOSONAR
{
throw new ExoCacheInitException("Cannot create the cache '" +
config.getName() + "'", e);
}
@@ -136,41 +136,26 @@
public static class GenericExoCache extends AbstractExoCache<Serializable,
Object>
{
- private final Configuration cacheConfig;
-
- public GenericExoCache(Configuration cacheConfig, ExoCacheConfig config,
Cache<Serializable, Object> cache)
+ public GenericExoCache(ExoCacheConfig config, Cache<Serializable, Object>
cache)
{
super(config, cache);
- this.cacheConfig = cacheConfig;
}
public void setMaxSize(int max)
{
- cacheConfig.fluent().eviction().maxEntries(max);
+ throw new UnsupportedOperationException("The configuration of the cache
cannot not be modified");
}
public void setLiveTime(long period)
{
- cacheConfig.fluent().expiration().lifespan(period);
+ throw new UnsupportedOperationException("The configuration of the cache
cannot not be modified");
}
- @Managed
- public void setMaxIdle(long maxIdle)
- {
- cacheConfig.fluent().expiration().maxIdle(maxIdle);
- }
-
- @Managed
- public void setWakeUpInterval(long wakeUpInterval)
- {
- cacheConfig.fluent().expiration().wakeUpInterval(wakeUpInterval);
- }
-
@ManagedName("MaxEntries")
@ManagedDescription("Maximum number of entries in a cache instance. -1 means
no limit.")
public int getMaxSize()
{
- return cacheConfig.getEvictionMaxEntries();
+ return cache.getCacheConfiguration().eviction().maxEntries();
}
@ManagedName("Lifespan")
@@ -178,7 +163,7 @@
+ " -1 means the entries never expire.")
public long getLiveTime()
{
- return cacheConfig.getExpirationLifespan();
+ return cache.getCacheConfiguration().expiration().lifespan();
}
@Managed
@@ -187,7 +172,7 @@
+ "If the idle time is exceeded, the entry will be expired cluster-wide. -1
means the entries never expire.")
public long getMaxIdle()
{
- return cacheConfig.getExpirationMaxIdle();
+ return cache.getCacheConfiguration().expiration().maxIdle();
}
@Managed
@@ -196,7 +181,7 @@
+ "process altogether, set wakeupInterval to -1.")
public long getWakeUpInterval()
{
- return cacheConfig.getExpirationWakeUpInterval();
+ return cache.getCacheConfiguration().expiration().wakeUpInterval();
}
}
}
\ No newline at end of file
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/ispn/DistributedCacheManager.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/ispn/DistributedCacheManager.java 2012-03-20
11:47:42 UTC (rev 5921)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/ispn/DistributedCacheManager.java 2012-03-20
13:45:55 UTC (rev 5922)
@@ -27,14 +27,26 @@
import org.exoplatform.container.xml.ValueParam;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import org.exoplatform.services.transaction.TransactionService;
import org.infinispan.Cache;
+import org.infinispan.configuration.cache.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
+import org.infinispan.configuration.global.GlobalConfigurationBuilder;
+import org.infinispan.configuration.parsing.ConfigurationBuilderHolder;
+import org.infinispan.configuration.parsing.Parser;
+import org.infinispan.distribution.ch.ConsistentHash;
+import org.infinispan.distribution.ch.DefaultConsistentHash;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.transaction.lookup.TransactionManagerLookup;
+import org.infinispan.util.Util;
import org.picocontainer.Startable;
import java.security.PrivilegedExceptionAction;
import java.util.Map;
+import javax.transaction.TransactionManager;
+
/**
* This class is used to allow to use infinispan in distribution mode with
* the ability to launch infinispan instances in standalone mode, in other
@@ -52,8 +64,8 @@
/**
* The logger
*/
- private static final Log LOG = ExoLogger
-
.getLogger("exo.kernel.component.ext.cache.impl.infinispan.v5.DistributedCacheManager");
+ private static final Log LOG = ExoLogger //NOSONAR
+
.getLogger("exo.kernel.component.ext.cache.impl.infinispan.v5.DistributedCacheManager");//NOSONAR
/**
* The parameter name corresponding to the infinispan configuration
@@ -77,7 +89,7 @@
public DistributedCacheManager(String configurationFile, Map<String, String>
parameters,
ConfigurationManager configManager)
{
- this.manager = init(configurationFile, parameters, configManager);
+ this.manager = init(configurationFile, parameters, configManager, null);
}
/**
@@ -85,13 +97,23 @@
*/
public DistributedCacheManager(InitParams params, ConfigurationManager configManager)
{
+ this(params, configManager, null);
+ }
+
+ /**
+ * Default constructor
+ */
+ public DistributedCacheManager(InitParams params, ConfigurationManager configManager,
TransactionService ts)
+ {
ValueParam vp;
final String result;
if (params != null && (vp =
params.getValueParam(CONFIG_FILE_PARAMETER_NAME)) != null
&& (result = vp.getValue()) != null && !result.isEmpty())
{
PropertiesParam pp = params.getPropertiesParam(PARAMS_PARAMETER_NAME);
- this.manager = init(result, pp == null ? null : pp.getProperties(),
configManager);
+ this.manager =
+ init(result, pp == null ? null : pp.getProperties(), configManager,
+ ts == null ? null : ts.getTransactionManager());
}
else
{
@@ -104,10 +126,11 @@
* @param configurationFile the path of the configuration file
* @param parameters the parameters to inject into the configuration file
* @param configManager the configuration manager used to get the configuration file
+ * @param tm the transaction manager
* @return the CacheManager initialized
*/
private EmbeddedCacheManager init(final String configurationFile, final Map<String,
String> parameters,
- final ConfigurationManager configManager)
+ final ConfigurationManager configManager, final TransactionManager tm)
{
try
{
@@ -128,25 +151,46 @@
}
return SecurityHelper.doPrivilegedIOExceptionAction(new
PrivilegedExceptionAction<EmbeddedCacheManager>()
{
-
- @Override
public EmbeddedCacheManager run() throws Exception
{
+ Parser parser = new
Parser(Thread.currentThread().getContextClassLoader());
+ // Load the configuration
+ ConfigurationBuilderHolder holder =
parser.parse(helper.fillTemplate(configurationFile, parameters));
+ GlobalConfigurationBuilder configBuilder =
holder.getGlobalConfigurationBuilder();
+ Utils.loadJGroupsConfig(configManager, configBuilder.build(),
configBuilder);
+ // Create the CacheManager from the new configuration
EmbeddedCacheManager manager =
- new DefaultCacheManager(helper.fillTemplate(configurationFile,
parameters), false);
- Utils.loadJGroupsConfig(configManager, manager.getGlobalConfiguration());
- manager.start();
- for (String cacheName : manager.getCacheNames())
+ new DefaultCacheManager(configBuilder.build(),
holder.getDefaultConfigurationBuilder().build());
+ TransactionManagerLookup tml = new TransactionManagerLookup()
{
- manager.getCache(cacheName);
+ public TransactionManager getTransactionManager() throws Exception
+ {
+ return tm;
+ }
+ };
+ for (ConfigurationBuilder b : holder.getConfigurationBuilders())
+ {
+ if (tm != null)
+ {
+ b.transaction().transactionManagerLookup(tml);
+ }
+ //TODO remove it once ISPN-1689 will be fixed
+ b.clustering()
+ .hash()
+ .consistentHash(
+ Util.<ConsistentHash>
getInstance(DefaultConsistentHash.class.getName(), Thread.currentThread()
+ .getContextClassLoader()));
+ Configuration c = b.build();
+ manager.defineConfiguration(c.name(), c);
+ manager.getCache(c.name());
}
return manager;
}
});
}
- catch (Exception e)
+ catch (Exception e)//NOSONAR
{
- throw new RuntimeException("Could not initialize the cache manager
corresponding to the configuration file "
+ throw new IllegalStateException("Could not initialize the cache manager
corresponding to the configuration file "
+ configurationFile, e);
}
}
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/ispn/Utils.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/ispn/Utils.java 2012-03-20
11:47:42 UTC (rev 5921)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/java/org/exoplatform/services/ispn/Utils.java 2012-03-20
13:45:55 UTC (rev 5922)
@@ -23,7 +23,8 @@
import org.exoplatform.services.cache.ExoCacheInitException;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
-import org.infinispan.config.GlobalConfiguration;
+import org.infinispan.configuration.global.GlobalConfiguration;
+import org.infinispan.configuration.global.GlobalConfigurationBuilder;
import org.infinispan.remoting.transport.jgroups.JGroupsTransport;
import java.io.IOException;
@@ -41,22 +42,24 @@
/**
* The logger
*/
- private static final Log LOG = ExoLogger
- .getLogger("exo.kernel.component.ext.cache.impl.infinispan.v5.Utils");
-
- private Utils() {}
-
+ private static final Log LOG =
ExoLogger.getLogger("exo.kernel.component.ext.cache.impl.infinispan.v5.Utils");//NOSONAR
+ private Utils()
+ {
+ }
+
/**
* Load the JGroups configuration file thanks to the {@link ConfigurationManager}
* @param config the global configuration from which the JGroups config will be
extracted
+ * @param configBuilder the related configuration builder
* @return <code>true</code> if the JGoups config could be loaded
successfully,
* <code>false</code> if there were no JGroups config to load
* @throws IllegalStateException if the JGroups config could not be loaded
*/
- public static boolean loadJGroupsConfig(ConfigurationManager cfm, GlobalConfiguration
config) throws ExoCacheInitException
+ public static boolean loadJGroupsConfig(ConfigurationManager cfm, GlobalConfiguration
config,
+ GlobalConfigurationBuilder configBuilder) throws ExoCacheInitException
{
- Properties properties = config.getTransportProperties();
+ Properties properties = config.transport().properties();
if (properties == null ||
!properties.containsKey(JGroupsTransport.CONFIGURATION_FILE))
{
return false;
@@ -67,9 +70,8 @@
// inputStream still remains null, so file was not opened
if (inputStream == null)
{
- throw new IllegalStateException("The jgroups configuration cannot be loaded
from '" + filename
- + "'");
- }
+ throw new IllegalStateException("The jgroups configuration cannot be loaded
from '" + filename + "'");
+ }
try
{
// Set the jgroups configuration as XML
@@ -77,15 +79,14 @@
}
catch (IOException e)
{
- throw new IllegalStateException("The jgroups configuration cannot be read
from '" + filename
- + "'");
+ throw new IllegalStateException("The jgroups configuration cannot be read
from '" + filename + "'", e);
}
// Remove the property corresponding to the configuration file
properties.remove(JGroupsTransport.CONFIGURATION_FILE);
+ configBuilder.transport().withProperties(properties);
return true;
}
-
/**
* Reads bytes from input stream and builds a string from them
*
@@ -110,7 +111,7 @@
{
inputStream.close();
}
- catch (Exception e)
+ catch (IOException e)
{
LOG.debug("Cannot close stream", e);
}
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/resources/conf/portal/cache-configuration-template.xml
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/resources/conf/portal/cache-configuration-template.xml 2012-03-20
11:47:42 UTC (rev 5921)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/main/resources/conf/portal/cache-configuration-template.xml 2012-03-20
13:45:55 UTC (rev 5922)
@@ -53,8 +53,8 @@
<shutdown hookBehavior="DEFAULT"/>
</global>
<default>
- <locking isolationLevel="READ_COMMITTED"
lockAcquisitionTimeout="10000" writeSkewCheck="false"
concurrencyLevel="500"/>
- <transaction
transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"
syncRollbackPhase="true" syncCommitPhase="true"/>
+ <locking isolationLevel="READ_COMMITTED"
lockAcquisitionTimeout="10000" writeSkewCheck="false"
concurrencyLevel="500" useLockStriping="true"/>
+ <transaction
transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"
syncRollbackPhase="true" syncCommitPhase="true"
transactionMode="TRANSACTIONAL"/>
<jmxStatistics enabled="true"/>
<invocationBatching enabled="true"/>
<clustering mode="replication">
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestAbstractExoCache.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestAbstractExoCache.java 2012-03-20
11:47:42 UTC (rev 5921)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestAbstractExoCache.java 2012-03-20
13:45:55 UTC (rev 5922)
@@ -519,7 +519,7 @@
@Override
public boolean equals(Object paramObject)
{
- return paramObject instanceof MyKey &&
((MyKey)paramObject).value.endsWith(value);
+ return paramObject instanceof MyKey &&
((MyKey)paramObject).value.equals(value);
}
@Override
@@ -546,13 +546,13 @@
+ System.getProperty("java.net.preferIPv4Stack"));
ExoCacheConfig config = new ExoCacheConfig();
config.setName("MyCacheDistributed");
- config.setMaxSize(5);
+ config.setMaxSize(8);
config.setLiveTime(1);
config.setImplementation("LRU");
config.setReplicated(true);
ExoCacheConfig config2 = new ExoCacheConfig();
config2.setName("MyCacheDistributed2");
- config2.setMaxSize(5);
+ config2.setMaxSize(8);
config2.setLiveTime(1);
config2.setImplementation("LRU");
config2.setReplicated(true);
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheCreator.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheCreator.java 2012-03-20
11:47:42 UTC (rev 5921)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheCreator.java 2012-03-20
13:45:55 UTC (rev 5922)
@@ -24,7 +24,7 @@
import org.exoplatform.services.cache.ExoCacheConfig;
import org.exoplatform.services.cache.ExoCacheInitException;
import org.infinispan.Cache;
-import org.infinispan.config.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
import java.io.Serializable;
import java.util.Collections;
@@ -42,10 +42,10 @@
{
/**
- * @see
org.exoplatform.services.cache.impl.infinispan.ExoCacheCreator#create(org.exoplatform.services.cache.ExoCacheConfig,
org.infinispan.config.Configuration, java.util.concurrent.Callable)
+ * {@inheritDoc}
*/
@Override
- public ExoCache<Serializable, Object> create(ExoCacheConfig config,
Configuration cacheConfig,
+ public ExoCache<Serializable, Object> create(ExoCacheConfig config,
ConfigurationBuilder confBuilder,
Callable<Cache<Serializable, Object>> cacheGetter) throws
ExoCacheInitException
{
return new TestExoCache();
@@ -61,55 +61,46 @@
return Collections.singleton("TEST");
}
+ @SuppressWarnings({"rawtypes", "unchecked"})
public static class TestExoCache implements ExoCache<Serializable, Object>
{
public void addCacheListener(CacheListener listener)
{
- // TODO Auto-generated method stub
-
}
-
public int getCacheHit()
{
- // TODO Auto-generated method stub
return 0;
}
public int getCacheMiss()
{
- // TODO Auto-generated method stub
return 0;
}
public int getCacheSize()
{
- // TODO Auto-generated method stub
return 0;
}
public List getCachedObjects()
{
- // TODO Auto-generated method stub
return null;
}
public String getLabel()
{
- // TODO Auto-generated method stub
return null;
}
public long getLiveTime()
{
- // TODO Auto-generated method stub
return 0;
}
public int getMaxSize()
{
- // TODO Auto-generated method stub
return 0;
}
@@ -120,104 +111,86 @@
public boolean isDistributed()
{
- // TODO Auto-generated method stub
return false;
}
public boolean isLogEnabled()
{
- // TODO Auto-generated method stub
return false;
}
public boolean isReplicated()
{
- // TODO Auto-generated method stub
return false;
}
-
public void select(CachedObjectSelector selector) throws Exception
{
- // TODO Auto-generated method stub
}
public void setDistributed(boolean b)
{
- // TODO Auto-generated method stub
}
public void setLabel(String s)
{
- // TODO Auto-generated method stub
}
public void setLiveTime(long period)
{
- // TODO Auto-generated method stub
}
public void setLogEnabled(boolean b)
{
- // TODO Auto-generated method stub
}
public void setMaxSize(int max)
{
- // TODO Auto-generated method stub
}
public void setName(String name)
{
- // TODO Auto-generated method stub
}
public void setReplicated(boolean b)
{
- // TODO Auto-generated method stub
}
public void clearCache()
{
- // TODO Auto-generated method stub
-
+
}
public Object get(Serializable key)
{
- // TODO Auto-generated method stub
return null;
}
public void put(Serializable key, Object value) throws NullPointerException
{
- // TODO Auto-generated method stub
-
+
}
public void putMap(Map objs) throws NullPointerException, IllegalArgumentException
{
- // TODO Auto-generated method stub
-
+
}
public Object remove(Serializable key) throws NullPointerException
{
- // TODO Auto-generated method stub
return null;
}
public List removeCachedObjects()
{
- // TODO Auto-generated method stub
return null;
}
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java 2012-03-20
11:47:42 UTC (rev 5921)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java 2012-03-20
13:45:55 UTC (rev 5922)
@@ -23,7 +23,7 @@
import org.exoplatform.services.cache.ExoCache;
import org.exoplatform.services.cache.impl.infinispan.TestExoCacheCreator.TestExoCache;
import org.exoplatform.test.BasicTestCase;
-import org.infinispan.config.Configuration.CacheMode;
+import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.manager.CacheContainer;
/**
@@ -31,6 +31,7 @@
* @version $Id$
*
*/
+@SuppressWarnings("rawtypes")
public class TestExoCacheFactoryImpl extends BasicTestCase
{
@@ -51,17 +52,20 @@
ExoCache cache = service_.getCacheInstance("myCache");
assertTrue("expect an instance of AbstractExoCache", cache instanceof
AbstractExoCache);
AbstractExoCache aCache = (AbstractExoCache)cache;
- assertTrue("expect a local cache",
aCache.cache.getConfiguration().getCacheMode() == CacheMode.LOCAL);
+ assertTrue("expect a local cache",
+ aCache.cache.getCacheConfiguration().clustering().cacheMode() ==
CacheMode.LOCAL);
aCache.cache.stop();
cache = service_.getCacheInstance("cacheDistributed");
assertTrue("expect an instance of AbstractExoCache", cache instanceof
AbstractExoCache);
aCache = (AbstractExoCache)cache;
- assertTrue("expect a distributed cache",
aCache.cache.getConfiguration().getCacheMode() == CacheMode.REPL_SYNC);
+ assertTrue("expect a distributed cache",
+ aCache.cache.getCacheConfiguration().clustering().cacheMode() ==
CacheMode.REPL_SYNC);
aCache.cache.stop();
cache = service_.getCacheInstance("myCustomCache");
assertTrue("expect an instance of AbstractExoCache", cache instanceof
AbstractExoCache);
aCache = (AbstractExoCache)cache;
- assertTrue("expect a distributed cache",
aCache.cache.getConfiguration().getCacheMode() == CacheMode.REPL_SYNC);
+ assertTrue("expect a distributed cache",
+ aCache.cache.getCacheConfiguration().clustering().cacheMode() ==
CacheMode.REPL_SYNC);
aCache.cache.stop();
}
@@ -76,27 +80,27 @@
cache = service_.getCacheInstance("test-custom-impl-with-new-config");
assertTrue("expect an instance of TestExoCache", cache instanceof
TestExoCache);
}
-
+
public void testSameCacheManager()
{
ExoCache cache1 = service_.getCacheInstance("myCustomCache");
assertTrue("expect an instance of AbstractExoCache", cache1 instanceof
AbstractExoCache);
AbstractExoCache aCache1 = (AbstractExoCache)cache1;
CacheContainer cacheContainer1 = aCache1.cache.getCacheManager();
-
+
ExoCache cache2 = service_.getCacheInstance("myCustomCache-Bis");
assertTrue("expect an instance of AbstractExoCache", cache2 instanceof
AbstractExoCache);
AbstractExoCache aCache2 = (AbstractExoCache)cache2;
CacheContainer cacheContainer2 = aCache2.cache.getCacheManager();
assertTrue("The CacheContainer should be the same", cacheContainer1 ==
cacheContainer2);
-
+
ExoCache cache3 = service_.getCacheInstance("myCustomCache-Bis2");
assertTrue("expect an instance of AbstractExoCache", cache3 instanceof
AbstractExoCache);
AbstractExoCache aCache3 = (AbstractExoCache)cache3;
CacheContainer cacheContainer3 = aCache3.cache.getCacheManager();
assertTrue("The CacheContainer should be the same", cacheContainer1 ==
cacheContainer3);
-
+
aCache1.cache.stop();
- aCache2.cache.stop();
+ aCache2.cache.stop();
}
}
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/distributed/TestDistributedExoCache.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/distributed/TestDistributedExoCache.java 2012-03-20
11:47:42 UTC (rev 5921)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/java/org/exoplatform/services/cache/impl/infinispan/distributed/TestDistributedExoCache.java 2012-03-20
13:45:55 UTC (rev 5922)
@@ -32,6 +32,9 @@
import org.exoplatform.services.cache.impl.infinispan.ExoCacheFactoryImpl;
import org.exoplatform.services.ispn.DistributedCacheManager;
import org.exoplatform.test.BasicTestCase;
+import org.infinispan.affinity.KeyAffinityService;
+import org.infinispan.affinity.KeyAffinityServiceFactory;
+import org.infinispan.affinity.KeyGenerator;
import org.infinispan.distribution.DistributionManager;
import java.io.Serializable;
@@ -42,8 +45,10 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Random;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
/**
@@ -467,17 +472,29 @@
{
private static final long serialVersionUID = 1L;
- public String value;
- public MyKey(){}
- public MyKey(String value)
+ public Object value;
+
+ public String displayValue;
+
+ public MyKey()
{
+ }
+
+ public MyKey(Object value)
+ {
this.value = value;
}
+ public MyKey(String displayValue, Object value)
+ {
+ this.displayValue = displayValue;
+ this.value = value;
+ }
+
@Override
public boolean equals(Object paramObject)
{
- return paramObject instanceof MyKey &&
((MyKey)paramObject).value.endsWith(value);
+ return paramObject instanceof MyKey &&
((MyKey)paramObject).value.equals(value);
}
@Override
@@ -489,10 +506,30 @@
@Override
public String toString()
{
- return value;
+ return displayValue == null ? value.toString() : displayValue;
}
}
-
+
+ public static class MyKeyGenerator implements
KeyGenerator<DistributedExoCache.CacheKey<MyKey>>
+ {
+
+ public static final Random rnd = new Random();
+
+ private String fullName;
+
+ public MyKeyGenerator(String fullName)
+ {
+ this.fullName = fullName;
+ }
+
+ @Override
+ public DistributedExoCache.CacheKey<MyKey> getKey()
+ {
+ return new DistributedExoCache.CacheKey<MyKey>(fullName, new
MyKey(rnd.nextLong()));
+ }
+ }
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
public void testDistributedCache() throws Exception
{
PortalContainer pc = PortalContainer.getInstance();
@@ -511,191 +548,312 @@
DistributedCacheManager dcm2 =
new
DistributedCacheManager("jar:/conf/portal/distributed-cache-configuration.xml",
params, cm);
- @SuppressWarnings("unchecked")
DistributedExoCache<Serializable, Object> cache1 =
(DistributedExoCache<Serializable, Object>)((ExoCacheFactory)pc
.getComponentInstanceOfType(ExoCacheFactory.class)).createCache(config);
DistributionManager dm = cache1.getCache().getDistributionManager();
- MyCacheListener listener1 = new MyCacheListener();
- cache1.addCacheListener(listener1);
DistributedExoCache<Serializable, Object> cache2 =
(DistributedExoCache<Serializable, Object>)new ExoCacheFactoryImpl(
(ExoContainerContext)pc.getComponentInstanceOfType(ExoContainerContext.class),
"jar:/conf/portal/cache-configuration-template.xml", cm,
dcm2).createCache(config);
- MyCacheListener listener2 = new MyCacheListener();
- cache2.addCacheListener(listener2);
+ KeyAffinityService kas1 =
+ KeyAffinityServiceFactory.newLocalKeyAffinityService(cache1.getCache(),
+ new MyKeyGenerator(cache1.getFullName()),
Executors.newSingleThreadExecutor(), 100);
+ KeyAffinityService kas2 =
+ KeyAffinityServiceFactory.newLocalKeyAffinityService(cache2.getCache(),
+ new MyKeyGenerator(cache1.getFullName()),
Executors.newSingleThreadExecutor(), 100);
+
try
{
- MyKey key;
- cache1.put(key = new MyKey("a"), "b");
- assertEquals(1, cache1.getCacheSize());
- assertEquals("b", cache2.get(new MyKey("a")));
- assertEquals(1, cache2.getCacheSize());
-
-// int put1 = 1;
-// int put2 = dm.getLocality(key).isLocal() ? 0 : 1;
-//
-// assertEquals(put1, listener1.put);
-// assertEquals(put2, listener2.put);
+ Object a, b, c;
+ for (int i = 0; i < 2; i++)
+ {
+ if (i == 0)
+ {
+ a =
+ new MyKey("a",
((DistributedExoCache.CacheKey<MyKey>)kas1.getKeyForAddress(cache1.getCache()
+ .getRpcManager().getAddress())).getKey().value);
+ }
+ else
+ {
+ a =
+ new MyKey("a",
((DistributedExoCache.CacheKey<MyKey>)kas2.getKeyForAddress(cache2.getCache()
+ .getRpcManager().getAddress())).getKey().value);
+ }
+ for (int j = 0; j < 2; j++)
+ {
+ if (j == 0)
+ {
+ b =
+ new MyKey("b",
((DistributedExoCache.CacheKey<MyKey>)kas1.getKeyForAddress(cache1.getCache()
+ .getRpcManager().getAddress())).getKey().value);
+ }
+ else
+ {
+ b =
+ new MyKey("b",
((DistributedExoCache.CacheKey<MyKey>)kas2.getKeyForAddress(cache2.getCache()
+ .getRpcManager().getAddress())).getKey().value);
+ }
+ for (int k = 0; k < 2; k++)
+ {
+ if (k == 0)
+ {
+ c =
+ new MyKey("c",
((DistributedExoCache.CacheKey<MyKey>)kas1.getKeyForAddress(cache1.getCache()
+ .getRpcManager().getAddress())).getKey().value);
+ }
+ else
+ {
+ c =
+ new MyKey("c",
((DistributedExoCache.CacheKey<MyKey>)kas2.getKeyForAddress(cache2.getCache()
+ .getRpcManager().getAddress())).getKey().value);
+ }
+ checkUseCase(cache1, cache2, dm, a, b, c);
+ }
+ }
+ }
+ }
+ finally
+ {
+ dcm2.stop();
+ }
+ }
- assertEquals(0, listener1.get);
- assertEquals(1, listener2.get);
-
- MyKey key2;
- cache2.put(key2 = new MyKey("b"), "c");
- assertEquals(2, cache1.getCacheSize());
- assertEquals(2, cache2.getCacheSize());
- assertEquals("c", cache1.get(new MyKey("b")));
-
-// put1 += dm.getLocality(key2).isLocal() ? 1 : 0;
-// put2++;
-//
-// assertEquals(put1, listener1.put);
-// assertEquals(put2, listener2.put);
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ private void checkUseCase(DistributedExoCache<Serializable, Object> cache1,
+ DistributedExoCache<Serializable, Object> cache2, DistributionManager dm,
Object a, Object b, Object c)
+ throws InterruptedException
+ {
+ MyCacheListener listener1 = new MyCacheListener();
+ cache1.addCacheListener(listener1);
+ MyCacheListener listener2 = new MyCacheListener();
+ cache2.addCacheListener(listener2);
+ boolean isALocal = dm.getLocality(new
DistributedExoCache.CacheKey(cache1.getFullName(), new MyKey(a))).isLocal();
+ boolean isBLocal = dm.getLocality(new
DistributedExoCache.CacheKey(cache1.getFullName(), new MyKey(b))).isLocal();
+ boolean isCLocal = dm.getLocality(new
DistributedExoCache.CacheKey(cache1.getFullName(), new MyKey(c))).isLocal();
+ System.out.println("#####################################");
+ System.out.println("'a' is local = " + isALocal);
+ System.out.println("'b' is local = " + isBLocal);
+ System.out.println("'c' is local = " + isCLocal);
+ MyKey key = new MyKey(a);
+ cache1.put(key, "b");
+ assertEquals(1, cache1.getCacheSize());
+ assertEquals("b", cache2.get(new MyKey(a)));
+ assertEquals(1, cache2.getCacheSize());
- assertEquals(1, listener1.get);
- assertEquals(1, listener2.get);
+ int put1 = 1;
+ int put2 = isALocal ? 0 : 1;
- assertEquals(2, cache1.getCacheSize());
- assertEquals(2, cache2.getCacheSize());
+ assertEquals(put1, listener1.put);
+ assertEquals(put2, listener2.put);
-// assertEquals(put1, listener1.put);
-// assertEquals(put2, listener2.put);
+ assertEquals(0, listener1.get);
+ assertEquals(1, listener2.get);
- assertEquals(1, listener1.get);
- assertEquals(1, listener2.get);
+ MyKey key2 = new MyKey(b);
+ cache2.put(key2, "c");
+ assertEquals(2, cache1.getCacheSize());
+ assertEquals(2, cache2.getCacheSize());
+ assertEquals("c", cache1.get(new MyKey(b)));
- cache2.put(key = new MyKey("a"), "a");
- assertEquals(2, cache1.getCacheSize());
- assertEquals(2, cache2.getCacheSize());
- assertEquals("a", cache1.get(new MyKey("a")));
-
-// put1 += dm.getLocality(key).isLocal() ? 1 : 0;
-// put2++;
-//
-// assertEquals(put1, listener1.put);
-// assertEquals(put2, listener2.put);
+ put1 += isBLocal ? 1 : 0;
+ put2++;
- assertEquals(2, listener1.get);
- assertEquals(1, listener2.get);
+ assertEquals(put1, listener1.put);
+ assertEquals(put2, listener2.put);
- cache2.remove(key = new MyKey("a"));
- assertEquals(1, cache1.getCacheSize());
- assertEquals(1, cache2.getCacheSize());
-
-// assertEquals(put1, listener1.put);
-// assertEquals(put2, listener2.put);
+ assertEquals(1, listener1.get);
+ assertEquals(1, listener2.get);
- assertEquals(2, listener1.get);
- assertEquals(1, listener2.get);
-
-// int remove1 = dm.getLocality(key).isLocal() ? 1 : 0;
-// int remove2 = 1;
-//
-// assertEquals(remove1, listener1.remove);
-// assertEquals(remove2, listener2.remove);
-
- cache1.put(key = new MyKey("c"), "c");
- cache1.clearCache();
- assertEquals(0, cache1.getCacheSize());
- assertNull(cache1.get(new MyKey("b")));
- assertNull(cache2.get(new MyKey("b")));
- assertNull(cache2.get(new MyKey("c")));
- assertEquals(0, cache2.getCacheSize());
-
-// put1++;
-// put2 += dm.getLocality(key).isLocal() ? 0 : 1;
+ assertEquals(2, cache1.getCacheSize());
+ assertEquals(2, cache2.getCacheSize());
-// assertEquals(put1, listener1.put);
-// assertEquals(put2, listener2.put);
+ assertEquals(put1, listener1.put);
+ assertEquals(put2, listener2.put);
- assertEquals(3, listener1.get);
- assertEquals(3, listener2.get);
+ assertEquals(1, listener1.get);
+ assertEquals(1, listener2.get);
-// assertEquals(remove1, listener1.remove);
-// assertEquals(remove2, listener2.remove);
+ key = new MyKey(a);
+ cache2.put(key, "a");
+ assertEquals(2, cache1.getCacheSize());
+ assertEquals(2, cache2.getCacheSize());
+ assertEquals("a", cache1.get(new MyKey(a)));
- assertEquals(1, listener1.clearCache);
- assertEquals(0, listener2.clearCache);
+ put1 += isALocal ? 1 : 0;
+ put2++;
- Map<Serializable, Object> values = new HashMap<Serializable,
Object>();
- values.put(key = new MyKey("a"), "a");
- values.put(key2 = new MyKey("b"), "b");
- cache1.putMap(values);
- assertEquals(2, cache1.getCacheSize());
- Thread.sleep(40);
- assertEquals("a", cache2.get(new MyKey("a")));
- assertEquals("b", cache2.get(new MyKey("b")));
- assertEquals(2, cache2.getCacheSize());
+ assertEquals(put1, listener1.put);
+ assertEquals(put2, listener2.put);
-// put1 += 2;
-// put2 += (dm.getLocality(key).isLocal() ? 0 : 1) +
(dm.getLocality(key2).isLocal() ? 0 : 1);
-//
-// assertEquals(put1, listener1.put);
-// assertEquals(put2, listener2.put);
+ assertEquals(2, listener1.get);
+ assertEquals(1, listener2.get);
- assertEquals(3, listener1.get);
- assertEquals(5, listener2.get);
+ key = new MyKey(a);
+ cache2.remove(key);
+ assertEquals(1, cache1.getCacheSize());
+ assertEquals(1, cache2.getCacheSize());
-// assertEquals(remove1, listener1.remove);
-// assertEquals(remove2, listener2.remove);
+ assertEquals(put1, listener1.put);
+ assertEquals(put2, listener2.put);
- assertEquals(1, listener1.clearCache);
- assertEquals(0, listener2.clearCache);
+ assertEquals(2, listener1.get);
+ assertEquals(1, listener2.get);
- values = new HashMap<Serializable, Object>()
+ int remove1 = isALocal ? 1 : 0;
+ int remove2 = 1;
+
+ assertEquals(remove1, listener1.remove);
+ assertEquals(remove2, listener2.remove);
+
+ key = new MyKey(c);
+ cache1.put(key, "c");
+ assertEquals(2, cache1.getCacheSize());
+ assertEquals(2, cache2.getCacheSize());
+ assertEquals("c", cache2.get(new MyKey(c)));
+
+ put1++;
+ put2 += isCLocal ? 0 : 1;
+
+ assertEquals(put1, listener1.put);
+ assertEquals(put2, listener2.put);
+
+ assertEquals(2, listener1.get);
+ assertEquals(2, listener2.get);
+
+ assertEquals(remove1, listener1.remove);
+ assertEquals(remove2, listener2.remove);
+
+ assertEquals(0, listener1.clearCache);
+ assertEquals(0, listener2.clearCache);
+
+ cache1.clearCache();
+ assertEquals(0, cache1.getCacheSize());
+ assertNull(cache1.get(new MyKey(b)));
+ assertNull(cache1.get(new MyKey(c)));
+ assertNull(cache2.get(new MyKey(b)));
+ assertNull(cache2.get(new MyKey(c)));
+ assertEquals(0, cache2.getCacheSize());
+
+ assertEquals(put1, listener1.put);
+ assertEquals(put2, listener2.put);
+
+ assertEquals(4, listener1.get);
+ assertEquals(4, listener2.get);
+
+ // Since the clear cache map/reduce can only find cache1,
+ // the remove calls will be applied to cache1 so cache2
+ // will be notified on its entries, this is due to the
+ // hack used to apply modifications within a map/reduce
+ remove2 += (isBLocal ? 0 : 1) + (isCLocal ? 0 : 1);
+
+ assertEquals(remove1, listener1.remove);
+ assertEquals(remove2, listener2.remove);
+
+ assertEquals(1, listener1.clearCache);
+ assertEquals(0, listener2.clearCache);
+
+ Map<Serializable, Object> values = new HashMap<Serializable,
Object>();
+ key = new MyKey(a);
+ key2 = new MyKey(b);
+ values.put(key, "a");
+ values.put(key2, "b");
+ cache1.putMap(values);
+ assertEquals(2, cache1.getCacheSize());
+ Thread.sleep(40);
+ assertEquals("a", cache1.get(new MyKey(a)));
+ assertEquals("b", cache1.get(new MyKey(b)));
+ assertEquals("a", cache2.get(new MyKey(a)));
+ assertEquals("b", cache2.get(new MyKey(b)));
+ assertEquals(2, cache2.getCacheSize());
+
+ put1 += 2;
+ put2 += (isALocal ? 0 : 1) + (isBLocal ? 0 : 1);
+
+ assertEquals(put1, listener1.put);
+ assertEquals(put2, listener2.put);
+
+ assertEquals(6, listener1.get);
+ assertEquals(6, listener2.get);
+
+ assertEquals(remove1, listener1.remove);
+ assertEquals(remove2, listener2.remove);
+
+ assertEquals(1, listener1.clearCache);
+ assertEquals(0, listener2.clearCache);
+
+ values = new HashMap<Serializable, Object>()
+ {
+ private static final long serialVersionUID = 1L;
+
+ public Set<Entry<Serializable, Object>> entrySet()
{
- private static final long serialVersionUID = 1L;
+ Set<Entry<Serializable, Object>> set = new
LinkedHashSet<Entry<Serializable, Object>>(super.entrySet());
+ set.add(new Entry<Serializable, Object>()
+ {
- public Set<Entry<Serializable, Object>> entrySet()
- {
- Set<Entry<Serializable, Object>> set = new
LinkedHashSet<Entry<Serializable, Object>>(super.entrySet());
- set.add(new Entry<Serializable, Object>()
+ public Object setValue(Object paramV)
{
+ return null;
+ }
- public Object setValue(Object paramV)
- {
- return null;
- }
+ public Object getValue()
+ {
+ throw new RuntimeException("An exception");
+ }
- public Object getValue()
- {
- throw new RuntimeException("An exception");
- }
+ public Serializable getKey()
+ {
+ return "c";
+ }
+ });
+ return set;
+ }
+ };
+ values.put(new MyKey("e"), "e");
+ values.put(new MyKey("d"), "d");
+ cache1.putMap(values);
+ assertEquals(2, cache1.getCacheSize());
+ assertEquals(2, cache2.getCacheSize());
- public Serializable getKey()
- {
- return "c";
- }
- });
- return set;
- }
- };
- values.put(new MyKey("e"), "e");
- values.put(new MyKey("d"), "d");
- cache1.putMap(values);
- assertEquals(2, cache1.getCacheSize());
- assertEquals(2, cache2.getCacheSize());
+ assertEquals(put1, listener1.put);
+ assertEquals(put2, listener2.put);
-// assertEquals(put1, listener1.put);
-// assertEquals(put2, listener2.put);
+ assertEquals(6, listener1.get);
+ assertEquals(6, listener2.get);
- assertEquals(3, listener1.get);
- assertEquals(5, listener2.get);
+ assertEquals(remove1, listener1.remove);
+ assertEquals(remove2, listener2.remove);
-// assertEquals(remove1, listener1.remove);
-// assertEquals(remove2, listener2.remove);
+ assertEquals(1, listener1.clearCache);
+ assertEquals(0, listener2.clearCache);
- assertEquals(1, listener1.clearCache);
- assertEquals(0, listener2.clearCache);
+ assertEquals(0, listener1.expire);
+ assertEquals(0, listener2.expire);
- assertEquals(0, listener1.expire);
- assertEquals(0, listener2.expire);
+ cache2.clearCache();
+ assertEquals(0, cache1.getCacheSize());
+ assertEquals(0, cache2.getCacheSize());
- }
- finally
- {
- dcm2.stop();
- }
+ assertEquals(put1, listener1.put);
+ assertEquals(put2, listener2.put);
+
+ assertEquals(6, listener1.get);
+ assertEquals(6, listener2.get);
+
+ // Since the clear cache map/reduce can only find cache1,
+ // the remove calls will be applied to cache1 so cache2
+ // will be notified on its entries, this is due to the
+ // hack used to apply modifications within a map/reduce
+ remove2 += (isALocal ? 0 : 1) + (isBLocal ? 0 : 1);
+
+ assertEquals(remove1, listener1.remove);
+ assertEquals(remove2, listener2.remove);
+
+ assertEquals(1, listener1.clearCache);
+ assertEquals(1, listener2.clearCache);
+
+ assertEquals(0, listener1.expire);
+ assertEquals(0, listener2.expire);
}
}
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/cache-configuration-template.xml
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/cache-configuration-template.xml 2012-03-20
11:47:42 UTC (rev 5921)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/cache-configuration-template.xml 2012-03-20
13:45:55 UTC (rev 5922)
@@ -53,12 +53,13 @@
<shutdown hookBehavior="DEFAULT"/>
</global>
<default>
- <locking isolationLevel="READ_COMMITTED"
lockAcquisitionTimeout="10000" writeSkewCheck="false"
concurrencyLevel="500"/>
- <transaction
transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"
syncRollbackPhase="true" syncCommitPhase="true"/>
+ <locking isolationLevel="READ_COMMITTED"
lockAcquisitionTimeout="10000" writeSkewCheck="false"
concurrencyLevel="500" useLockStriping="true"/>
+ <transaction
transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"
syncRollbackPhase="true" syncCommitPhase="true"
transactionMode="TRANSACTIONAL"/>
<jmxStatistics enabled="true"/>
<clustering mode="replication">
<stateRetrieval timeout="20000"
fetchInMemoryState="false"/>
<sync replTimeout="20000"/>
</clustering>
+ <invocationBatching enabled="true"/>
</default>
</infinispan>
\ No newline at end of file
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/distributed-cache-configuration-template.xml
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/distributed-cache-configuration-template.xml 2012-03-20
11:47:42 UTC (rev 5921)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/distributed-cache-configuration-template.xml 2012-03-20
13:45:55 UTC (rev 5922)
@@ -54,11 +54,12 @@
</global>
<default>
<locking isolationLevel="READ_COMMITTED"
lockAcquisitionTimeout="20000" writeSkewCheck="false"
concurrencyLevel="500" useLockStriping="true"/>
- <transaction
transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"
syncRollbackPhase="true" syncCommitPhase="true"/>
+ <transaction
transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"
syncRollbackPhase="true" syncCommitPhase="true"
transactionMode="TRANSACTIONAL"/>
<jmxStatistics enabled="true"/>
<clustering mode="replication">
<stateRetrieval timeout="20000"
fetchInMemoryState="false"/>
<sync replTimeout="20000"/>
</clustering>
+ <invocationBatching enabled="true"/>
</default>
</infinispan>
\ No newline at end of file
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/distributed-cache-configuration.xml
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/distributed-cache-configuration.xml 2012-03-20
11:47:42 UTC (rev 5921)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/distributed-cache-configuration.xml 2012-03-20
13:45:55 UTC (rev 5922)
@@ -54,10 +54,9 @@
</global>
<namedCache name="eXoCache">
<locking isolationLevel="READ_COMMITTED"
lockAcquisitionTimeout="20000" writeSkewCheck="false"
concurrencyLevel="500" useLockStriping="true" />
- <transaction
transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"
syncRollbackPhase="true" syncCommitPhase="true"
eagerLockSingleNode="true"/>
+ <transaction
transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"
syncRollbackPhase="true" syncCommitPhase="true"
eagerLockSingleNode="true" transactionMode="TRANSACTIONAL"/>
<jmxStatistics enabled="true"/>
<clustering mode="distribution">
- <l1 enabled="false"/>
<hash numOwners="${infinispan-num-owners}"
rehashRpcTimeout="120000" />
<sync/>
</clustering>
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/test-configuration.xml
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/test-configuration.xml 2012-03-20
11:47:42 UTC (rev 5921)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.infinispan.v5/src/test/resources/conf/portal/test-configuration.xml 2012-03-20
13:45:55 UTC (rev 5922)
@@ -32,7 +32,7 @@
<description>The default cache configuration</description>
<object type="org.exoplatform.services.cache.ExoCacheConfig">
<field
name="name"><string>default</string></field>
- <field name="maxSize"><int>5</int></field>
+ <field name="maxSize"><int>10</int></field>
<field
name="liveTime"><long>2</long></field>
</object>
</object-param>
@@ -223,9 +223,6 @@
<string>LRU</string>
</value>
<value>
- <string>LRU_OLD</string>
- </value>
- <value>
<string>UNORDERED</string>
</value>
<value>
Modified: kernel/trunk/exo.kernel.component.ext.rpc.impl.jgroups.v3/pom.xml
===================================================================
--- kernel/trunk/exo.kernel.component.ext.rpc.impl.jgroups.v3/pom.xml 2012-03-20 11:47:42
UTC (rev 5921)
+++ kernel/trunk/exo.kernel.component.ext.rpc.impl.jgroups.v3/pom.xml 2012-03-20 13:45:55
UTC (rev 5922)
@@ -44,7 +44,7 @@
<dependency>
<groupId>org.jgroups</groupId>
<artifactId>jgroups</artifactId>
- <version>3.0.0.Final</version>
+ <version>3.0.6.Final</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Modified: kernel/trunk/pom.xml
===================================================================
--- kernel/trunk/pom.xml 2012-03-20 11:47:42 UTC (rev 5921)
+++ kernel/trunk/pom.xml 2012-03-20 13:45:55 UTC (rev 5922)
@@ -203,7 +203,7 @@
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
- <version>5.1.0.CR1</version>
+ <version>5.1.0.CR3</version>
</dependency>
<dependency>
<groupId>org.jibx</groupId>