Author: nfilotto
Date: 2010-09-16 11:16:19 -0400 (Thu, 16 Sep 2010)
New Revision: 3124
Modified:
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNCacheableLockManagerImpl.java
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/ISPNCacheWorkspaceStorageCache.java
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/infinispan/ISPNCacheFactory.java
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-jcr-config.xml
Log:
EXOJCR-938: All the Cache instances with the same GlobalConfiguration, will share the same
CacheManager
Modified:
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNCacheableLockManagerImpl.java
===================================================================
---
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNCacheableLockManagerImpl.java 2010-09-16
15:01:49 UTC (rev 3123)
+++
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/infinispan/ISPNCacheableLockManagerImpl.java 2010-09-16
15:16:19 UTC (rev 3124)
@@ -112,7 +112,7 @@
// configure cache loader parameters with correct DB data-types
configureJDBCCacheLoader(config.getLockManager());
- cache = factory.createCache(config.getLockManager());
+ cache = factory.createCache("Lock-" + config.getUniqueName(),
config.getLockManager());
// Context recall is a workaround of JDBCCacheLoader starting.
context.recall();
Modified:
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/ISPNCacheWorkspaceStorageCache.java
===================================================================
---
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/ISPNCacheWorkspaceStorageCache.java 2010-09-16
15:01:49 UTC (rev 3123)
+++
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/infinispan/ISPNCacheWorkspaceStorageCache.java 2010-09-16
15:16:19 UTC (rev 3124)
@@ -209,7 +209,7 @@
// create parent Infinispan instance
CacheEntry cacheEntry = wsConfig.getCache();
- Cache<Serializable, Object> parentCache = factory.createCache(cacheEntry);
+ Cache<Serializable, Object> parentCache =
factory.createCache("Data-" + wsConfig.getUniqueName(), cacheEntry);
Boolean allowLocalChanges = null;
try
Modified:
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/infinispan/ISPNCacheFactory.java
===================================================================
---
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/infinispan/ISPNCacheFactory.java 2010-09-16
15:01:49 UTC (rev 3123)
+++
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/infinispan/ISPNCacheFactory.java 2010-09-16
15:16:19 UTC (rev 3124)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.services.jcr.infinispan;
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.services.jcr.config.MappedParametrizedObjectEntry;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
@@ -25,6 +27,8 @@
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.GlobalConfiguration;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;
@@ -32,6 +36,8 @@
import java.io.InputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.HashMap;
+import java.util.Map;
/**
* Factory that creates and starts pre-configured instances of Infinispan.
@@ -48,11 +54,16 @@
public static final String INFINISPAN_CONFIG = "infinispan-configuration";
- public static final String JGROUPS_CONFIG = "jgroups-configuration";
-
private final TemplateConfigurationHelper configurationHelper;
- private final Log log =
ExoLogger.getLogger("exo.jcr.component.core.InfinispanCacheFactory");
+ private static final Log log =
ExoLogger.getLogger("exo.jcr.component.core.InfinispanCacheFactory");
+
+ /**
+ * A Map that contains all the registered CacheManager order by {@link ExoContainer}
+ * instances and {@link GlobalConfiguration}.
+ */
+ private static Map<ExoContainer, Map<GlobalConfiguration,
EmbeddedCacheManager>> CACHES =
+ new HashMap<ExoContainer, Map<GlobalConfiguration,
EmbeddedCacheManager>>();
/**
* Creates InfinispanCacheFactory with provided configuration transaction managers.
@@ -71,11 +82,12 @@
* "infinispan-configuration" property in parameterEntry instance.
* <br>
*
+ * @param regionId the unique id of the cache region to create
* @param parameterEntry
* @return
* @throws RepositoryConfigurationException
*/
- public Cache<K, V> createCache(MappedParametrizedObjectEntry parameterEntry)
throws RepositoryConfigurationException
+ public Cache<K, V> createCache(final String regionId,
MappedParametrizedObjectEntry parameterEntry) throws RepositoryConfigurationException
{
// get Infinispan configuration file path
final String configurationPath =
parameterEntry.getParameterValue(INFINISPAN_CONFIG);
@@ -97,7 +109,7 @@
final EmbeddedCacheManager manager;
try
{
- manager = new DefaultCacheManager(configStream);
+ manager = getUniqueInstance(regionId, new DefaultCacheManager(configStream));
}
catch (IOException e)
{
@@ -108,11 +120,51 @@
{
public Cache<K, V> run()
{
- return manager.getCache();
+ return manager.getCache(regionId);
}
};
Cache<K, V> cache = AccessController.doPrivileged(action);
return cache;
}
+
+ /**
+ * Try to find if a {@link EmbeddedCacheManager} of the same type (i.e. their {@link
GlobalConfiguration} are equals)
+ * has already been registered for the same current container.
+ * If no cache manager has been registered, we register the given cache manager
otherwise we
+ * use the previously registered cache manager and we define a dedicated region for
the related cache.
+ * @param regionId the unique id of the cache region to create
+ * @param manager the current cache manager of the cache to create
+ * @return the given cache manager if it has not been registered otherwise the cache
manager of the same
+ * type that has already been registered..
+ */
+ private static synchronized EmbeddedCacheManager getUniqueInstance(String regionId,
EmbeddedCacheManager manager)
+ {
+ ExoContainer container = ExoContainerContext.getCurrentContainer();
+ Map<GlobalConfiguration, EmbeddedCacheManager> allCacheManagers =
CACHES.get(container);
+ if (allCacheManagers == null)
+ {
+ allCacheManagers = new HashMap<GlobalConfiguration,
EmbeddedCacheManager>();
+ CACHES.put(container, allCacheManagers);
+ }
+ GlobalConfiguration gc = manager.getGlobalConfiguration();
+ // Ensure that the cluster name won't be used between 2 ExoContainers
+ gc.setClusterName(gc.getClusterName() + "-" +
container.getContext().getName());
+ Configuration conf = manager.getDefaultConfiguration();
+ if (allCacheManagers.containsKey(gc))
+ {
+ manager = allCacheManagers.get(gc);
+ }
+ else
+ {
+ allCacheManagers.put(gc, manager);
+ if (log.isInfoEnabled())
+ log.info("A new JBoss Cache instance has been registered for the region
" + regionId + " and the container " + container.getContext().getName());
+ }
+ // Define the configuration of the cache
+ manager.defineConfiguration(regionId, conf);
+ if (log.isInfoEnabled())
+ log.info("The region " + regionId + " has been registered for the
container " + container.getContext().getName());
+ return manager;
+ }
}
Modified:
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-jcr-config.xml
===================================================================
---
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-jcr-config.xml 2010-09-16
15:01:49 UTC (rev 3123)
+++
jcr/branches/1.14-ISPN/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-jcr-config.xml 2010-09-16
15:16:19 UTC (rev 3124)
@@ -63,7 +63,7 @@
<properties>
<property name="infinispan-configuration"
value="conf/standalone/cluster/test-infinispan-config.xml" />
<property name="jgroups-configuration"
value="flush-udp.xml" />
- <property name="infinispan-cluster-name"
value="JCR-cluster-db1-ws" />
+ <property name="infinispan-cluster-name"
value="JCR-cluster" />
</properties>
</cache>
<query-handler
class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
@@ -76,7 +76,7 @@
<property name="time-out" value="15m" />
<property name="infinispan-configuration"
value="conf/standalone/cluster/test-infinispan-config.xml" />
<property name="jgroups-configuration"
value="flush-udp.xml" />
- <property name="infinispan-cluster-name"
value="JCR-cluster-locks-db1-ws" />
+ <property name="infinispan-cluster-name"
value="JCR-cluster" />
<property name="infinispan-cl-cache.jdbc.table.name"
value="jcrlocks_db1_ws" />
<property name="infinispan-cl-cache.jdbc.table.create"
value="true" />
<property name="infinispan-cl-cache.jdbc.table.drop"
value="false" />
@@ -114,7 +114,7 @@
<properties>
<property name="infinispan-configuration"
value="conf/standalone/cluster/test-infinispan-config.xml" />
<property name="jgroups-configuration"
value="flush-udp.xml" />
- <property name="infinispan-cluster-name"
value="JCR-cluster-db1-ws1" />
+ <property name="infinispan-cluster-name"
value="JCR-cluster" />
</properties>
</cache>
<query-handler
class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
@@ -133,7 +133,7 @@
<property name="time-out" value="15m" />
<property name="infinispan-configuration"
value="conf/standalone/cluster/test-infinispan-config.xml" />
<property name="jgroups-configuration"
value="flush-udp.xml" />
- <property name="infinispan-cluster-name"
value="JCR-cluster-locks-db1-ws1" />
+ <property name="infinispan-cluster-name"
value="JCR-cluster" />
<property name="infinispan-cl-cache.jdbc.table.name"
value="jcrlocks_db1_ws1" />
<property name="infinispan-cl-cache.jdbc.table.create"
value="true" />
<property name="infinispan-cl-cache.jdbc.table.drop"
value="false" />
@@ -171,7 +171,7 @@
<properties>
<property name="infinispan-configuration"
value="conf/standalone/cluster/test-infinispan-config.xml" />
<property name="jgroups-configuration"
value="flush-udp.xml" />
- <property name="infinispan-cluster-name"
value="JCR-cluster-db1-ws2" />
+ <property name="infinispan-cluster-name"
value="JCR-cluster" />
</properties>
</cache>
<query-handler
class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
@@ -190,7 +190,7 @@
<property name="time-out" value="15m" />
<property name="infinispan-configuration"
value="conf/standalone/cluster/test-infinispan-config.xml" />
<property name="jgroups-configuration"
value="flush-udp.xml" />
- <property name="infinispan-cluster-name"
value="JCR-cluster-locks-db1-ws2" />
+ <property name="infinispan-cluster-name"
value="JCR-cluster" />
<property name="infinispan-cl-cache.jdbc.table.name"
value="jcrlocks_db1_ws2" />
<property name="infinispan-cl-cache.jdbc.table.create"
value="true" />
<property name="infinispan-cl-cache.jdbc.table.drop"
value="false" />
@@ -246,7 +246,7 @@
<properties>
<property name="infinispan-configuration"
value="conf/standalone/cluster/test-infinispan-config.xml" />
<property name="jgroups-configuration"
value="flush-udp.xml" />
- <property name="infinispan-cluster-name"
value="JCR-cluster-db1-ws3" />
+ <property name="infinispan-cluster-name"
value="JCR-cluster" />
</properties>
</cache>
<query-handler
class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
@@ -265,7 +265,7 @@
<property name="time-out" value="15m" />
<property name="infinispan-configuration"
value="conf/standalone/cluster/test-infinispan-config.xml" />
<property name="jgroups-configuration"
value="flush-udp.xml" />
- <property name="infinispan-cluster-name"
value="JCR-cluster-locks-db1-ws3" />
+ <property name="infinispan-cluster-name"
value="JCR-cluster" />
<property name="infinispan-cl-cache.jdbc.table.name"
value="jcrlocks_db1_ws3" />
<property name="infinispan-cl-cache.jdbc.table.create"
value="true" />
<property name="infinispan-cl-cache.jdbc.table.drop"
value="false" />
@@ -319,7 +319,7 @@
<properties>
<property name="infinispan-configuration"
value="conf/standalone/cluster/test-infinispan-config.xml" />
<property name="jgroups-configuration"
value="flush-udp.xml" />
- <property name="infinispan-cluster-name"
value="JCR-cluster-db1tck-ws" />
+ <property name="infinispan-cluster-name"
value="JCR-cluster" />
</properties>
</cache>
<query-handler
class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
@@ -339,7 +339,7 @@
<property name="time-out" value="15m" />
<property name="infinispan-configuration"
value="conf/standalone/cluster/test-infinispan-config.xml" />
<property name="jgroups-configuration"
value="flush-udp.xml" />
- <property name="infinispan-cluster-name"
value="JCR-cluster-locks-db1tck-ws" />
+ <property name="infinispan-cluster-name"
value="JCR-cluster" />
<property name="infinispan-cl-cache.jdbc.table.name"
value="jcrlocks_db1tck_ws" />
<property name="infinispan-cl-cache.jdbc.table.create"
value="true" />
<property name="infinispan-cl-cache.jdbc.table.drop"
value="false" />
@@ -383,7 +383,7 @@
<properties>
<property name="infinispan-configuration"
value="conf/standalone/cluster/test-infinispan-config.xml" />
<property name="jgroups-configuration"
value="flush-udp.xml" />
- <property name="infinispan-cluster-name"
value="JCR-cluster-db1tck-ws1" />
+ <property name="infinispan-cluster-name"
value="JCR-cluster" />
</properties>
</cache>
<query-handler
class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
@@ -402,7 +402,7 @@
<property name="time-out" value="15m" />
<property name="infinispan-configuration"
value="conf/standalone/cluster/test-infinispan-config.xml" />
<property name="jgroups-configuration"
value="flush-udp.xml" />
- <property name="infinispan-cluster-name"
value="JCR-cluster-locks-db1tck-ws1" />
+ <property name="infinispan-cluster-name"
value="JCR-cluster" />
<property name="infinispan-cl-cache.jdbc.table.name"
value="jcrlocks_db1tck_ws1" />
<property name="infinispan-cl-cache.jdbc.table.create"
value="true" />
<property name="infinispan-cl-cache.jdbc.table.drop"
value="false" />
@@ -446,7 +446,7 @@
<properties>
<property name="infinispan-configuration"
value="conf/standalone/cluster/test-infinispan-config.xml" />
<property name="jgroups-configuration"
value="flush-udp.xml" />
- <property name="infinispan-cluster-name"
value="JCR-cluster-db1tck-ws2" />
+ <property name="infinispan-cluster-name"
value="JCR-cluster" />
</properties>
</cache>
<query-handler
class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
@@ -468,7 +468,7 @@
<property name="time-out" value="15m" />
<property name="infinispan-configuration"
value="conf/standalone/cluster/test-infinispan-config.xml" />
<property name="jgroups-configuration"
value="flush-udp.xml" />
- <property name="infinispan-cluster-name"
value="JCR-cluster-locks-db1tck-ws2" />
+ <property name="infinispan-cluster-name"
value="JCR-cluster" />
<property name="infinispan-cl-cache.jdbc.table.name"
value="jcrlocks_db1tck_ws2" />
<property name="infinispan-cl-cache.jdbc.table.create"
value="true" />
<property name="infinispan-cl-cache.jdbc.table.drop"
value="false" />