Author: nfilotto
Date: 2010-09-03 06:42:11 -0400 (Fri, 03 Sep 2010)
New Revision: 3050
Modified:
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/distributed-cache-configuration-template.xml
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/test-configuration.xml
kernel/branches/2.3-ISPN/pom.xml
Log:
EXOJCR-802: ISPN has been upgraded to 4.1.0.FINAL and the code has been reviewed to ensure
that the same CacheManager will be used if the GlobalConfig is the same
Modified:
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java
===================================================================
---
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java 2010-09-02
14:17:14 UTC (rev 3049)
+++
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/main/java/org/exoplatform/services/cache/impl/infinispan/ExoCacheFactoryImpl.java 2010-09-03
10:42:11 UTC (rev 3050)
@@ -70,6 +70,11 @@
private static final String CACHE_CONFIG_TEMPLATE_KEY =
"cache.config.template";
/**
+ * The current {@link ExoContainerContext}
+ */
+ private final ExoContainerContext ctx;
+
+ /**
* The configuration manager that allows us to retrieve a configuration file in
several different
* manners
*/
@@ -97,9 +102,9 @@
private final Map<String, String> mappingCacheNameConfig = new
HashMap<String, String>();
/**
- * The mapping between the configuration paths and the cache managers
+ * The mapping between the global configuration and the cache managers
*/
- private final Map<String, DefaultCacheManager> mappingConfigPathCacheManager =
new HashMap<String, DefaultCacheManager>();
+ private final Map<GlobalConfiguration, DefaultCacheManager>
mappingGlobalConfigCacheManager = new HashMap<GlobalConfiguration,
DefaultCacheManager>();
/**
* The default creator
@@ -115,20 +120,23 @@
ExoCacheFactoryImpl(ExoContainerContext ctx, String cacheConfigTemplate,
ConfigurationManager configManager)
throws ExoCacheInitException
{
+ this.ctx = ctx;
this.configManager = configManager;
if (cacheConfigTemplate == null)
{
throw new RuntimeException("The parameter '" +
CACHE_CONFIG_TEMPLATE_KEY + "' must be set");
}
-
- this.cacheManager = initCacheManager(ctx, cacheConfigTemplate);
+ // Initialize the main cache manager
+ this.cacheManager = initCacheManager(cacheConfigTemplate);
+ // Register the main cache manager
+ mappingGlobalConfigCacheManager.put(cacheManager.getGlobalConfiguration(),
cacheManager);
}
/**
* Initializes the {@link DefaultCacheManager}
* @throws ExoCacheInitException if the cache manager cannot be initialized
*/
- private DefaultCacheManager initCacheManager(ExoContainerContext ctx, String
cacheConfigTemplate)
+ private DefaultCacheManager initCacheManager(String cacheConfigTemplate)
throws ExoCacheInitException
{
InputStream is = null;
@@ -160,11 +168,42 @@
}
GlobalConfiguration config = cacheManager.getGlobalConfiguration();
+
+ configureJGroups(config);
+ return cacheManager;
+ }
+
+ /**
+ * If some JGoups properties has been set, it will load the configuration and set
+ * 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
+ * @throws ExoCacheInitException if any exception occurs while configuring JGroups
+ */
+ private void configureJGroups(GlobalConfiguration config) throws
ExoCacheInitException
+ {
+ if (loadJGroupsConfig(config))
+ {
+ // The JGroups Config could be loaded which means that the configuration is for
a cluster
+ config.setClusterName(config.getClusterName() + "-" + 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
+ * @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
+ {
Properties properties = config.getTransportProperties();
if (properties == null ||
!properties.containsKey(JGroupsTransport.CONFIGURATION_FILE))
{
- return cacheManager;
+ return false;
}
+ InputStream is;
String jgroupsFileLocation =
properties.getProperty(JGroupsTransport.CONFIGURATION_FILE);
try
{
@@ -192,9 +231,7 @@
// Remove the property corresponding to the configuration file
properties.remove(JGroupsTransport.CONFIGURATION_FILE);
}
- // Set the cluster name
- config.setClusterName(ctx.getName() + "-cluster");
- return cacheManager;
+ return true;
}
/**
@@ -242,6 +279,7 @@
final String region = config.getName();
final String customConfig = mappingCacheNameConfig.get(region);
final ExoCache<Serializable, Object> eXoCache;
+ final DefaultCacheManager cacheManager;
try
{
final Configuration conf;
@@ -250,18 +288,26 @@
// A custom configuration has been set
if (LOG.isInfoEnabled())
LOG.info("A custom configuration has been set for the cache
'" + region + "'.");
- DefaultCacheManager cacheManager =
mappingConfigPathCacheManager.get(customConfig);
- if (cacheManager == null)
+ // Create the CacheManager by loading the configuration
+ DefaultCacheManager customCacheManager = new
DefaultCacheManager(configManager.getInputStream(customConfig), false);
+ GlobalConfiguration gc = customCacheManager.getGlobalConfiguration();
+ // Configure JGroups since it could affect the state of the Global Config
+ configureJGroups(gc);
+ // Check if a CacheManager with the same GlobalConfiguration exists
+ DefaultCacheManager currentCacheManager =
mappingGlobalConfigCacheManager.get(gc);
+ if (currentCacheManager == null)
{
- // No cache manager has been defined so far for this configuration file
- cacheManager = new
DefaultCacheManager(configManager.getInputStream(customConfig), false);
+ // No cache manager has been defined so far for this Cache Configuration
+ currentCacheManager = customCacheManager;
// We register this new cache manager
- mappingConfigPathCacheManager.put(customConfig, cacheManager);
+ mappingGlobalConfigCacheManager.put(gc, customCacheManager);
}
- conf = cacheManager.getDefaultConfiguration().clone();
+ conf = currentCacheManager.getDefaultConfiguration().clone();
+ cacheManager = currentCacheManager;
}
else
{
+ cacheManager = this.cacheManager;
// 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 + "'.");
Modified:
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java
===================================================================
---
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java 2010-09-02
14:17:14 UTC (rev 3049)
+++
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/java/org/exoplatform/services/cache/impl/infinispan/TestExoCacheFactoryImpl.java 2010-09-03
10:42:11 UTC (rev 3050)
@@ -24,6 +24,7 @@
import org.exoplatform.services.cache.impl.infinispan.TestExoCacheCreator.TestExoCache;
import org.exoplatform.test.BasicTestCase;
import org.infinispan.config.Configuration.CacheMode;
+import org.infinispan.manager.CacheContainer;
/**
* @author <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas
Filotto</a>
@@ -75,4 +76,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();
+ }
}
Modified:
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/distributed-cache-configuration-template.xml
===================================================================
---
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/distributed-cache-configuration-template.xml 2010-09-02
14:17:14 UTC (rev 3049)
+++
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/distributed-cache-configuration-template.xml 2010-09-03
10:42:11 UTC (rev 3050)
@@ -44,7 +44,7 @@
<property name="threadNamePrefix"
value="ReplicationQueueThread"/>
</properties>
</replicationQueueScheduledExecutor>
- <globalJmxStatistics jmxDomain="infinispan"
enabled="true"/>
+ <globalJmxStatistics jmxDomain="infinispan"
enabled="false"/>
<transport
transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport"
clusterName="Infinispan-cluster" distributedSyncTimeout="20000">
<properties>
<property name="configurationFile"
value="flush-udp.xml"/>
Modified:
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/test-configuration.xml
===================================================================
---
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/test-configuration.xml 2010-09-02
14:17:14 UTC (rev 3049)
+++
kernel/branches/2.3-ISPN/exo.kernel.component.ext.cache.impl.infinispan.v4/src/test/resources/conf/portal/test-configuration.xml 2010-09-03
10:42:11 UTC (rev 3050)
@@ -172,6 +172,10 @@
<name>myCustomCache</name>
<value>jar:/conf/portal/distributed-cache-configuration-template.xml</value>
</value-param>
+ <value-param>
+ <name>myCustomCache-Bis</name>
+
<value>classpath:/conf/portal/distributed-cache-configuration-template.xml</value>
+ </value-param>
</init-params>
</component-plugin>
<component-plugin>
Modified: kernel/branches/2.3-ISPN/pom.xml
===================================================================
--- kernel/branches/2.3-ISPN/pom.xml 2010-09-02 14:17:14 UTC (rev 3049)
+++ kernel/branches/2.3-ISPN/pom.xml 2010-09-03 10:42:11 UTC (rev 3050)
@@ -190,7 +190,7 @@
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
- <version>4.1.0.CR2</version>
+ <version>4.1.0.FINAL</version>
</dependency>
<dependency>
<groupId>org.jibx</groupId>