Author: nzamosenchuk
Date: 2010-01-28 10:06:59 -0500 (Thu, 28 Jan 2010)
New Revision: 1610
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/config/LockManagerEntry.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
jcr/trunk/exo.jcr.component.core/src/main/resources/binding.xml
Log:
EXOJCR-425: Support of multiplexing added by using ExoCacheFactory that is responsible
pre-configured for cache creation. Also parameter (attribute-like parameter)
<jbosscacheConfig> from LockManagerEntry. JBossCache configuration should only be
provided by <property name="jbosscache-configuration"
value="path/to/file">.
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/config/LockManagerEntry.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/config/LockManagerEntry.java 2010-01-28
14:43:45 UTC (rev 1609)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/config/LockManagerEntry.java 2010-01-28
15:06:59 UTC (rev 1610)
@@ -29,8 +29,6 @@
private LockPersisterEntry persister;
- private String cacheConfig;
-
public long getTimeout()
{
return timeout;
@@ -51,14 +49,4 @@
this.persister = persister;
}
- public String getCacheConfig()
- {
- return cacheConfig;
- }
-
- public void steCacheConfig(String cacheConfig)
- {
- this.cacheConfig = cacheConfig;
- }
-
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java 2010-01-28
14:43:45 UTC (rev 1609)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManager.java 2010-01-28
15:06:59 UTC (rev 1610)
@@ -24,7 +24,6 @@
import org.exoplatform.services.jcr.access.SystemIdentity;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.config.SimpleParameterEntry;
-import org.exoplatform.services.jcr.config.TemplateConfigurationHelper;
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.dataflow.ChangesLogIterator;
import org.exoplatform.services.jcr.dataflow.CompositeChangesLog;
@@ -48,21 +47,18 @@
import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
import
org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
import org.exoplatform.services.jcr.impl.storage.JCRInvalidItemStateException;
+import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory;
import org.exoplatform.services.jcr.observation.ExtendedEvent;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.naming.InitialContextInitializer;
import org.exoplatform.services.transaction.TransactionService;
import org.jboss.cache.Cache;
-import org.jboss.cache.CacheFactory;
-import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
import org.jboss.cache.loader.CacheLoader;
import org.picocontainer.Startable;
-import java.io.IOException;
-import java.io.InputStream;
import java.io.Serializable;
import java.math.BigInteger;
import java.security.MessageDigest;
@@ -185,7 +181,8 @@
* @throws RepositoryConfigurationException
*/
public CacheableLockManager(WorkspacePersistentDataManager dataManager, WorkspaceEntry
config,
- InitialContextInitializer context, TransactionService
transactionService,ConfigurationManager cfm) throws RepositoryConfigurationException
+ InitialContextInitializer context, TransactionService transactionService,
ConfigurationManager cfm)
+ throws RepositoryConfigurationException
{
this(dataManager, config, context, transactionService.getTransactionManager(),
cfm);
}
@@ -199,9 +196,9 @@
* @throws RepositoryConfigurationException
*/
public CacheableLockManager(WorkspacePersistentDataManager dataManager, WorkspaceEntry
config,
- InitialContextInitializer context,ConfigurationManager cfm) throws
RepositoryConfigurationException
+ InitialContextInitializer context, ConfigurationManager cfm) throws
RepositoryConfigurationException
{
- this(dataManager, config, context, (TransactionManager)null,cfm);
+ this(dataManager, config, context, (TransactionManager)null, cfm);
}
/**
@@ -215,7 +212,8 @@
* @throws RepositoryConfigurationException
*/
public CacheableLockManager(WorkspacePersistentDataManager dataManager, WorkspaceEntry
config,
- InitialContextInitializer context, TransactionManager transactionManager,
ConfigurationManager cfm) throws RepositoryConfigurationException
+ InitialContextInitializer context, TransactionManager transactionManager,
ConfigurationManager cfm)
+ throws RepositoryConfigurationException
{
lockRoot = Fqn.fromElements(LOCKS);
@@ -248,38 +246,16 @@
dataManager.addItemPersistenceListener(this);
// make cache
- if (config.getLockManager() != null
- && (config.getLockManager().getCacheConfig() != null || (paramenerts !=
null && config.getLockManager()
- .getParameterValue(JBOSSCACCHE_CONFIG, null) != null)))
+ if (config.getLockManager() != null)
{
- String jbcConfig =
- (paramenerts != null &&
config.getLockManager().getParameterValue(JBOSSCACCHE_CONFIG, null) != null)
- ? config.getLockManager().getParameterValue(JBOSSCACCHE_CONFIG) :
config.getLockManager()
- .getCacheConfig();
-
- // initialize template
- TemplateConfigurationHelper configurationHelper =
TemplateConfigurationHelper.createJBossCacheHelper(cfm);
- InputStream configStream;
- try
- {
- // fill template
- configStream = configurationHelper.fillTemplate(jbcConfig,
config.getLockManager().getParameters());
- }
- catch (IOException e)
- {
- throw new RepositoryConfigurationException(e);
- }
-
- CacheFactory<Serializable, Object> factory = new
DefaultCacheFactory<Serializable, Object>();
-
- cache = factory.createCache(configStream, false);
-
this.tm = transactionManager;
- if (transactionManager != null)
- {
-
cache.getConfiguration().getRuntimeConfig().setTransactionManager(transactionManager);
- }
+ // create cache using custom factory
+ ExoJBossCacheFactory<Serializable, Object> factory =
+ new ExoJBossCacheFactory<Serializable, Object>(cfm,
transactionManager);
+
+ cache = factory.createCache(config.getLockManager());
+
cache.create();
cache.start();
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java 2010-01-28
14:43:45 UTC (rev 1609)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java 2010-01-28
15:06:59 UTC (rev 1610)
@@ -29,6 +29,7 @@
import org.exoplatform.services.jcr.impl.core.query.IndexingTree;
import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
import org.exoplatform.services.jcr.impl.core.query.SearchManager;
+import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory;
import org.exoplatform.services.jcr.util.IdGenerator;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -77,25 +78,10 @@
RepositoryConfigurationException
{
super(searchManager, parentSearchManager, config, indexingTree, parentIndexingTree,
handler, parentHandler, cfm);
- String jbcConfig =
config.getParameterValue(QueryHandlerParams.PARAM_JBOSSCACHE_CONFIGURATION);
+ // create cache using custom factory
+ ExoJBossCacheFactory<Serializable, Object> factory = new
ExoJBossCacheFactory<Serializable, Object>(cfm);
+ this.cache = factory.createCache(config);
- // initialize template
- TemplateConfigurationHelper configurationHelper =
TemplateConfigurationHelper.createJBossCacheHelper(cfm);
- InputStream configStream;
- try
- {
- // fill template
- configStream = configurationHelper.fillTemplate(jbcConfig,
config.getParameters());
- }
- catch (IOException e)
- {
- throw new RepositoryConfigurationException(e);
- }
-
- CacheFactory<Serializable, Object> factory = new
DefaultCacheFactory<Serializable, Object>();
- log.info("JBoss Cache configuration used: " + jbcConfig);
- this.cache = factory.createCache(configStream, false);
-
// initialize IndexerCacheLoader
IndexerCacheLoader indexerCacheLoader = new IndexerCacheLoader();
// inject dependencies
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-01-28
14:43:45 UTC (rev 1609)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2010-01-28
15:06:59 UTC (rev 1610)
@@ -36,6 +36,7 @@
import org.exoplatform.services.jcr.impl.Constants;
import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
+import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.transaction.TransactionService;
@@ -257,36 +258,18 @@
* @throws RepositoryException if error of initialization
* @throws RepositoryConfigurationException if error of configuration
*/
- public JBossCacheWorkspaceStorageCache(WorkspaceEntry wsConfig, TransactionService
transactionService, ConfigurationManager cfm)
- throws RepositoryException, RepositoryConfigurationException
+ public JBossCacheWorkspaceStorageCache(WorkspaceEntry wsConfig, TransactionService
transactionService,
+ ConfigurationManager cfm) throws RepositoryException,
RepositoryConfigurationException
{
if (wsConfig.getCache() == null)
{
throw new RepositoryConfigurationException("Cache configuration not
found");
}
- String jbcConfig = wsConfig.getCache().getParameterValue(JBOSSCACHE_CONFIG);
-
- CacheFactory<Serializable, Object> factory = new
DefaultCacheFactory<Serializable, Object>();
- LOG.info("JBoss Cache configuration used: " + jbcConfig);
-
- // initialize template
- TemplateConfigurationHelper configurationHelper =
TemplateConfigurationHelper.createJBossCacheHelper(cfm);
- InputStream configStream;
- try
- {
- // fill template
- configStream = configurationHelper.fillTemplate(jbcConfig,
wsConfig.getCache().getParameters());
- }
- catch (IOException e)
- {
- throw new RepositoryConfigurationException(e);
- }
- this.cache = new BufferedJBossCache(factory.createCache(configStream, false));
- if (transactionService.getTransactionManager() != null)
- {
-
cache.getConfiguration().getRuntimeConfig().setTransactionManager(transactionService.getTransactionManager());
- }
+ // create cache using custom factory
+ ExoJBossCacheFactory<Serializable, Object> factory =
+ new ExoJBossCacheFactory<Serializable, Object>(cfm,
transactionService.getTransactionManager());
+ this.cache = new BufferedJBossCache(factory.createCache(wsConfig.getCache()));
this.itemsRoot = Fqn.fromElements(ITEMS);
this.childNodes = Fqn.fromElements(CHILD_NODES);
@@ -311,8 +294,8 @@
* @throws RepositoryException if error of initialization
* @throws RepositoryConfigurationException if error of configuration
*/
- public JBossCacheWorkspaceStorageCache(WorkspaceEntry wsConfig, ConfigurationManager
cfm) throws RepositoryException,
- RepositoryConfigurationException
+ public JBossCacheWorkspaceStorageCache(WorkspaceEntry wsConfig, ConfigurationManager
cfm)
+ throws RepositoryException, RepositoryConfigurationException
{
this(wsConfig, null, cfm);
}
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java 2010-01-28
15:06:59 UTC (rev 1610)
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.jbosscache;
+
+import org.exoplatform.container.configuration.ConfigurationManager;
+import org.exoplatform.services.jcr.config.MappedParametrizedObjectEntry;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.config.TemplateConfigurationHelper;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheFactory;
+import org.jboss.cache.DefaultCacheFactory;
+import org.jgroups.JChannelFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.transaction.TransactionManager;
+
+/**
+ * Factory that creates pre-configured instances of JBossCache, without starting it.
+ * Path to JBossCache configuration or template should be provided as
+ * "jbosscache-configuration" property in parameterEntry instance. If
+ * transaction manager is configure in ExoJBossCacheFactory, then it
+ * is injected into the cache instance.
+ * <br>
+ * If parameterEntry has "jgroups-multiplexer-stack" (=true) and
+ * "jgroups-configuration" parameters then Multiplexing stack is enabled
+ * in JBossCache (this is highly recommended by RH specialists).
+ *
+ * @author <a href="mailto:nikolazius@gmail.com">Nikolay
Zamosenchuk</a>
+ * @version $Id: ExoCacheFactoryImpl.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
+ *
+ */
+public class ExoJBossCacheFactory<K, V>
+{
+
+ public static final String JBOSSCACHE_CONFIG = "jbosscache-configuration";
+
+ public static final String JGROUPS_CONFIG = "jgroups-configuration";
+
+ public static final String JGROUPS_MUX_ENABLED =
"jgroups-multiplexer-stack";
+
+ private final TemplateConfigurationHelper configurationHelper;
+
+ private final TransactionManager transactionManager;
+
+ private final Log log = ExoLogger.getLogger(ExoJBossCacheFactory.class);
+
+ /**
+ * Creates ExoJbossCacheFactory with provided configuration transaction managers.
+ * Transaction manager will later be injected to cache instance.
+ *
+ * @param configurationManager
+ * @param transactionManager
+ */
+ public ExoJBossCacheFactory(ConfigurationManager configurationManager,
TransactionManager transactionManager)
+ {
+ this.configurationHelper =
TemplateConfigurationHelper.createJBossCacheHelper(configurationManager);
+ this.transactionManager = transactionManager;
+ }
+
+ /**
+ * Creates ExoJbossCacheFactory with provided configuration manager and without
transaction manager.
+ *
+ * @param configurationManager
+ */
+ public ExoJBossCacheFactory(ConfigurationManager configurationManager)
+ {
+ this.configurationHelper =
TemplateConfigurationHelper.createJBossCacheHelper(configurationManager);
+ this.transactionManager = null;
+ }
+
+ /**
+ * Creates pre-configured instance of JBossCache, without starting it.
+ * Path to JBossCache configuration or template should be provided as
+ * "jbosscache-configuration" property in parameterEntry instance. If
+ * transaction manager is configure in ExoJBossCacheFactory, then it
+ * is injected into the cache instance.
+ * <br>
+ * If parameterEntry has "jgroups-multiplexer-stack" (=true) and
+ * "jgroups-configuration" parameters then Multiplexing stack is enabled
+ * in JBossCache (this is highly recommended by RH specialists).
+ *
+ * @param parameterEntry
+ * @return
+ * @throws RepositoryConfigurationException
+ */
+ public Cache<K, V> createCache(MappedParametrizedObjectEntry parameterEntry)
throws RepositoryConfigurationException
+ {
+ // get JBossCache configuration file path
+ String jBossCacheConfigurationPath =
parameterEntry.getParameterValue(JBOSSCACHE_CONFIG);
+ log.info("JBoss Cache configuration/template used: " +
jBossCacheConfigurationPath);
+
+ // prepare configuration
+ InputStream configStream;
+ try
+ {
+ // fill template
+ configStream = configurationHelper.fillTemplate(jBossCacheConfigurationPath,
parameterEntry.getParameters());
+ }
+ catch (IOException e)
+ {
+ throw new RepositoryConfigurationException(e);
+ }
+
+ // create cache
+ CacheFactory<K, V> factory = new DefaultCacheFactory<K, V>();
+ Cache<K, V> cache = factory.createCache(configStream, false);
+
+ // inject transaction manager if defined
+ if (transactionManager != null)
+ {
+
cache.getConfiguration().getRuntimeConfig().setTransactionManager(transactionManager);
+ }
+
+ // JGroups multiplexer configuration if enabled
+ if (parameterEntry.getParameterBoolean(JGROUPS_MUX_ENABLED, false))
+ {
+ try
+ {
+ // Get path to JGroups configuration
+ String jgroupsConfigurationFilePath =
parameterEntry.getParameterValue(JGROUPS_CONFIG);
+ if (jgroupsConfigurationFilePath != null)
+ {
+ // Create and inject multiplexer fatory
+ JChannelFactory muxFactory = new JChannelFactory();
+ muxFactory.setMultiplexerConfig(jgroupsConfigurationFilePath);
+
cache.getConfiguration().getRuntimeConfig().setMuxChannelFactory(muxFactory);
+ log.info("Multiplexer stack successfully inabled for the
cache.");
+ }
+ }
+ catch (Exception e)
+ {
+ // exception occurred setting mux factory
+ e.printStackTrace();
+ throw new RepositoryConfigurationException("Error setting multiplexer
configuration.", e);
+ }
+ }
+ return cache;
+ }
+}
Property changes on:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jcr/trunk/exo.jcr.component.core/src/main/resources/binding.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/resources/binding.xml 2010-01-28 14:43:45
UTC (rev 1609)
+++ jcr/trunk/exo.jcr.component.core/src/main/resources/binding.xml 2010-01-28 15:06:59
UTC (rev 1610)
@@ -71,7 +71,6 @@
factory="org.jibx.runtime.Utility.arrayListFactory" />
<value name="time-out" field="timeout"
usage="optional"
deserializer="org.exoplatform.services.jcr.util.ConfigurationFormat.parseTime"
/>
- <value name="jbosscache-configuration" field="cacheConfig"
usage="optional" />
<structure name="persister" field="persister"
usage="optional">
<value name="class" field="type"
style="attribute" />