Author: nfilotto
Date: 2010-09-15 14:47:08 -0400 (Wed, 15 Sep 2010)
New Revision: 3116
Added:
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/AbstractExoCacheConfig.java
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/pom.xml
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ExoCacheFactoryImpl.java
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ea/EAExoCacheConfig.java
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/fifo/FIFOExoCacheConfig.java
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lfu/LFUExoCacheConfig.java
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lru/LRUExoCacheConfig.java
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/mru/MRUExoCacheConfig.java
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestAbstractExoCache.java
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/resources/conf/portal/test-configuration.xml
Log:
EXOJCR-943: We can now deactivate the ability to share several JBC instances between
several eXo Cache.This can be set at ExoCacheConfig level by setting the value of the
parameter allowShareableCache otherwise we will use the default value that is set at
ExoCacheFactoryImpl level and the related parameter name is allow.shareable.cache
Modified: kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/pom.xml
===================================================================
--- kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/pom.xml 2010-09-15 15:19:22
UTC (rev 3115)
+++ kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/pom.xml 2010-09-15 18:47:08
UTC (rev 3116)
@@ -76,9 +76,13 @@
<name>jgroups.stack</name>
<value>udp</value>
</property>
+ <property>
+ <name>allow.shareable.cache</name>
+ <value>true</value>
+ </property>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
-</project>
\ No newline at end of file
+</project>
Added:
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/AbstractExoCacheConfig.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/AbstractExoCacheConfig.java
(rev 0)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/AbstractExoCacheConfig.java 2010-09-15
18:47:08 UTC (rev 3116)
@@ -0,0 +1,29 @@
+package org.exoplatform.services.cache.impl.jboss;
+
+import org.exoplatform.services.cache.ExoCacheConfig;
+
+/**
+ * The parent class of all the existing {@link ExoCacheConfig} available for the
JBossCache
+ * implementation of the eXo Cache
+ *
+ * @author <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas
Filotto</a>
+ * @version $Id$
+ */
+public abstract class AbstractExoCacheConfig extends ExoCacheConfig
+{
+
+ /**
+ * Indicate whether the JBossCache instance used for this cache can be shared
+ */
+ public Boolean allowShareableCache;
+
+ public Boolean getAllowShareableCache()
+ {
+ return allowShareableCache;
+ }
+
+ public void setAllowShareableCache(Boolean allowShareableCache)
+ {
+ this.allowShareableCache = allowShareableCache;
+ }
+}
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ExoCacheFactoryImpl.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ExoCacheFactoryImpl.java 2010-09-15
15:19:22 UTC (rev 3115)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ExoCacheFactoryImpl.java 2010-09-15
18:47:08 UTC (rev 3116)
@@ -62,7 +62,14 @@
* The initial parameter key that defines the full path of the configuration template
*/
private static final String CACHE_CONFIG_TEMPLATE_KEY =
"cache.config.template";
+
+ /**
+ * Indicate whether the JBoss Cache instance used can be shared with other caches
+ */
+ public static final String ALLOW_SHAREABLE_CACHE = "allow.shareable.cache";
+ public static final boolean ALLOW_SHAREABLE_CACHE_DEFAULT = true;
+
/**
* The configuration manager that allows us to retrieve a configuration file in
several different
* manners
@@ -73,6 +80,11 @@
* The full path of the configuration template
*/
private final String cacheConfigTemplate;
+
+ /**
+ * Indicates whether the JBossCache instances can be shared between several eXo Cache
by default
+ */
+ private final boolean allowShareableCache;
/**
* The mapping between the configuration types and the creators
@@ -103,13 +115,15 @@
public ExoCacheFactoryImpl(InitParams params, ConfigurationManager configManager)
{
- this(getValueParam(params, CACHE_CONFIG_TEMPLATE_KEY), configManager);
+ this(getValueParam(params, CACHE_CONFIG_TEMPLATE_KEY), configManager,
getBooleanParam(params,
+ ALLOW_SHAREABLE_CACHE, ALLOW_SHAREABLE_CACHE_DEFAULT));
}
- ExoCacheFactoryImpl(String cacheConfigTemplate, ConfigurationManager configManager)
+ ExoCacheFactoryImpl(String cacheConfigTemplate, ConfigurationManager configManager,
boolean allowShareableCache)
{
this.configManager = configManager;
this.cacheConfigTemplate = cacheConfigTemplate;
+ this.allowShareableCache = allowShareableCache;
if (cacheConfigTemplate == null)
{
throw new RuntimeException("The parameter '" +
CACHE_CONFIG_TEMPLATE_KEY + "' must be set");
@@ -156,7 +170,7 @@
}
final ExoCacheCreator creator = getExoCacheCreator(config);
// Ensure that new created cache doesn't exist
- cache = getUniqueInstance(cache, region);
+ cache = getUniqueInstance(cache, config);
// Create the cache
eXoCache = creator.create(config, cache);
// Create the cache
@@ -214,6 +228,16 @@
}
/**
+ * Returns the boolean value of the parameter corresponding to the given key. If no
value can
+ * be found the default value will be returned
+ */
+ private static boolean getBooleanParam(InitParams params, String key, boolean
defaultValue)
+ {
+ String value = getValueParam(params, key);
+ return value == null ? defaultValue : Boolean.valueOf(value).booleanValue();
+ }
+
+ /**
* Returns the most relevant ExoCacheCreator according to the give configuration
*/
protected ExoCacheCreator getExoCacheCreator(ExoCacheConfig config)
@@ -258,17 +282,40 @@
* Try to find if a Cache of the same type (i.e. their {@link Configuration} are
equals)
* has already been registered.
* If no cache has been registered, we register the given cache otherwise we
- * use the previously registered cache.
+ * use the previously registered cache. If the config given is of type {@link
AbstractExoCacheConfig}
+ * we will try to get the value of the parameter allowShareableCache, if it is not set
we will use the
+ * default value defined in the current instance of {@link ExoCacheFactoryImpl}. If
the cache
+ * is not shareable then no cache will be registered.
* @param cache the cache to register
- * @param region the region of the cache
+ * @param config the configuration of the cache
* @return the given cache if has not been registered otherwise the cache of the same
* type that has already been registered
* @throws ExoCacheInitException
*/
- private synchronized Cache<Serializable, Object>
getUniqueInstance(Cache<Serializable, Object> cache, String region)
+ private synchronized Cache<Serializable, Object>
getUniqueInstance(Cache<Serializable, Object> cache, ExoCacheConfig config)
throws ExoCacheInitException
{
+ String region = config.getName();
+ boolean allowShareableCache = this.allowShareableCache;
+ if (config instanceof AbstractExoCacheConfig)
+ {
+ AbstractExoCacheConfig aConfig = (AbstractExoCacheConfig)config;
+ if (aConfig.getAllowShareableCache() != null)
+ {
+ allowShareableCache = aConfig.getAllowShareableCache().booleanValue();
+ }
+ }
Configuration cfg = cache.getConfiguration();
+ if (!allowShareableCache)
+ {
+ // Rename the cluster name
+ String clusterName = cfg.getClusterName();
+ if (clusterName != null && (clusterName = clusterName.trim()).length()
> 0)
+ {
+ cfg.setClusterName(clusterName + " " + region);
+ }
+ return cache;
+ }
ConfigurationKey key;
try
{
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ea/EAExoCacheConfig.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ea/EAExoCacheConfig.java 2010-09-15
15:19:22 UTC (rev 3115)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ea/EAExoCacheConfig.java 2010-09-15
18:47:08 UTC (rev 3116)
@@ -16,7 +16,7 @@
*/
package org.exoplatform.services.cache.impl.jboss.ea;
-import org.exoplatform.services.cache.ExoCacheConfig;
+import org.exoplatform.services.cache.impl.jboss.AbstractExoCacheConfig;
import org.jboss.cache.eviction.ExpirationAlgorithm;
@@ -29,7 +29,7 @@
* nicolas.filotto(a)exoplatform.com
* 8 mars 2010
*/
-public class EAExoCacheConfig extends ExoCacheConfig
+public class EAExoCacheConfig extends AbstractExoCacheConfig
{
private int maxNodes;
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/fifo/FIFOExoCacheConfig.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/fifo/FIFOExoCacheConfig.java 2010-09-15
15:19:22 UTC (rev 3115)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/fifo/FIFOExoCacheConfig.java 2010-09-15
18:47:08 UTC (rev 3116)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.cache.impl.jboss.fifo;
-import org.exoplatform.services.cache.ExoCacheConfig;
+import org.exoplatform.services.cache.impl.jboss.AbstractExoCacheConfig;
/**
* The {@link org.exoplatform.services.cache.ExoCacheConfig} for the FIFO implementation
@@ -28,7 +28,7 @@
* exo(a)exoplatform.com
* 21 juil. 2009
*/
-public class FIFOExoCacheConfig extends ExoCacheConfig
+public class FIFOExoCacheConfig extends AbstractExoCacheConfig
{
private int maxNodes;
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lfu/LFUExoCacheConfig.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lfu/LFUExoCacheConfig.java 2010-09-15
15:19:22 UTC (rev 3115)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lfu/LFUExoCacheConfig.java 2010-09-15
18:47:08 UTC (rev 3116)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.cache.impl.jboss.lfu;
-import org.exoplatform.services.cache.ExoCacheConfig;
+import org.exoplatform.services.cache.impl.jboss.AbstractExoCacheConfig;
/**
* The {@link org.exoplatform.services.cache.ExoCacheConfig} for the LFU implementation
@@ -28,7 +28,7 @@
* exo(a)exoplatform.com
* 21 juil. 2009
*/
-public class LFUExoCacheConfig extends ExoCacheConfig
+public class LFUExoCacheConfig extends AbstractExoCacheConfig
{
private int maxNodes;
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lru/LRUExoCacheConfig.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lru/LRUExoCacheConfig.java 2010-09-15
15:19:22 UTC (rev 3115)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/lru/LRUExoCacheConfig.java 2010-09-15
18:47:08 UTC (rev 3116)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.cache.impl.jboss.lru;
-import org.exoplatform.services.cache.ExoCacheConfig;
+import org.exoplatform.services.cache.impl.jboss.AbstractExoCacheConfig;
/**
* The {@link org.exoplatform.services.cache.ExoCacheConfig} for the LRU implementation
@@ -28,7 +28,7 @@
* exo(a)exoplatform.com
* 21 juil. 2009
*/
-public class LRUExoCacheConfig extends ExoCacheConfig
+public class LRUExoCacheConfig extends AbstractExoCacheConfig
{
private int maxNodes;
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/mru/MRUExoCacheConfig.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/mru/MRUExoCacheConfig.java 2010-09-15
15:19:22 UTC (rev 3115)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/mru/MRUExoCacheConfig.java 2010-09-15
18:47:08 UTC (rev 3116)
@@ -18,7 +18,7 @@
*/
package org.exoplatform.services.cache.impl.jboss.mru;
-import org.exoplatform.services.cache.ExoCacheConfig;
+import org.exoplatform.services.cache.impl.jboss.AbstractExoCacheConfig;
/**
* The {@link org.exoplatform.services.cache.ExoCacheConfig} for the MRU implementation
@@ -28,7 +28,7 @@
* exo(a)exoplatform.com
* 21 juil. 2009
*/
-public class MRUExoCacheConfig extends ExoCacheConfig
+public class MRUExoCacheConfig extends AbstractExoCacheConfig
{
private int maxNodes;
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestAbstractExoCache.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestAbstractExoCache.java 2010-09-15
15:19:22 UTC (rev 3115)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestAbstractExoCache.java 2010-09-15
18:47:08 UTC (rev 3116)
@@ -238,8 +238,10 @@
private ExoCacheFactory getExoCacheFactoryInstance() throws ExoCacheInitException
{
PortalContainer pc = PortalContainer.getInstance();
- ExoCacheFactoryImpl factory = new
ExoCacheFactoryImpl("jar:/conf/portal/cache-configuration-template.xml",
(ConfigurationManager)pc
- .getComponentInstanceOfType(ConfigurationManager.class));
+ ExoCacheFactoryImpl factory =
+ new
ExoCacheFactoryImpl("jar:/conf/portal/cache-configuration-template.xml",
(ConfigurationManager)pc
+ .getComponentInstanceOfType(ConfigurationManager.class), Boolean.valueOf(
+ System.getProperty("allow.shareable.cache")).booleanValue());
InitParams params = new InitParams();
ObjectParameter param = new ObjectParameter();
param.setName("LRU");
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/resources/conf/portal/test-configuration.xml
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/resources/conf/portal/test-configuration.xml 2010-09-15
15:19:22 UTC (rev 3115)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/resources/conf/portal/test-configuration.xml 2010-09-15
18:47:08 UTC (rev 3116)
@@ -154,6 +154,10 @@
<name>cache.config.template</name>
<value>jar:/conf/portal/cache-configuration-template.xml</value>
</value-param>
+ <value-param>
+ <name>allow.shareable.cache</name>
+ <value>${allow.shareable.cache}</value>
+ </value-param>
</init-params>
</component>