[exo-jcr-commits] exo-jcr SVN: r5817 - in jcr/branches/1.15.x: exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query and 4 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Mar 6 08:32:27 EST 2012
Author: tolusha
Date: 2012-03-06 08:32:25 -0500 (Tue, 06 Mar 2012)
New Revision: 5817
Modified:
jcr/branches/1.15.x/exo.jcr.component.core.impl.infinispan.v5/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/LocalIndexChangesFilter.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/LocalIndexChangesFilter.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java
Log:
EXOJCR-1783: stopping shareable JBC
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2012-03-06 13:23:03 UTC (rev 5816)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2012-03-06 13:32:25 UTC (rev 5817)
@@ -506,6 +506,7 @@
public void stop()
{
super.stop();
+
if (shareable)
{
// The cache cannot be stopped since it can be shared so we evict the root node instead
@@ -513,10 +514,16 @@
cache.evict(lockRoot, true);
cache.getRegion(lockRoot, false).processEvictionQueues();
}
- else
+
+ try
{
- PrivilegedJBossCacheHelper.stop(cache);
+ ExoJBossCacheFactory.releaseUniqueInstance(CacheType.LOCK_CACHE, cache);
}
+ catch (RepositoryConfigurationException e)
+ {
+ LOG.error("Can not release cache instance", e);
+ }
+
if (jmxManager != null)
{
SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java 2012-03-06 13:23:03 UTC (rev 5816)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java 2012-03-06 13:32:25 UTC (rev 5817)
@@ -155,7 +155,6 @@
{
addNode(add.next());
}
-
}
/**
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java 2012-03-06 13:23:03 UTC (rev 5816)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java 2012-03-06 13:32:25 UTC (rev 5817)
@@ -282,6 +282,13 @@
LOG.warn("Not all JBoss Cache MBeans were unregistered.");
}
- PrivilegedJBossCacheHelper.stop(cache);
+ try
+ {
+ ExoJBossCacheFactory.releaseUniqueInstance(CacheType.INDEX_CACHE, cache);
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ LOG.error("Can not release cache instance", e);
+ }
}
}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/LocalIndexChangesFilter.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/LocalIndexChangesFilter.java 2012-03-06 13:23:03 UTC (rev 5816)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/LocalIndexChangesFilter.java 2012-03-06 13:32:25 UTC (rev 5817)
@@ -30,12 +30,13 @@
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.jbosscache.ExoJBossCacheFactory.CacheType;
import org.exoplatform.services.jcr.jbosscache.PrivilegedJBossCacheHelper;
-import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory.CacheType;
import org.exoplatform.services.jcr.util.IdGenerator;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
+import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.config.CacheLoaderConfig;
@@ -45,6 +46,8 @@
import java.io.IOException;
import java.io.Serializable;
import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import javax.jcr.RepositoryException;
@@ -176,19 +179,20 @@
cache.put(Fqn.fromRelativeElements(rootFqn, id), LISTWRAPPER, changes);
}
+
/**
- * @see java.lang.Object#finalize()
+ * {@inheritDoc}
*/
@Override
- protected void finalize() throws Throwable
+ public void close()
{
try
{
if (jmxManager != null)
{
- SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Void>()
{
- public Void run()
+ public Void run() throws CacheException
{
jmxManager.unregisterAllMBeans();
return null;
@@ -196,9 +200,18 @@
});
}
}
- finally
+ catch (PrivilegedActionException e)
{
- super.finalize();
+ log.warn("Not all JBoss Cache MBeans were unregistered.");
}
+
+ try
+ {
+ ExoJBossCacheFactory.releaseUniqueInstance(CacheType.INDEX_CACHE, cache);
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ log.error("Can not release cache instance", e);
+ }
}
}
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2012-03-06 13:23:03 UTC (rev 5816)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/BufferedJBossCache.java 2012-03-06 13:32:25 UTC (rev 5817)
@@ -19,8 +19,11 @@
package org.exoplatform.services.jcr.impl.dataflow.persistent.jbosscache;
import org.exoplatform.commons.utils.SecurityHelper;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.datamodel.ItemData;
import org.exoplatform.services.jcr.impl.core.itemfilters.QPathEntryFilter;
+import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory;
+import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory.CacheType;
import org.exoplatform.services.jcr.jbosscache.PrivilegedJBossCacheHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -741,7 +744,14 @@
*/
public void stop()
{
- PrivilegedJBossCacheHelper.stop(parentCache);
+ try
+ {
+ ExoJBossCacheFactory.releaseUniqueInstance(CacheType.JCR_CACHE, parentCache);
+ }
+ catch (RepositoryConfigurationException e)
+ {
+ LOG.error("Can not release cache instance", e);
+ }
}
public TransactionManager getTransactionManager()
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2012-03-06 13:23:03 UTC (rev 5816)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java 2012-03-06 13:32:25 UTC (rev 5817)
@@ -734,8 +734,10 @@
return null;
}
});
- }
+ }
+ cache.stop();
+
if (shareable)
{
// The cache cannot be stopped since it can be shared so we evict the root node instead
Modified: jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java 2012-03-06 13:23:03 UTC (rev 5816)
+++ jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/jbosscache/ExoJBossCacheFactory.java 2012-03-06 13:32:25 UTC (rev 5817)
@@ -40,9 +40,11 @@
import java.io.IOException;
import java.io.InputStream;
+import java.io.Serializable;
import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.Map;
+import java.util.Map.Entry;
import javax.management.ObjectName;
import javax.transaction.TransactionManager;
@@ -88,8 +90,8 @@
* A Map that contains all the registered JBC instances, ordered by
* {@link ExoContainer} instances, {@link CacheType} and JBC Configuration.
*/
- private static Map<ExoContainer, Map<CacheType, Map<ConfigurationKey, Cache>>> CACHES =
- new HashMap<ExoContainer, Map<CacheType, Map<ConfigurationKey, Cache>>>();
+ private static Map<ExoContainer, Map<CacheType, Map<ConfigurationKey, CacheInstance>>> CACHES =
+ new HashMap<ExoContainer, Map<CacheType, Map<ConfigurationKey, CacheInstance>>>();
private final TemplateConfigurationHelper configurationHelper;
@@ -272,16 +274,16 @@
return cache;
}
ExoContainer container = ExoContainerContext.getCurrentContainer();
- Map<CacheType, Map<ConfigurationKey, Cache>> allCacheTypes = CACHES.get(container);
+ Map<CacheType, Map<ConfigurationKey, CacheInstance>> allCacheTypes = CACHES.get(container);
if (allCacheTypes == null)
{
- allCacheTypes = new HashMap<CacheType, Map<ConfigurationKey, Cache>>();
+ allCacheTypes = new HashMap<CacheType, Map<ConfigurationKey, CacheInstance>>();
CACHES.put(container, allCacheTypes);
}
- Map<ConfigurationKey, Cache> caches = allCacheTypes.get(cacheType);
+ Map<ConfigurationKey, CacheInstance> caches = allCacheTypes.get(cacheType);
if (caches == null)
{
- caches = new HashMap<ConfigurationKey, Cache>();
+ caches = new HashMap<ConfigurationKey, CacheInstance>();
allCacheTypes.put(cacheType, caches);
}
Configuration cfg = cache.getConfiguration();
@@ -294,13 +296,21 @@
{
throw new RepositoryConfigurationException("Cannot clone the configuration.", e);
}
+
if (caches.containsKey(key))
{
- cache = caches.get(key);
+ CacheInstance cacheInstance = caches.get(key);
+ cacheInstance.acquire();
+
+ cache = cacheInstance.cache;
}
else
{
- caches.put(key, cache);
+ CacheInstance cacheInstance = new CacheInstance(cache);
+ cacheInstance.acquire();
+
+ caches.put(key, cacheInstance);
+
if (LOG.isInfoEnabled())
{
LOG.info("A new JBoss Cache instance has been registered for the region " + rootFqn + ", a cache of type "
@@ -316,6 +326,29 @@
return cache;
}
+ public static synchronized <K, V> void releaseUniqueInstance(CacheType cacheType, Cache<K, V> cache)
+ throws RepositoryConfigurationException
+ {
+ ExoContainer container = ExoContainerContext.getCurrentContainer();
+ Map<CacheType, Map<ConfigurationKey, CacheInstance>> allCacheTypes = CACHES.get(container);
+ Map<ConfigurationKey, CacheInstance> caches = allCacheTypes.get(cacheType);
+
+ for (Entry<ConfigurationKey, CacheInstance> entry : caches.entrySet())
+ {
+ CacheInstance cacheInstance = entry.getValue();
+ if (cacheInstance.isSame(cache))
+ {
+ cacheInstance.release();
+
+ if (!cacheInstance.hasReferences())
+ {
+ caches.remove(entry.getKey());
+ PrivilegedJBossCacheHelper.stop((Cache<Serializable, Object>)cache);
+ }
+ }
+ }
+ }
+
/**
* Gives the {@link JmxRegistrationManager} instance corresponding to the given context
*/
@@ -422,4 +455,39 @@
return true;
}
}
+
+ /**
+ * This class is used to store the actual amount of times cache was used.
+ */
+ private static class CacheInstance
+ {
+ private final Cache cache;
+
+ private int references;
+
+ public CacheInstance(Cache cache)
+ {
+ this.cache = cache;
+ }
+
+ private void acquire()
+ {
+ references++;
+ }
+
+ private void release()
+ {
+ references--;
+ }
+
+ private boolean hasReferences()
+ {
+ return references > 0;
+ }
+
+ private boolean isSame(Cache cache)
+ {
+ return this.cache == cache;
+ }
+ }
}
Modified: jcr/branches/1.15.x/exo.jcr.component.core.impl.infinispan.v5/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/LocalIndexChangesFilter.java
===================================================================
--- jcr/branches/1.15.x/exo.jcr.component.core.impl.infinispan.v5/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/LocalIndexChangesFilter.java 2012-03-06 13:23:03 UTC (rev 5816)
+++ jcr/branches/1.15.x/exo.jcr.component.core.impl.infinispan.v5/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/LocalIndexChangesFilter.java 2012-03-06 13:32:25 UTC (rev 5817)
@@ -29,6 +29,7 @@
import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
import org.exoplatform.services.jcr.impl.core.query.SearchManager;
import org.exoplatform.services.jcr.infinispan.ISPNCacheFactory;
+import org.exoplatform.services.jcr.infinispan.PrivilegedISPNCacheHelper;
import org.exoplatform.services.jcr.util.IdGenerator;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -112,4 +113,12 @@
ChangesKey changesKey = new ChangesKey(wsId, IdGenerator.generate());
cache.getAdvancedCache().withFlags(Flag.SKIP_LOCKING).put(changesKey, changes);
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void close()
+ {
+ PrivilegedISPNCacheHelper.stop(cache);
+ }
}
More information about the exo-jcr-commits
mailing list