Author: tolusha
Date: 2010-06-16 05:50:33 -0400 (Wed, 16 Jun 2010)
New Revision: 2628
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedCacheHelper.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.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/core/query/jbosscache/JBossCacheIndexInfos.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexUpdateMonitor.java
Log:
EXOJCR-756: replace cache operations on privileged cache operations
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-06-16
08:57:47 UTC (rev 2627)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/lock/jbosscache/CacheableLockManagerImpl.java 2010-06-16
09:50:33 UTC (rev 2628)
@@ -49,6 +49,7 @@
import org.exoplatform.services.jcr.impl.storage.JCRInvalidItemStateException;
import org.exoplatform.services.jcr.impl.storage.jdbc.DBConstants;
import org.exoplatform.services.jcr.impl.storage.jdbc.DialectDetecter;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedCacheHelper;
import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory;
import org.exoplatform.services.jcr.observation.ExtendedEvent;
import org.exoplatform.services.log.ExoLogger;
@@ -71,7 +72,6 @@
import java.security.AccessController;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
-import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.sql.Connection;
@@ -258,28 +258,12 @@
cache = factory.createCache(config.getLockManager());
- PrivilegedAction<Object> action = new PrivilegedAction<Object>()
- {
- public Object run()
- {
- cache.create();
- return null;
- }
- };
- AccessController.doPrivileged(action);
+ PrivilegedCacheHelper.create(cache);
// Add the cache loader needed to prevent TimeoutException
addCacheLoader();
- action = new PrivilegedAction<Object>()
- {
- public Object run()
- {
- cache.start();
- return null;
- }
- };
- AccessController.doPrivileged(action);
+ PrivilegedCacheHelper.start(cache);
createStructuredNode(lockRoot);
@@ -768,7 +752,7 @@
public Object execute(LockData newLockData) throws LockException
{
Fqn<String> fqn = makeLockFqn(newLockData.getNodeIdentifier());
- Object oldValue = cache.put(fqn, LOCK_DATA, newLockData);
+ Object oldValue = PrivilegedCacheHelper.put(cache, fqn, LOCK_DATA,
newLockData);
if (oldValue == null)
{
throw new LockException("Can't refresh lock for node " +
newLockData.getNodeIdentifier()
@@ -830,15 +814,7 @@
lockRemover.interrupt();
sessionLockManagers.clear();
- PrivilegedAction<Object> action = new PrivilegedAction<Object>()
- {
- public Object run()
- {
- cache.stop();
- return null;
- }
- };
- AccessController.doPrivileged(action);
+ PrivilegedCacheHelper.stop(cache);
}
/**
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-06-16
08:57:47 UTC (rev 2627)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexChangesFilter.java 2010-06-16
09:50:33 UTC (rev 2628)
@@ -28,6 +28,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.impl.util.io.PrivilegedCacheHelper;
import org.exoplatform.services.jcr.jbosscache.ExoJBossCacheFactory;
import org.exoplatform.services.jcr.util.IdGenerator;
import org.exoplatform.services.log.ExoLogger;
@@ -90,8 +91,7 @@
// try to get pushState parameters, since they are set programmatically only
Boolean pushState =
config.getParameterBoolean(QueryHandlerParams.PARAM_JBOSSCACHE_PUSHSTATE, false);
- Long pushStateTimeOut =
- config.getParameterTime(QueryHandlerParams.PARAM_JBOSSCACHE_PUSHSTATE_TIMEOUT,
10000L);
+ Long pushStateTimeOut =
config.getParameterTime(QueryHandlerParams.PARAM_JBOSSCACHE_PUSHSTATE_TIMEOUT, 10000L);
singletonStoreProperties.setProperty("pushStateWhenCoordinator",
pushState.toString());
singletonStoreProperties.setProperty("pushStateWhenCoordinatorTimeout",
pushStateTimeOut.toString());
@@ -115,8 +115,10 @@
cacheLoaderConfig.addIndividualCacheLoaderConfig(individualCacheLoaderConfig);
// insert CacheLoaderConfig
this.cache.getConfiguration().setCacheLoaderConfig(cacheLoaderConfig);
- this.cache.create();
- this.cache.start();
+
+ PrivilegedCacheHelper.create(cache);
+ PrivilegedCacheHelper.start(cache);
+
// start will invoke cache listener which will notify handler that mode is changed
IndexerIoMode ioMode =
((CacheSPI)cache).getRPCManager().isCoordinator() ? IndexerIoMode.READ_WRITE :
IndexerIoMode.READ_ONLY;
@@ -149,8 +151,8 @@
String id = IdGenerator.generate();
try
{
- cache.put(id, LISTWRAPPER, new ChangesFilterListsWrapper(addedNodes,
removedNodes, parentAddedNodes,
- parentRemovedNodes));
+ PrivilegedCacheHelper.put(cache, id, LISTWRAPPER, new
ChangesFilterListsWrapper(addedNodes, removedNodes,
+ parentAddedNodes, parentRemovedNodes));
}
catch (CacheException e)
{
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexInfos.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexInfos.java 2010-06-16
08:57:47 UTC (rev 2627)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexInfos.java 2010-06-16
09:50:33 UTC (rev 2628)
@@ -23,6 +23,7 @@
import org.exoplatform.services.jcr.impl.core.query.IndexerIoModeListener;
import org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos;
import org.exoplatform.services.jcr.impl.core.query.lucene.MultiIndex;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedCacheHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
@@ -158,7 +159,7 @@
// write to FS
super.write();
// write to cache
- cache.put(namesFqn, LIST_KEY, getNames());
+ PrivilegedCacheHelper.put(cache, namesFqn, LIST_KEY, getNames());
}
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexUpdateMonitor.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexUpdateMonitor.java 2010-06-16
08:57:47 UTC (rev 2627)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexUpdateMonitor.java 2010-06-16
09:50:33 UTC (rev 2628)
@@ -24,6 +24,7 @@
import org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos;
import org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitor;
import org.exoplatform.services.jcr.impl.core.query.lucene.IndexUpdateMonitorListener;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedCacheHelper;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
@@ -156,7 +157,7 @@
localUpdateInProgress = updateInProgress;
if (persitentUpdate)
{
- cache.put(parametersFqn, PARAMETER_NAME, new Boolean(updateInProgress));
+ PrivilegedCacheHelper.put(cache, parametersFqn, PARAMETER_NAME, new
Boolean(updateInProgress));
}
for (IndexUpdateMonitorListener listener : listeners)
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedCacheHelper.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedCacheHelper.java
(rev 0)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedCacheHelper.java 2010-06-16
09:50:33 UTC (rev 2628)
@@ -0,0 +1,166 @@
+/*
+ * 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.impl.util.io;
+
+import org.jboss.cache.Cache;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.Fqn;
+
+import java.io.Serializable;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * @author <a href="anatoliy.bazko(a)exoplatform.org">Anatoliy
Bazko</a>
+ * @version $Id: PrivilegedCacheHelper.java 111 2010-11-11 11:11:11Z tolusha $
+ *
+ */
+public class PrivilegedCacheHelper
+{
+ /**
+ * Start cache in privileged mode.
+ *
+ * @param cache
+ */
+ public static void start(final Cache<Serializable, Object> cache)
+ {
+ PrivilegedAction<Object> action = new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ cache.start();
+ return null;
+ }
+ };
+ AccessController.doPrivileged(action);
+ }
+
+ /**
+ * Stop cache in privileged mode.
+ *
+ * @param cache
+ */
+ public static void stop(final Cache<Serializable, Object> cache)
+ {
+ PrivilegedAction<Object> action = new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ cache.stop();
+ return null;
+ }
+ };
+ AccessController.doPrivileged(action);
+ }
+
+ /**
+ * Create cache in privileged mode.
+ *
+ * @param cache
+ */
+ public static void create(final Cache<Serializable, Object> cache)
+ {
+ PrivilegedAction<Object> action = new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ cache.create();
+ return null;
+ }
+ };
+ AccessController.doPrivileged(action);
+ }
+
+ /**
+ * Put in cache in privileged mode.
+ *
+ * @param cache
+ */
+ public static Object put(final Cache<Serializable, Object> cache, final String
fqn, final Serializable key,
+ final Object value) throws CacheException
+ {
+ PrivilegedExceptionAction<Object> action = new
PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ return cache.put(fqn, key, value);
+
+ }
+ };
+ try
+ {
+ return AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof CacheException)
+ {
+ throw (CacheException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
+ }
+
+ /**
+ * Put in cache in privileged mode.
+ *
+ * @param cache
+ */
+ public static Object put(final Cache<Serializable, Object> cache, final Fqn fqn,
final Serializable key,
+ final Object value) throws CacheException
+ {
+ PrivilegedExceptionAction<Object> action = new
PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ return cache.put(fqn, key, value);
+ }
+ };
+ try
+ {
+ return AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof CacheException)
+ {
+ throw (CacheException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
+ }
+}