exo-jcr SVN: r4024 - in kernel/trunk/exo.kernel.container/src: test/java/org/exoplatform/container and 1 other directories.
by do-not-reply@jboss.org
Author: nfilotto
Date: 2011-02-28 07:30:08 -0500 (Mon, 28 Feb 2011)
New Revision: 4024
Added:
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/util/
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/util/TestContainerUtil.java
Modified:
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java
Log:
EXOJCR-1089: Now the ContainerUtil get rid of any resources found into the WEB-INF directory
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java 2011-02-28 09:25:46 UTC (rev 4023)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/util/ContainerUtil.java 2011-02-28 12:30:08 UTC (rev 4024)
@@ -86,10 +86,17 @@
Map<String, URL> map = new HashMap<String, URL>();
Iterator i = c.iterator();
+ String forbiddenSuffix = "WEB-INF/" + configuration;
while (i.hasNext())
{
URL url = (URL)i.next();
String key = url.toString();
+ // The content of the WEB-INF folder is part of the CL in JBoss AS 6 so
+ // we have to get rid of it in order to prevent any boot issues
+ if (key.endsWith(forbiddenSuffix))
+ {
+ continue;
+ }
// jboss bug, jboss has a very weird behavior. It copy all the jar files
// and
// deploy them to a temp dir and include both jars, the one in sar and tmp
Added: kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/util/TestContainerUtil.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/util/TestContainerUtil.java (rev 0)
+++ kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/util/TestContainerUtil.java 2011-02-28 12:30:08 UTC (rev 4024)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2011 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.container.util;
+
+import junit.framework.TestCase;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ */
+public class TestContainerUtil extends TestCase
+{
+
+ public void testJBossAS6CL() throws Exception
+ {
+ ClassLoader oldCLoader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Thread.currentThread().setContextClassLoader(new JBossAS6MockClassLoader());
+ Collection<URL> urls = ContainerUtil.getConfigurationURL("conf/configuration.xml");
+ assertNotNull(urls);
+ assertEquals(3, urls.size());
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(oldCLoader);
+ }
+ }
+
+ private static class JBossAS6MockClassLoader extends ClassLoader
+ {
+
+ @Override
+ public Enumeration<URL> getResources(String name) throws IOException
+ {
+ List<URL> urls = new ArrayList<URL>();
+ urls.add(new URL("file:///GateIn-JBoss6/server/default/deploy/gatein.ear/lib/exo.portal.webui.portal.jar/conf/configuration.xml"));
+ urls.add(new URL("file:///GateIn-JBoss6/server/default/deploy/gatein.ear/lib/exo.core.component.xml-processing/conf/configuration.xml"));
+ urls.add(new URL("file:///GateIn-JBoss6/server/default/deploy/gatein-sample-extension.ear/sample-ext.war/WEB-INF/conf/configuration.xml"));
+ urls.add(new URL("file:///GateIn-JBoss6/server/default/deploy/gatein.ear/lib/exo.kernel.commons.jar/conf/configuration.xml"));
+ return Collections.enumeration(urls);
+ }
+
+ }
+}
13 years, 1 month
exo-jcr SVN: r4023 - in jcr/trunk/exo.jcr.component.core/src: test/resources/conf/standalone/cluster and 1 other directory.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2011-02-28 04:25:46 -0500 (Mon, 28 Feb 2011)
New Revision: 4023
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/AbstractIndexerCacheStore.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/LocalIndexCacheStore.java
Removed:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/AbstractInputCacheStore.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/ISPNIndexChangesFilter.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/IndexerCacheStore.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/LocalIndexChangesFilter.java
jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-infinispan-indexer.xml
Log:
EXOJCR-832 : Added CacheStore implementations for default and local index behaviors.
Copied: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/AbstractIndexerCacheStore.java (from rev 4018, jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/AbstractInputCacheStore.java)
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/AbstractIndexerCacheStore.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/AbstractIndexerCacheStore.java 2011-02-28 09:25:46 UTC (rev 4023)
@@ -0,0 +1,218 @@
+/*
+ * Copyright (C) 2011 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.core.query.ispn;
+
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.impl.core.query.Indexer;
+import org.exoplatform.services.jcr.impl.core.query.IndexerIoMode;
+import org.exoplatform.services.jcr.impl.core.query.IndexerIoModeHandler;
+import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
+import org.exoplatform.services.jcr.impl.core.query.SearchManager;
+import org.exoplatform.services.jcr.impl.core.query.jbosscache.ChangesFilterListsWrapper;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.infinispan.container.entries.InternalCacheEntry;
+import org.infinispan.loaders.AbstractCacheStore;
+import org.infinispan.loaders.AbstractCacheStoreConfig;
+import org.infinispan.loaders.CacheLoaderConfig;
+import org.infinispan.loaders.CacheLoaderException;
+
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Abstract Indexer Cache Loader defines default implementation of data processing received via cache.
+ *
+ * @author <a href="mailto:nikolazius@gmail.com">Nikolay Zamosenchuk</a>
+ * @version $Id: AbstractInputCacheStore.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
+ *
+ */
+public abstract class AbstractIndexerCacheStore extends AbstractCacheStore
+{
+
+ /**
+ * A map of all the indexers that has been registered
+ */
+ protected final Map<Integer, Indexer> indexers = new HashMap<Integer, Indexer>();
+
+ protected static final Log log = ExoLogger.getLogger("exo.jcr.component.core.IndexerCacheLoader");
+
+ /**
+ * This method will register a new Indexer according to the given parameters.
+ *
+ * @param searchManager
+ * @param parentSearchManager
+ * @param handler
+ * @param parentHandler
+ * @throws RepositoryConfigurationException
+ */
+ public void register(SearchManager searchManager, SearchManager parentSearchManager, QueryHandler handler,
+ QueryHandler parentHandler) throws RepositoryConfigurationException
+ {
+ indexers.put(searchManager.getWsId().hashCode(), new Indexer(searchManager, parentSearchManager, handler,
+ parentHandler));
+ if (log.isDebugEnabled())
+ {
+ log.debug("Register " + searchManager.getWsId() + " " + this + " in " + indexers);
+ }
+ }
+
+ /**
+ * @see org.infinispan.loaders.CacheStore#store(org.infinispan.container.entries.InternalCacheEntry)
+ */
+ public void store(InternalCacheEntry entry) throws CacheLoaderException
+ {
+ if (entry.getValue() instanceof ChangesFilterListsWrapper && entry.getKey() instanceof ChangesKey)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.info("Received list wrapper, start indexing...");
+ }
+ // updating index
+ ChangesFilterListsWrapper wrapper = (ChangesFilterListsWrapper)entry.getValue();
+ ChangesKey key = (ChangesKey)entry.getKey();
+ try
+ {
+ Indexer indexer = indexers.get(key.getWsId());
+ if (indexer == null)
+ {
+ log.warn("No indexer could be found for the cache entry " + key.toString());
+ if (log.isDebugEnabled())
+ {
+ log.debug("The current content of the map of indexers is " + indexers);
+ }
+ }
+ else if (wrapper.withChanges())
+ {
+ indexer.updateIndex(wrapper.getChanges(), wrapper.getParentChanges());
+ }
+ else
+ {
+ indexer.updateIndex(wrapper.getAddedNodes(), wrapper.getRemovedNodes(), wrapper.getParentAddedNodes(),
+ wrapper.getParentRemovedNodes());
+ }
+ }
+ finally
+ {
+ if (getModeHandler().getMode() == IndexerIoMode.READ_WRITE)
+ {
+ // remove the data from the cache
+ cache.remove(key);
+ }
+ }
+ }
+ }
+
+ /**
+ * @return IndexerIoModeHandler instance
+ */
+ public abstract IndexerIoModeHandler getModeHandler();
+
+ // ===================================================
+
+ /**
+ * @see org.infinispan.loaders.CacheLoader#getConfigurationClass()
+ */
+ public Class<? extends CacheLoaderConfig> getConfigurationClass()
+ {
+ return AbstractCacheStoreConfig.class;
+ }
+
+ /**
+ * @see org.infinispan.loaders.CacheStore#fromStream(java.io.ObjectInput)
+ */
+ public void fromStream(ObjectInput inputStream) throws CacheLoaderException
+ {
+ throw new UnsupportedOperationException("This operation is not supported by this component.");
+ }
+
+ /**
+ * @see org.infinispan.loaders.CacheStore#toStream(java.io.ObjectOutput)
+ */
+ public void toStream(ObjectOutput outputStream) throws CacheLoaderException
+ {
+ throw new UnsupportedOperationException("This operation is not supported by this component.");
+ }
+
+ /**
+ * @see org.infinispan.loaders.AbstractCacheStore#purgeInternal()
+ */
+ @Override
+ protected void purgeInternal() throws CacheLoaderException
+ {
+ // This cacheStore only accepts data
+ }
+
+ /**
+ * @see org.infinispan.loaders.CacheStore#clear()
+ */
+ public void clear() throws CacheLoaderException
+ {
+ throw new UnsupportedOperationException("This operation is not supported by this component.");
+ }
+
+ /**
+ * @see org.infinispan.loaders.CacheStore#remove(java.lang.Object)
+ */
+ public boolean remove(Object key) throws CacheLoaderException
+ {
+ // This cacheStore only accepts data
+ return true;
+ }
+
+ /**
+ * @see org.infinispan.loaders.CacheLoader#load(java.lang.Object)
+ */
+ public InternalCacheEntry load(Object key) throws CacheLoaderException
+ {
+ // This cacheStore only accepts data
+ return null;
+ }
+
+ /**
+ * @see org.infinispan.loaders.CacheLoader#load(int)
+ */
+ public Set<InternalCacheEntry> load(int numEntries) throws CacheLoaderException
+ {
+ // This cacheStore only accepts data
+ return null;
+ }
+
+ /**
+ * @see org.infinispan.loaders.CacheLoader#loadAll()
+ */
+ public Set<InternalCacheEntry> loadAll() throws CacheLoaderException
+ {
+ // This cacheStore only accepts data
+ return null;
+ }
+
+ /**
+ * @see org.infinispan.loaders.CacheLoader#loadAllKeys(java.util.Set)
+ */
+ public Set<Object> loadAllKeys(Set<Object> keysToExclude) throws CacheLoaderException
+ {
+ // This cacheStore only accepts data
+ return null;
+ }
+
+}
\ No newline at end of file
Property changes on: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/AbstractIndexerCacheStore.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/AbstractInputCacheStore.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/AbstractInputCacheStore.java 2011-02-28 07:46:58 UTC (rev 4022)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/AbstractInputCacheStore.java 2011-02-28 09:25:46 UTC (rev 4023)
@@ -1,133 +0,0 @@
-/*
- * Copyright (C) 2011 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.core.query.ispn;
-
-import org.infinispan.container.entries.InternalCacheEntry;
-import org.infinispan.loaders.AbstractCacheStore;
-import org.infinispan.loaders.AbstractCacheStoreConfig;
-import org.infinispan.loaders.CacheLoaderConfig;
-import org.infinispan.loaders.CacheLoaderException;
-
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Set;
-
-/**
- * @author <a href="mailto:nikolazius@gmail.com">Nikolay Zamosenchuk</a>
- * @version $Id: AbstractInputCacheStore.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
- *
- */
-public abstract class AbstractInputCacheStore extends AbstractCacheStore
-{
-
- /**
- *
- */
- public AbstractInputCacheStore()
- {
- super();
- }
-
- /**
- * @see org.infinispan.loaders.CacheLoader#getConfigurationClass()
- */
- public Class<? extends CacheLoaderConfig> getConfigurationClass()
- {
- return AbstractCacheStoreConfig.class;
- }
-
- /**
- * @see org.infinispan.loaders.CacheStore#fromStream(java.io.ObjectInput)
- */
- public void fromStream(ObjectInput inputStream) throws CacheLoaderException
- {
- throw new UnsupportedOperationException("This operation is not supported by this component.");
- }
-
- /**
- * @see org.infinispan.loaders.CacheStore#toStream(java.io.ObjectOutput)
- */
- public void toStream(ObjectOutput outputStream) throws CacheLoaderException
- {
- throw new UnsupportedOperationException("This operation is not supported by this component.");
- }
-
- /**
- * @see org.infinispan.loaders.AbstractCacheStore#purgeInternal()
- */
- @Override
- protected void purgeInternal() throws CacheLoaderException
- {
- // This cacheStore only accepts data
- }
-
- /**
- * @see org.infinispan.loaders.CacheStore#clear()
- */
- public void clear() throws CacheLoaderException
- {
- throw new UnsupportedOperationException("This operation is not supported by this component.");
- }
-
- /**
- * @see org.infinispan.loaders.CacheStore#remove(java.lang.Object)
- */
- public boolean remove(Object key) throws CacheLoaderException
- {
- // This cacheStore only accepts data
- return false;
- }
-
- /**
- * @see org.infinispan.loaders.CacheLoader#load(java.lang.Object)
- */
- public InternalCacheEntry load(Object key) throws CacheLoaderException
- {
- // This cacheStore only accepts data
- return null;
- }
-
- /**
- * @see org.infinispan.loaders.CacheLoader#load(int)
- */
- public Set<InternalCacheEntry> load(int numEntries) throws CacheLoaderException
- {
- // This cacheStore only accepts data
- return null;
- }
-
- /**
- * @see org.infinispan.loaders.CacheLoader#loadAll()
- */
- public Set<InternalCacheEntry> loadAll() throws CacheLoaderException
- {
- // This cacheStore only accepts data
- return null;
- }
-
- /**
- * @see org.infinispan.loaders.CacheLoader#loadAllKeys(java.util.Set)
- */
- public Set<Object> loadAllKeys(Set<Object> keysToExclude) throws CacheLoaderException
- {
- // This cacheStore only accepts data
- return null;
- }
-
-}
\ No newline at end of file
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/ISPNIndexChangesFilter.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/ISPNIndexChangesFilter.java 2011-02-28 07:46:58 UTC (rev 4022)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/ISPNIndexChangesFilter.java 2011-02-28 09:25:46 UTC (rev 4023)
@@ -59,6 +59,8 @@
*/
private final Log log = ExoLogger.getLogger("exo.jcr.component.core.ISPNIndexChangesFilter");
+ public static final String PARAM_INFINISPAN_CACHESTORE_CLASS = "infinispan-cachestore-classname";
+
/**
* ISPN cache.
*/
@@ -82,6 +84,7 @@
this.wsId = searchManager.getWsId().hashCode();
ISPNCacheFactory<Serializable, Object> factory = new ISPNCacheFactory<Serializable, Object>(cfm);
+ config.putParameterValue(PARAM_INFINISPAN_CACHESTORE_CLASS, IndexerCacheStore.class.getName());
this.cache = factory.createCache("Indexer-" + searchManager.getWsId(), config);
CacheLoaderManager cacheLoaderManager =
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/IndexerCacheStore.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/IndexerCacheStore.java 2011-02-28 07:46:58 UTC (rev 4022)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/IndexerCacheStore.java 2011-02-28 09:25:46 UTC (rev 4023)
@@ -18,16 +18,10 @@
*/
package org.exoplatform.services.jcr.impl.core.query.ispn;
-import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
-import org.exoplatform.services.jcr.impl.core.query.Indexer;
import org.exoplatform.services.jcr.impl.core.query.IndexerIoMode;
import org.exoplatform.services.jcr.impl.core.query.IndexerIoModeHandler;
-import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
-import org.exoplatform.services.jcr.impl.core.query.SearchManager;
import org.exoplatform.services.jcr.impl.core.query.jbosscache.ChangesFilterListsWrapper;
import org.exoplatform.services.jcr.util.IdGenerator;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
import org.infinispan.Cache;
import org.infinispan.container.DataContainer;
import org.infinispan.container.entries.InternalCacheEntry;
@@ -52,12 +46,16 @@
import java.util.Map.Entry;
/**
+ * Implements Cache Store for clustered environment. It gives control of Index for coordinator and
+ * adds failover mechanisms when it changes.
+ *
* @author <a href="mailto:nikolazius@gmail.com">Nikolay Zamosenchuk</a>
* @version $Id: IndexCacheLoader.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
*
*/
-public class IndexerCacheStore extends AbstractInputCacheStore
+public class IndexerCacheStore extends AbstractIndexerCacheStore
{
+ protected volatile IndexerIoModeHandler modeHandler;
protected CacheListener listener;
@@ -73,37 +71,8 @@
*/
private volatile boolean coordinator;
- EmbeddedCacheManager cacheManager;
+ protected EmbeddedCacheManager cacheManager;
- protected volatile IndexerIoModeHandler modeHandler;
-
- /**
- * A map of all the indexers that has been registered
- */
- private final Map<Integer, Indexer> indexers = new HashMap<Integer, Indexer>();
-
- private static final Log log = ExoLogger.getLogger("exo.jcr.component.core.IndexerCacheLoader");
-
- /**
- * This method will register a new Indexer according to the given parameters.
- *
- * @param searchManager
- * @param parentSearchManager
- * @param handler
- * @param parentHandler
- * @throws RepositoryConfigurationException
- */
- public void register(SearchManager searchManager, SearchManager parentSearchManager, QueryHandler handler,
- QueryHandler parentHandler) throws RepositoryConfigurationException
- {
- indexers.put(searchManager.getWsId().hashCode(), new Indexer(searchManager, parentSearchManager, handler,
- parentHandler));
- if (log.isDebugEnabled())
- {
- log.debug("Register " + searchManager.getWsId() + " " + this + " in " + indexers);
- }
- }
-
@Override
public void init(CacheLoaderConfig config, Cache<?, ?> cache, StreamingMarshaller m) throws CacheLoaderException
{
@@ -114,56 +83,10 @@
}
/**
- * @see org.infinispan.loaders.CacheStore#store(org.infinispan.container.entries.InternalCacheEntry)
- */
- public void store(InternalCacheEntry entry) throws CacheLoaderException
- {
- if (entry.getValue() instanceof ChangesFilterListsWrapper && entry.getKey() instanceof ChangesKey)
- {
- if (log.isDebugEnabled())
- {
- log.info("Received list wrapper, start indexing...");
- }
- // updating index
- ChangesFilterListsWrapper wrapper = (ChangesFilterListsWrapper)entry.getValue();
- ChangesKey key = (ChangesKey)entry.getKey();
- try
- {
- Indexer indexer = indexers.get(key.getWsId());
- if (indexer == null)
- {
- log.warn("No indexer could be found for the cache entry " + key.toString());
- if (log.isDebugEnabled())
- {
- log.debug("The current content of the map of indexers is " + indexers);
- }
- }
- else if (wrapper.withChanges())
- {
- indexer.updateIndex(wrapper.getChanges(), wrapper.getParentChanges());
- }
- else
- {
- indexer.updateIndex(wrapper.getAddedNodes(), wrapper.getRemovedNodes(), wrapper.getParentAddedNodes(),
- wrapper.getParentRemovedNodes());
- }
- }
- finally
- {
- if (modeHandler.getMode() == IndexerIoMode.READ_WRITE)
- {
- // remove the data from the cache
- cache.remove(key);
- }
- }
- }
- }
-
- /**
* Set the mode handler
* @param modeHandler
*/
- IndexerIoModeHandler getModeHandler()
+ public IndexerIoModeHandler getModeHandler()
{
if (modeHandler == null)
{
@@ -232,6 +155,9 @@
}
}
+ /**
+ * Flushes all cache content to underlying CacheStore
+ */
protected void doPushState()
{
final boolean debugEnabled = log.isDebugEnabled();
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/LocalIndexCacheStore.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/LocalIndexCacheStore.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/LocalIndexCacheStore.java 2011-02-28 09:25:46 UTC (rev 4023)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2011 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.core.query.ispn;
+
+import org.exoplatform.services.jcr.impl.core.query.IndexerIoMode;
+import org.exoplatform.services.jcr.impl.core.query.IndexerIoModeHandler;
+
+/**
+ * Implements Cache Store that designed to be used when each cluster node has it's own local index
+ *
+ * @author <a href="mailto:nikolazius@gmail.com">Nikolay Zamosenchuk</a>
+ * @version $Id: LocalIndexerCacheStore.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
+ *
+ */
+public class LocalIndexCacheStore extends AbstractIndexerCacheStore
+{
+
+ protected volatile IndexerIoModeHandler modeHandler;
+
+ public LocalIndexCacheStore()
+ {
+ super();
+ this.modeHandler = new IndexerIoModeHandler(IndexerIoMode.READ_WRITE); // initialize mode handler
+ }
+
+ @Override
+ public IndexerIoModeHandler getModeHandler()
+ {
+ return modeHandler;
+ }
+
+}
Property changes on: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/LocalIndexCacheStore.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/LocalIndexChangesFilter.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/LocalIndexChangesFilter.java 2011-02-28 07:46:58 UTC (rev 4022)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/LocalIndexChangesFilter.java 2011-02-28 09:25:46 UTC (rev 4023)
@@ -62,6 +62,8 @@
*/
private final Log log = ExoLogger.getLogger("exo.jcr.component.core.LocalIndexChangesFilter");
+ public static final String PARAM_INFINISPAN_CACHESTORE_CLASS = "infinispan-cachestore-classname";
+
private final Cache<Serializable, Object> cache;
private final int wsId;
@@ -77,13 +79,13 @@
super(searchManager, parentSearchManager, config, indexingTree, parentIndexingTree, handler, parentHandler, cfm);
this.wsId = searchManager.getWsId().hashCode();
-
ISPNCacheFactory<Serializable, Object> factory = new ISPNCacheFactory<Serializable, Object>(cfm);
+ config.putParameterValue(PARAM_INFINISPAN_CACHESTORE_CLASS, LocalIndexCacheStore.class.getName());
this.cache = factory.createCache("Indexer-" + searchManager.getWsId(), config);
CacheLoaderManager cacheLoaderManager =
cache.getAdvancedCache().getComponentRegistry().getComponent(CacheLoaderManager.class);
- IndexerCacheStore cacheStore = (IndexerCacheStore)cacheLoaderManager.getCacheLoader();
+ AbstractIndexerCacheStore cacheStore = (AbstractIndexerCacheStore)cacheLoaderManager.getCacheLoader();
cacheStore.register(searchManager, parentSearchManager, handler, parentHandler);
IndexerIoModeHandler modeHandler = cacheStore.getModeHandler();
Modified: jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-infinispan-indexer.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-infinispan-indexer.xml 2011-02-28 07:46:58 UTC (rev 4022)
+++ jcr/trunk/exo.jcr.component.core/src/test/resources/conf/standalone/cluster/test-infinispan-indexer.xml 2011-02-28 09:25:46 UTC (rev 4023)
@@ -52,7 +52,7 @@
<deadlockDetection enabled="true" spinDuration="100"/>
<loaders passivation="false" shared="false" preload="false">
- <loader class="org.exoplatform.services.jcr.impl.core.query.ispn.IndexerCacheStore" fetchPersistentState="false" ignoreModifications="false" purgeOnStartup="false">
+ <loader class="${infinispan-cachestore-classname}" fetchPersistentState="false" ignoreModifications="false" purgeOnStartup="false">
<async enabled="false"/>
</loader>
</loaders>
13 years, 1 month
exo-jcr SVN: r4022 - jcr/trunk/exo.jcr.component.core/src/main/resources/conf/portal/cluster.
by do-not-reply@jboss.org
Author: tolusha
Date: 2011-02-28 02:46:58 -0500 (Mon, 28 Feb 2011)
New Revision: 4022
Added:
jcr/trunk/exo.jcr.component.core/src/main/resources/conf/portal/cluster/infinispan-data.xml
jcr/trunk/exo.jcr.component.core/src/main/resources/conf/portal/cluster/infinispan-indexer.xml
jcr/trunk/exo.jcr.component.core/src/main/resources/conf/portal/cluster/infinispan-lock.xml
Log:
EXOJCR-832: add cluster configuration
Added: jcr/trunk/exo.jcr.component.core/src/main/resources/conf/portal/cluster/infinispan-data.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/resources/conf/portal/cluster/infinispan-data.xml (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/resources/conf/portal/cluster/infinispan-data.xml 2011-02-28 07:46:58 UTC (rev 4022)
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2009 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.
+
+-->
+<infinispan
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:infinispan:config:4.0 http://www.infinispan.org/schemas/infinispan-config-4.0.xsd"
+ xmlns="urn:infinispan:config:4.0">
+
+ <global>
+ <evictionScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory">
+ <properties>
+ <property name="threadNamePrefix" value="EvictionThread"/>
+ </properties>
+ </evictionScheduledExecutor>
+
+ <globalJmxStatistics jmxDomain="infinispan" enabled="true" allowDuplicateDomains="true"/>
+
+ <transport transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport" clusterName="${infinispan-cluster-name}" distributedSyncTimeout="20000">
+ <properties>
+ <property name="configurationFile" value="${jgroups-configuration}"/>
+ </properties>
+ </transport>
+ </global>
+
+ <default>
+ <clustering mode="replication">
+ <stateRetrieval timeout="20000" fetchInMemoryState="false" />
+ <sync />
+ </clustering>
+
+ <locking isolationLevel="READ_COMMITTED" lockAcquisitionTimeout="20000" writeSkewCheck="false" concurrencyLevel="500"/>
+ <transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.JBossStandaloneJTAManagerLookup" syncRollbackPhase="false" syncCommitPhase="false"/>
+ <jmxStatistics enabled="true"/>
+ <deadlockDetection enabled="true" spinDuration="100"/>
+ <eviction strategy="LRU" wakeUpInterval="5000" threadPolicy="DEFAULT" maxEntries="1000000"/>
+ </default>
+</infinispan>
Added: jcr/trunk/exo.jcr.component.core/src/main/resources/conf/portal/cluster/infinispan-indexer.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/resources/conf/portal/cluster/infinispan-indexer.xml (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/resources/conf/portal/cluster/infinispan-indexer.xml 2011-02-28 07:46:58 UTC (rev 4022)
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2009 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.
+
+-->
+<infinispan
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:infinispan:config:4.0 http://www.infinispan.org/schemas/infinispan-config-4.0.xsd"
+ xmlns="urn:infinispan:config:4.0">
+
+ <global>
+ <evictionScheduledExecutor factory="org.infinispan.executors.DefaultScheduledExecutorFactory">
+ <properties>
+ <property name="threadNamePrefix" value="EvictionThread"/>
+ </properties>
+ </evictionScheduledExecutor>
+
+ <globalJmxStatistics jmxDomain="infinispan" enabled="true" allowDuplicateDomains="true"/>
+
+ <transport transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport" clusterName="${infinispan-cluster-name}" distributedSyncTimeout="20000">
+ <properties>
+ <property name="configurationFile" value="${jgroups-configuration}"/>
+ </properties>
+ </transport>
+ </global>
+
+ <default>
+ <clustering mode="replication">
+ <stateRetrieval timeout="20000" fetchInMemoryState="false" />
+ <sync />
+ </clustering>
+
+ <locking isolationLevel="READ_COMMITTED" lockAcquisitionTimeout="20000" writeSkewCheck="false" concurrencyLevel="500"/>
+ <transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.JBossStandaloneJTAManagerLookup" syncRollbackPhase="false" syncCommitPhase="false"/>
+ <jmxStatistics enabled="true"/>
+ <deadlockDetection enabled="true" spinDuration="100"/>
+
+ <loaders passivation="false" shared="false" preload="false">
+ <loader class="org.exoplatform.services.jcr.impl.core.query.ispn.IndexerCacheStore" fetchPersistentState="false" ignoreModifications="false" purgeOnStartup="false">
+ <async enabled="false"/>
+ </loader>
+ </loaders>
+ </default>
+</infinispan>
Added: jcr/trunk/exo.jcr.component.core/src/main/resources/conf/portal/cluster/infinispan-lock.xml
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/resources/conf/portal/cluster/infinispan-lock.xml (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/resources/conf/portal/cluster/infinispan-lock.xml 2011-02-28 07:46:58 UTC (rev 4022)
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2009 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.
+
+-->
+<infinispan
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:infinispan:config:4.0 http://www.infinispan.org/schemas/infinispan-config-4.0.xsd"
+ xmlns="urn:infinispan:config:4.0">
+
+ <global>
+ <globalJmxStatistics jmxDomain="infinispan" enabled="true" allowDuplicateDomains="true"/>
+
+ <transport transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport" clusterName="${infinispan-cluster-name}" distributedSyncTimeout="20000">
+ <properties>
+ <property name="configurationFile" value="${jgroups-configuration}"/>
+ </properties>
+ </transport>
+ </global>
+
+ <default>
+ <clustering mode="replication">
+ <stateRetrieval timeout="20000" fetchInMemoryState="false" />
+ <sync />
+ </clustering>
+
+ <locking isolationLevel="READ_COMMITTED" lockAcquisitionTimeout="20000" writeSkewCheck="false" concurrencyLevel="500"/>
+ <transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.JBossStandaloneJTAManagerLookup" syncRollbackPhase="false" syncCommitPhase="false"/>
+ <jmxStatistics enabled="true"/>
+ <deadlockDetection enabled="true" spinDuration="100"/>
+
+ <loaders passivation="false" shared="true" preload="true">
+ <loader class="org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStore" fetchPersistentState="false" ignoreModifications="false" purgeOnStartup="false">
+ <properties>
+ <property name="stringsTableNamePrefix" value="${infinispan-cl-cache.jdbc.table.name}"/>
+ <property name="idColumnName" value="${infinispan-cl-cache.jdbc.id.column}"/>
+ <property name="dataColumnName" value="${infinispan-cl-cache.jdbc.data.column}"/>
+ <property name="timestampColumnName" value="${infinispan-cl-cache.jdbc.timestamp.column}"/>
+ <property name="idColumnType" value="${infinispan-cl-cache.jdbc.id.type}"/>
+ <property name="dataColumnType" value="${infinispan-cl-cache.jdbc.data.type}"/>
+ <property name="timestampColumnType" value="${infinispan-cl-cache.jdbc.timestamp.type}"/>
+ <property name="dropTableOnExit" value="${infinispan-cl-cache.jdbc.table.drop}"/>
+ <property name="createTableOnStart" value="${infinispan-cl-cache.jdbc.table.create}"/>
+ <property name="connectionFactoryClass" value="${infinispan-cl-cache.jdbc.connectionFactory}"/>
+ <property name="datasourceJndiLocation" value="${infinispan-cl-cache.jdbc.datasource}"/>
+ </properties>
+ <async enabled="false"/>
+ </loader>
+ </loaders>
+ </default>
+
+</infinispan>
13 years, 1 month
exo-jcr SVN: r4021 - jcr/trunk/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp and 3 other directories.
by do-not-reply@jboss.org
Author: nfilotto
Date: 2011-02-25 15:24:27 -0500 (Fri, 25 Feb 2011)
New Revision: 4021
Added:
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/LifecycleVisitor.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/proccess/WorkerService.java
jcr/trunk/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/FtpServerImpl.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ConcurrentPicoContainer.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/web/PortalContainerCreator.java
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/TestExoContainer.java
Log:
EXOJCR-1213: Thanks to this patch if an error occurs in the stop or dispose methods, the error will be logged with the debug level, such that we are sure that the stop and dispose methods will be called on all components. This patch also stops the RootContainer on context destroy of the starter.war, it is necessary since the shutdown hooks are not triggered on tomcat stop command. And finally this patch convert the FtpServer and the WorkerService into daemon to avoid blocking the JVM to stop normally.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/proccess/WorkerService.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/proccess/WorkerService.java 2011-02-25 14:56:08 UTC (rev 4020)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/proccess/WorkerService.java 2011-02-25 20:24:27 UTC (rev 4021)
@@ -79,7 +79,7 @@
*/
public WorkerService(int threadCount)
{
- executor = new ScheduledThreadPoolExecutor(threadCount);
+ this(threadCount, "pool");
}
/**
@@ -90,7 +90,7 @@
*/
public WorkerService(int threadCount, String threadNamePrefix)
{
- executor = new ScheduledThreadPoolExecutor(threadCount, new WorkerThreadFactory(threadNamePrefix));
+ this(threadCount, threadNamePrefix, true);
}
/**
Modified: jcr/trunk/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/FtpServerImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/FtpServerImpl.java 2011-02-25 14:56:08 UTC (rev 4020)
+++ jcr/trunk/exo.jcr.component.ftp/src/main/java/org/exoplatform/services/ftp/FtpServerImpl.java 2011-02-25 20:24:27 UTC (rev 4021)
@@ -219,6 +219,7 @@
{
this.ftpServer = ftpServer;
this.serverSocket = serverSocket;
+ setDaemon(true);
}
public void disable()
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ConcurrentPicoContainer.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ConcurrentPicoContainer.java 2011-02-25 14:56:08 UTC (rev 4020)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ConcurrentPicoContainer.java 2011-02-25 20:24:27 UTC (rev 4021)
@@ -35,7 +35,6 @@
import org.picocontainer.defaults.DefaultPicoContainer;
import org.picocontainer.defaults.DuplicateComponentKeyRegistrationException;
import org.picocontainer.defaults.InstanceComponentAdapter;
-import org.picocontainer.defaults.LifecycleVisitor;
import org.picocontainer.defaults.VerifyingVisitor;
import java.io.Serializable;
@@ -460,6 +459,30 @@
}
/**
+ * Indicates whether or not the container can be started
+ */
+ protected boolean canBeStarted()
+ {
+ return !disposed.get() && !started.get();
+ }
+
+ /**
+ * Indicates whether or not the container can be stopped
+ */
+ protected boolean canBeStopped()
+ {
+ return !disposed.get() && started.get();
+ }
+
+ /**
+ * Indicates whether or not the container can be disposed
+ */
+ protected boolean canBeDisposed()
+ {
+ return !disposed.get();
+ }
+
+ /**
* Start the components of this PicoContainer and all its logical child containers.
* Any component implementing the lifecycle interface {@link org.picocontainer.Startable} will be started.
* @see #makeChildContainer()
@@ -468,7 +491,7 @@
*/
public void start()
{
- if (disposed.get() || started.get())
+ if (!canBeStarted())
return;
LifecycleVisitor.start(this);
started.set(true);
@@ -483,7 +506,7 @@
*/
public void stop()
{
- if (disposed.get() || !started.get())
+ if (!canBeStopped())
return;
LifecycleVisitor.stop(this);
started.set(false);
@@ -498,7 +521,7 @@
*/
public void dispose()
{
- if (disposed.get())
+ if (!canBeDisposed())
return;
LifecycleVisitor.dispose(this);
disposed.set(true);
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java 2011-02-25 14:56:08 UTC (rev 4020)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java 2011-02-25 20:24:27 UTC (rev 4021)
@@ -188,21 +188,24 @@
}
@Override
- public void dispose()
+ public synchronized void dispose()
{
SecurityManager security = System.getSecurityManager();
if (security != null)
security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
- destroyContainerInternal();
- super.dispose();
+ if (canBeDisposed())
+ {
+ destroyContainerInternal();
+ super.dispose();
+ }
}
/**
* Starts the container
* @param init indicates if the container must be initialized first
*/
- public void start(boolean init)
+ public synchronized void start(boolean init)
{
SecurityManager security = System.getSecurityManager();
if (security != null)
@@ -217,24 +220,31 @@
}
@Override
- public void start()
+ public synchronized void start()
{
SecurityManager security = System.getSecurityManager();
if (security != null)
security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
- super.start();
- startContainerInternal();
+
+ if (canBeStarted())
+ {
+ super.start();
+ startContainerInternal();
+ }
}
@Override
- public void stop()
+ public synchronized void stop()
{
SecurityManager security = System.getSecurityManager();
if (security != null)
security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
- stopContainerInternal();
- super.stop();
+ if (canBeStopped())
+ {
+ stopContainerInternal();
+ super.stop();
+ }
}
/**
Added: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/LifecycleVisitor.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/LifecycleVisitor.java (rev 0)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/LifecycleVisitor.java 2011-02-25 20:24:27 UTC (rev 4021)
@@ -0,0 +1,191 @@
+/*
+ * Copyright (C) 2011 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.container;
+
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.picocontainer.ComponentAdapter;
+import org.picocontainer.Disposable;
+import org.picocontainer.Parameter;
+import org.picocontainer.PicoContainer;
+import org.picocontainer.PicoIntrospectionException;
+import org.picocontainer.Startable;
+import org.picocontainer.defaults.AbstractPicoVisitor;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ */
+public class LifecycleVisitor extends AbstractPicoVisitor
+{
+
+ private static final Log LOG = ExoLogger.getLogger("exo.kernel.container.LifecycleVisitor");
+
+ private static final Method START;
+
+ private static final Method STOP;
+
+ private static final Method DISPOSE;
+ static
+ {
+ try
+ {
+ START = Startable.class.getMethod("start", (Class<?>[])null);
+ STOP = Startable.class.getMethod("stop", (Class<?>[])null);
+ DISPOSE = Disposable.class.getMethod("dispose", (Class<?>[])null);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new InternalError(e.getMessage());
+ }
+ }
+
+ private final Method method;
+
+ private final Class<?> type;
+
+ private final boolean visitInInstantiationOrder;
+
+ private final List componentInstances;
+
+ private final boolean ignoreError;
+
+ public LifecycleVisitor(Method method, Class<?> ofType, boolean visitInInstantiationOrder, boolean ignoreError)
+ {
+ this.method = method;
+ this.type = ofType;
+ this.visitInInstantiationOrder = visitInInstantiationOrder;
+ this.componentInstances = new ArrayList();
+ this.ignoreError = ignoreError;
+ }
+
+ public Object traverse(Object node)
+ {
+ componentInstances.clear();
+ try
+ {
+ super.traverse(node);
+ if (!visitInInstantiationOrder)
+ {
+ Collections.reverse(componentInstances);
+ }
+ for (Iterator iterator = componentInstances.iterator(); iterator.hasNext();)
+ {
+ Object o = iterator.next();
+ try
+ {
+ method.invoke(o, (Object[])null);
+ }
+ catch (IllegalArgumentException e)
+ {
+ if (ignoreError)
+ {
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Can't call " + method.getName() + " on " + o, e);
+ }
+ continue;
+ }
+ throw new PicoIntrospectionException("Can't call " + method.getName() + " on " + o, e);
+ }
+ catch (IllegalAccessException e)
+ {
+ if (ignoreError)
+ {
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Can't call " + method.getName() + " on " + o, e);
+ }
+ continue;
+ }
+ throw new PicoIntrospectionException("Can't call " + method.getName() + " on " + o, e);
+ }
+ catch (InvocationTargetException e)
+ {
+ if (ignoreError)
+ {
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Failed when calling " + method.getName() + " on " + o, e.getTargetException());
+ }
+ continue;
+ }
+ throw new PicoIntrospectionException("Failed when calling " + method.getName() + " on " + o,
+ e.getTargetException());
+ }
+ }
+ }
+ finally
+ {
+ componentInstances.clear();
+ }
+ return Void.TYPE;
+ }
+
+ public void visitContainer(PicoContainer pico)
+ {
+ checkTraversal();
+ componentInstances.addAll(pico.getComponentInstancesOfType(type));
+ }
+
+ public void visitComponentAdapter(ComponentAdapter componentAdapter)
+ {
+ checkTraversal();
+ }
+
+ public void visitParameter(Parameter parameter)
+ {
+ checkTraversal();
+ }
+
+ /**
+ * Invoke the standard PicoContainer lifecycle for {@link Startable#start()}.
+ * @param node The node to start the traversal.
+ */
+ public static void start(Object node)
+ {
+ new LifecycleVisitor(START, Startable.class, true, false).traverse(node);;
+ }
+
+ /**
+ * Invoke the standard PicoContainer lifecycle for {@link Startable#stop()}.
+ * @param node The node to start the traversal.
+ */
+ public static void stop(Object node)
+ {
+ new LifecycleVisitor(STOP, Startable.class, false, true).traverse(node);;
+ }
+
+ /**
+ * Invoke the standard PicoContainer lifecycle for {@link Disposable#dispose()}.
+ * @param node The node to start the traversal.
+ */
+ public static void dispose(Object node)
+ {
+ new LifecycleVisitor(DISPOSE, Disposable.class, false, true).traverse(node);;
+ }
+
+}
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/web/PortalContainerCreator.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/web/PortalContainerCreator.java 2011-02-25 14:56:08 UTC (rev 4020)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/web/PortalContainerCreator.java 2011-02-25 20:24:27 UTC (rev 4021)
@@ -45,6 +45,16 @@
*/
public void contextDestroyed(ServletContextEvent event)
{
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ // Ensure that the root container is stopped properly since the shutdown hook
+ // doesn't work in some cases for example with tomcat when we call the stop command
+ RootContainer.getInstance().stop();
+ return null;
+ }
+ });
}
/**
Modified: kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/TestExoContainer.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/TestExoContainer.java 2011-02-25 14:56:08 UTC (rev 4020)
+++ kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/TestExoContainer.java 2011-02-25 20:24:27 UTC (rev 4021)
@@ -22,6 +22,7 @@
import org.exoplatform.container.support.ContainerBuilder;
import org.exoplatform.container.xml.InitParams;
import org.picocontainer.ComponentAdapter;
+import org.picocontainer.Disposable;
import org.picocontainer.PicoContainer;
import org.picocontainer.PicoInitializationException;
import org.picocontainer.PicoIntrospectionException;
@@ -669,5 +670,170 @@
public void stop()
{
}
- }
+ }
+
+ public void testLifeCycle() throws Throwable
+ {
+ ConcurrentPicoContainer container = new ConcurrentPicoContainer();
+ assertTrue(container.canBeStarted());
+ assertFalse(container.canBeStopped());
+ assertTrue(container.canBeDisposed());
+ container.registerComponentImplementation(LC1.class);
+ container.registerComponentImplementation(LC2.class);
+ container.registerComponentImplementation(LC3.class);
+ container.registerComponentImplementation(LC4.class);
+ container.registerComponentImplementation(LC5.class);
+ try
+ {
+ container.start();
+ fail("Should fail due to the start method of C1");
+ }
+ catch (Exception e)
+ {
+ // igonre me
+ }
+ LC1 c1 = (LC1)container.getComponentInstanceOfType(LC1.class);
+ LC2 c2 = (LC2)container.getComponentInstanceOfType(LC2.class);
+ LC3 c3 = (LC3)container.getComponentInstanceOfType(LC3.class);
+ LC4 c4 = (LC4)container.getComponentInstanceOfType(LC4.class);
+ LC5 c5 = (LC5)container.getComponentInstanceOfType(LC5.class);
+ assertFalse(c2.started && c3.started && c4.started);
+ assertTrue(container.canBeStarted());
+ assertFalse(container.canBeStopped());
+ assertTrue(container.canBeDisposed());
+ container.stop();
+ assertTrue(container.canBeStarted());
+ assertFalse(container.canBeStopped());
+ assertTrue(container.canBeDisposed());
+ container.dispose();
+ assertTrue(c1.disposed && c2.disposed && c5.disposed);
+ assertFalse(container.canBeStarted());
+ assertFalse(container.canBeStopped());
+ assertFalse(container.canBeDisposed());
+ container = new ConcurrentPicoContainer();
+ assertTrue(container.canBeStarted());
+ assertFalse(container.canBeStopped());
+ assertTrue(container.canBeDisposed());
+ container.registerComponentImplementation(LC2.class);
+ container.registerComponentImplementation(LC3.class);
+ container.registerComponentImplementation(LC4.class);
+ container.registerComponentImplementation(LC5.class);
+ container.start();
+ c2 = (LC2)container.getComponentInstanceOfType(LC2.class);
+ c3 = (LC3)container.getComponentInstanceOfType(LC3.class);
+ c4 = (LC4)container.getComponentInstanceOfType(LC4.class);
+ assertTrue(c2.started && c3.started && c4.started);
+ assertFalse(container.canBeStarted());
+ assertTrue(container.canBeStopped());
+ assertTrue(container.canBeDisposed());
+ container.stop();
+ assertTrue(container.canBeStarted());
+ assertFalse(container.canBeStopped());
+ assertTrue(container.canBeDisposed());
+ container.dispose();
+ assertTrue(c1.disposed && c2.disposed && c5.disposed);
+ assertFalse(container.canBeStarted());
+ assertFalse(container.canBeStopped());
+ assertFalse(container.canBeDisposed());
+ }
+
+ public static class LC1 implements Startable, Disposable
+ {
+
+ public boolean started;
+ public boolean stopped;
+ public boolean disposed;
+
+ public void start()
+ {
+ throw new RuntimeException();
+ }
+
+ public void stop()
+ {
+ stopped = true;
+ }
+
+ public void dispose()
+ {
+ disposed = true;
+ }
+ }
+
+ public static class LC2 implements Startable, Disposable
+ {
+
+ public boolean started;
+ public boolean stopped;
+ public boolean disposed;
+
+ public void start()
+ {
+ started = true;
+ }
+
+ public void stop()
+ {
+ throw new RuntimeException();
+ }
+
+ public void dispose()
+ {
+ disposed = true;
+ }
+ }
+
+ public static class LC3 implements Startable, Disposable
+ {
+
+ public boolean started;
+ public boolean stopped;
+ public boolean disposed;
+
+ public void start()
+ {
+ started = true;
+ }
+
+ public void stop()
+ {
+ stopped = true;
+ }
+
+ public void dispose()
+ {
+ throw new RuntimeException();
+ }
+ }
+
+ public static class LC4 implements Startable
+ {
+
+ public boolean started;
+ public boolean stopped;
+ public boolean disposed;
+
+ public void start()
+ {
+ started = true;
+ }
+
+ public void stop()
+ {
+ stopped = true;
+ }
+ }
+
+ public static class LC5 implements Disposable
+ {
+
+ public boolean started;
+ public boolean stopped;
+ public boolean disposed;
+
+ public void dispose()
+ {
+ disposed = true;
+ }
+ }
}
13 years, 2 months
exo-jcr SVN: r4020 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2011-02-25 09:56:08 -0500 (Fri, 25 Feb 2011)
New Revision: 4020
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/IndexerCacheStore.java
Log:
EXOJCR-832 : Adding PushState code block
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/IndexerCacheStore.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/IndexerCacheStore.java 2011-02-25 14:23:26 UTC (rev 4019)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/IndexerCacheStore.java 2011-02-25 14:56:08 UTC (rev 4020)
@@ -25,9 +25,11 @@
import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
import org.exoplatform.services.jcr.impl.core.query.SearchManager;
import org.exoplatform.services.jcr.impl.core.query.jbosscache.ChangesFilterListsWrapper;
+import org.exoplatform.services.jcr.util.IdGenerator;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.infinispan.Cache;
+import org.infinispan.container.DataContainer;
import org.infinispan.container.entries.InternalCacheEntry;
import org.infinispan.lifecycle.ComponentStatus;
import org.infinispan.loaders.CacheLoaderConfig;
@@ -41,9 +43,13 @@
import org.infinispan.notifications.cachemanagerlistener.event.ViewChangedEvent;
import org.infinispan.remoting.transport.Address;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
/**
* @author <a href="mailto:nikolazius@gmail.com">Nikolay Zamosenchuk</a>
@@ -228,72 +234,72 @@
protected void doPushState()
{
- // final boolean debugEnabled = log.isDebugEnabled();
- //
- // if (debugEnabled)
- // {
- // log.debug("start pushing in-memory state to cache cacheLoader collection");
- // }
- //
- // // merging all lists stored in memory
- // Collection<NodeSPI> children = cache.getRoot().getChildren();
- // for (NodeSPI wsChildren : children)
- // {
- // final Set<String> removedNodes = new HashSet<String>();
- // final Set<String> addedNodes = new HashSet<String>();
- // final Set<String> parentRemovedNodes = new HashSet<String>();
- // final Set<String> parentAddedNodes = new HashSet<String>();
- // Collection<NodeSPI> changes = wsChildren.getChildren();
- // for (NodeSPI aChildren : changes)
- // {
- // Fqn<?> fqn = aChildren.getFqn();
- // Object value = cache.get(fqn, JBossCacheIndexChangesFilter.LISTWRAPPER);
- // if (value instanceof ChangesFilterListsWrapper)
- // {
- // // get wrapper object
- // ChangesFilterListsWrapper listsWrapper = (ChangesFilterListsWrapper)value;
- // if (listsWrapper.withChanges())
- // {
- // if (listsWrapper.getChanges() != null)
- // {
- // // get search manager lists
- // addedNodes.addAll(listsWrapper.getChanges().getAddIds());
- // removedNodes.addAll(listsWrapper.getChanges().getRemove());
- // }
- // if (listsWrapper.getParentChanges() != null)
- // {
- // // parent search manager lists
- // parentAddedNodes.addAll(listsWrapper.getParentChanges().getAddIds());
- // parentRemovedNodes.addAll(listsWrapper.getParentChanges().getRemove());
- // }
- // }
- // else
- // {
- // // get search manager lists
- // addedNodes.addAll(listsWrapper.getAddedNodes());
- // removedNodes.addAll(listsWrapper.getRemovedNodes());
- // // parent search manager lists
- // parentAddedNodes.addAll(listsWrapper.getParentAddedNodes());
- // parentRemovedNodes.addAll(listsWrapper.getParentAddedNodes());
- // }
- // }
- // }
- // String id = IdGenerator.generate();
- // cache.put(Fqn.fromRelativeElements(wsChildren.getFqn(), id), JBossCacheIndexChangesFilter.LISTWRAPPER,
- // new ChangesFilterListsWrapper(addedNodes, removedNodes, parentAddedNodes, parentRemovedNodes));
- // // Once we put the merged changes into the cache we can remove other changes from the cache
- // for (NodeSPI aChildren : children)
- // {
- // // Remove the node from the cache and do it asynchronously
- // cache.getInvocationContext().getOptionOverrides().setForceAsynchronous(true);
- // cache.removeNode(aChildren.getFqn());
- // }
- // }
- // if (debugEnabled)
- // {
- // log.debug("in-memory state passed to cache cacheLoader successfully");
- // }
- // return null;
+ final boolean debugEnabled = log.isDebugEnabled();
+
+ if (debugEnabled)
+ {
+ log.debug("start pushing in-memory state to cache cacheLoader collection");
+ }
+
+ Map<Integer, ChangesFilterListsWrapper> changesMap = new HashMap<Integer, ChangesFilterListsWrapper>();
+ List<ChangesKey> processedItemKeys = new ArrayList<ChangesKey>();
+
+ DataContainer dc = cache.getAdvancedCache().getDataContainer();
+ Set keys = dc.keySet();
+ InternalCacheEntry entry;
+ // collect all cache entries into the following map:
+ // <WS ID> : <Concated lists of added/removed nodes>
+ for (Object k : keys)
+ {
+ if ((entry = dc.get(k)) != null)
+ {
+ if (entry.getValue() instanceof ChangesFilterListsWrapper && entry.getKey() instanceof ChangesKey)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.info("Received list wrapper, start indexing...");
+ }
+ // get stale List that was not processed
+ ChangesFilterListsWrapper staleListIncache = (ChangesFilterListsWrapper)entry.getValue();
+ ChangesKey key = (ChangesKey)entry.getKey();
+ // get newly created wrapper instance
+ ChangesFilterListsWrapper listToPush = changesMap.get(key.getWsId());
+ if (listToPush == null)
+ {
+ listToPush =
+ new ChangesFilterListsWrapper(new HashSet<String>(), new HashSet<String>(), new HashSet<String>(),
+ new HashSet<String>());
+ changesMap.put(key.getWsId(), listToPush);
+ }
+ // copying lists into the new wrapper
+ listToPush.getParentAddedNodes().addAll(staleListIncache.getParentAddedNodes());
+ listToPush.getParentRemovedNodes().addAll(staleListIncache.getParentRemovedNodes());
+
+ listToPush.getAddedNodes().addAll(staleListIncache.getAddedNodes());
+ listToPush.getRemovedNodes().addAll(staleListIncache.getRemovedNodes());
+ processedItemKeys.add(key);
+ }
+ }
+
+ }
+
+ // process all lists for each workspace
+ for (Entry<Integer, ChangesFilterListsWrapper> changesEntry : changesMap.entrySet())
+ {
+ // create key based on wsId and generated id
+ ChangesKey changesKey = new ChangesKey(changesEntry.getKey(), IdGenerator.generate());
+ cache.putAsync(changesKey, changesEntry.getValue());
+ }
+
+ for (ChangesKey key : processedItemKeys)
+ {
+ cache.removeAsync(key);
+ }
+
+ if (debugEnabled)
+ {
+ log.debug("in-memory state passed to cache cacheStore successfully");
+ }
}
@Listener
13 years, 2 months
exo-jcr SVN: r4019 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core and 10 other directories.
by do-not-reply@jboss.org
Author: nfilotto
Date: 2011-02-25 09:23:26 -0500 (Fri, 25 Feb 2011)
New Revision: 4019
Added:
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/security/
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/security/ContainerPermissions.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryServiceImpl.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/ExoRepositoryStub.java
kernel/trunk/exo.kernel.component.common/src/test/resources/test.policy
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ConcurrentPicoContainer.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainerContext.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/PortalContainer.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/SessionContainer.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/SessionManagerImpl.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/StandaloneContainer.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManageableContainer.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/web/PortalContainerCreator.java
kernel/trunk/exo.kernel.container/src/test/resources/test.policy
ws/trunk/exo.ws.rest.core/src/test/resources/test.policy
ws/trunk/exo.ws.rest.ext/src/test/resources/test.policy
Log:
EXOJCR-1199: The operations on containers have been protected by a RuntimePermission called manageContainer and adding/removing a component from a container has been protected by a RuntimePermission called manageComponent
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java 2011-02-25 12:07:35 UTC (rev 4018)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java 2011-02-25 14:23:26 UTC (rev 4019)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.jcr.impl;
+import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.container.ExoContainer;
import org.exoplatform.container.component.ComponentPlugin;
import org.exoplatform.container.jmx.MX4JComponentAdapterFactory;
@@ -32,6 +33,7 @@
import org.exoplatform.services.jcr.config.WorkspaceEntry;
import org.exoplatform.services.jcr.core.nodetype.ExtendedNodeTypeManager;
import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
+import org.exoplatform.services.jcr.core.security.JCRRuntimePermissions;
import org.exoplatform.services.jcr.impl.core.AddNamespacePluginHolder;
import org.exoplatform.services.jcr.impl.core.LocationFactory;
import org.exoplatform.services.jcr.impl.core.NamespaceDataPersister;
@@ -65,6 +67,7 @@
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import java.security.PrivilegedAction;
import java.util.List;
import javax.jcr.NamespaceRegistry;
@@ -124,7 +127,7 @@
* @throws RepositoryConfigurationException
* configuration error
*/
- public RepositoryContainer(ExoContainer parent, RepositoryEntry config, List<ComponentPlugin> addNamespacePlugins)
+ public RepositoryContainer(final ExoContainer parent, RepositoryEntry config, List<ComponentPlugin> addNamespacePlugins)
throws RepositoryException, RepositoryConfigurationException
{
@@ -137,8 +140,15 @@
this.config = config;
this.addNamespacePlugins = addNamespacePlugins;
this.name = parent.getContext().getName() + "-" + config.getName();
-
- parent.registerComponentInstance(name, this);
+
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ parent.registerComponentInstance(name, this);
+ return null;
+ }
+ });
registerComponents();
}
@@ -154,7 +164,7 @@
* @throws RepositoryConfigurationException
* configuration error
*/
- public RepositoryContainer(ExoContainer parent, RepositoryEntry config) throws RepositoryException,
+ public RepositoryContainer(final ExoContainer parent, RepositoryEntry config) throws RepositoryException,
RepositoryConfigurationException
{
@@ -166,8 +176,15 @@
this.config = config;
this.name = parent.getContext().getName() + "-" + config.getName();
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ parent.registerComponentInstance(name, this);
+ return null;
+ }
+ });
- parent.registerComponentInstance(name, this);
registerComponents();
}
@@ -239,6 +256,12 @@
public void registerWorkspace(final WorkspaceEntry wsConfig) throws RepositoryException,
RepositoryConfigurationException
{
+ // Need privileges to manage repository.
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ {
+ security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
+ }
try
{
@@ -247,61 +270,86 @@
if (getWorkspaceContainer(wsConfig.getName()) != null)
throw new RepositoryException("Workspace " + wsConfig.getName() + " already registered");
- WorkspaceContainer workspaceContainer = new WorkspaceContainer(this, wsConfig);
+ final WorkspaceContainer workspaceContainer = new WorkspaceContainer(this, wsConfig);
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ registerComponentInstance(wsConfig.getName(), workspaceContainer);
- registerComponentInstance(wsConfig.getName(), workspaceContainer);
+ wsConfig.setUniqueName(getName() + "_" + wsConfig.getName());
- wsConfig.setUniqueName(getName() + "_" + wsConfig.getName());
+ workspaceContainer.registerComponentInstance(wsConfig);
- workspaceContainer.registerComponentInstance(wsConfig);
-
- workspaceContainer.registerComponentImplementation(StandaloneStoragePluginProvider.class);
-
+ workspaceContainer.registerComponentImplementation(StandaloneStoragePluginProvider.class);
+ return null;
+ }
+ });
try
{
- Class<?> containerType = Class.forName(wsConfig.getContainer().getType());
- workspaceContainer.registerComponentImplementation(containerType);
- if (isSystem)
+ final Class<?> containerType = Class.forName(wsConfig.getContainer().getType());
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
{
- registerComponentInstance(new SystemDataContainerHolder((WorkspaceDataContainer)workspaceContainer
- .getComponentInstanceOfType(WorkspaceDataContainer.class)));
- }
+ public Void run()
+ {
+ workspaceContainer.registerComponentImplementation(containerType);
+ if (isSystem)
+ {
+ registerComponentInstance(new SystemDataContainerHolder((WorkspaceDataContainer)workspaceContainer
+ .getComponentInstanceOfType(WorkspaceDataContainer.class)));
+ }
+ return null;
+ }
+ });
}
catch (ClassNotFoundException e)
{
throw new RepositoryConfigurationException("Class not found for workspace data container "
+ wsConfig.getUniqueName() + " : " + e);
}
-
- // cache type
- try
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
{
- String className = wsConfig.getCache().getType();
- if (className != null && className.length() > 0)
+ public Void run()
{
- workspaceContainer.registerComponentImplementation(Class.forName(className));
+ // cache type
+ try
+ {
+ String className = wsConfig.getCache().getType();
+ if (className != null && className.length() > 0)
+ {
+ workspaceContainer.registerComponentImplementation(Class.forName(className));
+ }
+ else
+ workspaceContainer.registerComponentImplementation(LinkedWorkspaceStorageCacheImpl.class);
+ }
+ catch (ClassNotFoundException e)
+ {
+ log.warn("Workspace cache class not found " + wsConfig.getCache().getType()
+ + ", will use default. Error : " + e);
+ workspaceContainer.registerComponentImplementation(LinkedWorkspaceStorageCacheImpl.class);
+ }
+
+ workspaceContainer.registerComponentImplementation(CacheableWorkspaceDataManager.class);
+ workspaceContainer.registerComponentImplementation(LocalWorkspaceDataManagerStub.class);
+ workspaceContainer.registerComponentImplementation(ObservationManagerRegistry.class);
+ return null;
}
- else
- workspaceContainer.registerComponentImplementation(LinkedWorkspaceStorageCacheImpl.class);
- }
- catch (ClassNotFoundException e)
- {
- log.warn("Workspace cache class not found " + wsConfig.getCache().getType()
- + ", will use default. Error : " + e);
- workspaceContainer.registerComponentImplementation(LinkedWorkspaceStorageCacheImpl.class);
- }
+ });
- workspaceContainer.registerComponentImplementation(CacheableWorkspaceDataManager.class);
- workspaceContainer.registerComponentImplementation(LocalWorkspaceDataManagerStub.class);
- workspaceContainer.registerComponentImplementation(ObservationManagerRegistry.class);
-
// Lock manager and Lock persister is a optional parameters
if (wsConfig.getLockManager() != null && wsConfig.getLockManager().getPersister() != null)
{
try
{
- Class<?> lockPersister = Class.forName(wsConfig.getLockManager().getPersister().getType());
- workspaceContainer.registerComponentImplementation(lockPersister);
+ final Class<?> lockPersister = Class.forName(wsConfig.getLockManager().getPersister().getType());
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ workspaceContainer.registerComponentImplementation(lockPersister);
+ return null;
+ }
+ });
}
catch (ClassNotFoundException e)
{
@@ -315,8 +363,15 @@
{
try
{
- Class<?> lockManagerType = Class.forName(wsConfig.getLockManager().getType());
- workspaceContainer.registerComponentImplementation(lockManagerType);
+ final Class<?> lockManagerType = Class.forName(wsConfig.getLockManager().getType());
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ workspaceContainer.registerComponentImplementation(lockManagerType);
+ return null;
+ }
+ });
}
catch (ClassNotFoundException e)
{
@@ -326,29 +381,49 @@
}
else
{
- workspaceContainer.registerComponentImplementation(LockManagerImpl.class);
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ workspaceContainer.registerComponentImplementation(LockManagerImpl.class);
+ return null;
+ }
+ });
}
-
- // Query handler
- if (wsConfig.getQueryHandler() != null)
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
{
- workspaceContainer.registerComponentImplementation(SearchManager.class);
- workspaceContainer.registerComponentImplementation(QueryManager.class);
- workspaceContainer.registerComponentImplementation(QueryManagerFactory.class);
- workspaceContainer.registerComponentInstance(wsConfig.getQueryHandler());
- if (isSystem)
+ public Void run()
{
- workspaceContainer.registerComponentImplementation(SystemSearchManager.class);
+ // Query handler
+ if (wsConfig.getQueryHandler() != null)
+ {
+ workspaceContainer.registerComponentImplementation(SearchManager.class);
+ workspaceContainer.registerComponentImplementation(QueryManager.class);
+ workspaceContainer.registerComponentImplementation(QueryManagerFactory.class);
+ workspaceContainer.registerComponentInstance(wsConfig.getQueryHandler());
+ if (isSystem)
+ {
+ workspaceContainer.registerComponentImplementation(SystemSearchManager.class);
+ }
+ }
+ return null;
}
- }
+ });
// access manager
if (wsConfig.getAccessManager() != null && wsConfig.getAccessManager().getType() != null)
{
try
{
- Class<?> am = Class.forName(wsConfig.getAccessManager().getType());
- workspaceContainer.registerComponentImplementation(am);
+ final Class<?> am = Class.forName(wsConfig.getAccessManager().getType());
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ workspaceContainer.registerComponentImplementation(am);
+ return null;
+ }
+ });
}
catch (ClassNotFoundException e)
{
@@ -358,7 +433,7 @@
}
// initializer
- Class<?> initilizerType;
+ final Class<?> initilizerType;
if (wsConfig.getInitializer() != null && wsConfig.getInitializer().getType() != null)
{
// use user defined
@@ -377,10 +452,16 @@
// use default
initilizerType = ScratchWorkspaceInitializer.class;
}
- workspaceContainer.registerComponentImplementation(initilizerType);
- workspaceContainer.registerComponentImplementation(SessionFactory.class);
-
- LocalWorkspaceDataManagerStub wsDataManager =
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ workspaceContainer.registerComponentImplementation(initilizerType);
+ workspaceContainer.registerComponentImplementation(SessionFactory.class);
+ return null;
+ }
+ });
+ final LocalWorkspaceDataManagerStub wsDataManager =
(LocalWorkspaceDataManagerStub)workspaceContainer
.getComponentInstanceOfType(LocalWorkspaceDataManagerStub.class);
@@ -388,7 +469,14 @@
{
// system workspace
systemDataManager = wsDataManager;
- registerComponentInstance(systemDataManager);
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ registerComponentInstance(systemDataManager);
+ return null;
+ }
+ });
}
wsDataManager.setSystemDataManager(systemDataManager);
@@ -526,52 +614,73 @@
private void registerComponents() throws RepositoryConfigurationException, RepositoryException
{
-
- registerComponentInstance(config);
- // WorkspaceFileCleanerHolder - is a common holder for all workspaces.
- // It is used to initialize FileValueStorage
- registerComponentImplementation(FileCleanerHolder.class);
- registerComponentImplementation(LockRemoverHolder.class);
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ registerComponentInstance(config);
+ // WorkspaceFileCleanerHolder - is a common holder for all workspaces.
+ // It is used to initialize FileValueStorage
+ registerComponentImplementation(FileCleanerHolder.class);
+ registerComponentImplementation(LockRemoverHolder.class);
+ return null;
+ }
+ });
registerWorkspacesComponents();
registerRepositoryComponents();
}
private void registerRepositoryComponents() throws RepositoryConfigurationException, RepositoryException
{
- registerComponentImplementation(IdGenerator.class);
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ registerComponentImplementation(IdGenerator.class);
- registerComponentImplementation(RepositoryIndexSearcherHolder.class);
+ registerComponentImplementation(RepositoryIndexSearcherHolder.class);
- registerComponentImplementation(LocationFactory.class);
- registerComponentImplementation(ValueFactoryImpl.class);
+ registerComponentImplementation(LocationFactory.class);
+ registerComponentImplementation(ValueFactoryImpl.class);
- registerComponentInstance(new AddNamespacePluginHolder(addNamespacePlugins));
+ registerComponentInstance(new AddNamespacePluginHolder(addNamespacePlugins));
- registerComponentImplementation(JCRNodeTypeDataPersister.class);
- registerComponentImplementation(NamespaceDataPersister.class);
- registerComponentImplementation(NamespaceRegistryImpl.class);
+ registerComponentImplementation(JCRNodeTypeDataPersister.class);
+ registerComponentImplementation(NamespaceDataPersister.class);
+ registerComponentImplementation(NamespaceRegistryImpl.class);
- registerComponentImplementation(NodeTypeManagerImpl.class);
- registerComponentImplementation(NodeTypeDataManagerImpl.class);
+ registerComponentImplementation(NodeTypeManagerImpl.class);
+ registerComponentImplementation(NodeTypeDataManagerImpl.class);
- registerComponentImplementation(DefaultAccessManagerImpl.class);
+ registerComponentImplementation(DefaultAccessManagerImpl.class);
- registerComponentImplementation(SessionRegistry.class);
+ registerComponentImplementation(SessionRegistry.class);
- String systemWsname = config.getSystemWorkspaceName();
- WorkspaceEntry systemWsEntry = getWorkspaceEntry(systemWsname);
+ String systemWsname = config.getSystemWorkspaceName();
+ WorkspaceEntry systemWsEntry = getWorkspaceEntry(systemWsname);
- if (systemWsEntry != null && systemWsEntry.getQueryHandler() != null)
- {
- SystemSearchManager systemSearchManager =
- (SystemSearchManager)getWorkspaceContainer(systemWsname).getComponentInstanceOfType(
- SystemSearchManager.class);
- registerComponentInstance(new SystemSearchManagerHolder(systemSearchManager));
- }
+ if (systemWsEntry != null && systemWsEntry.getQueryHandler() != null)
+ {
+ SystemSearchManager systemSearchManager =
+ (SystemSearchManager)getWorkspaceContainer(systemWsname).getComponentInstanceOfType(
+ SystemSearchManager.class);
+ registerComponentInstance(new SystemSearchManagerHolder(systemSearchManager));
+ }
+ return null;
+ }
+ });
try
{
- registerComponentImplementation(Class.forName(config.getAuthenticationPolicy()));
+ final Class<?> authenticationPolicyClass = Class.forName(config.getAuthenticationPolicy());
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ registerComponentImplementation(authenticationPolicyClass);
+ return null;
+ }
+ });
}
catch (ClassNotFoundException e)
{
@@ -579,9 +688,15 @@
}
// Repository
- RepositoryImpl repository = new RepositoryImpl(this);
- registerComponentInstance(repository);
-
+ final RepositoryImpl repository = new RepositoryImpl(this);
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ registerComponentInstance(repository);
+ return null;
+ }
+ });
}
private void registerWorkspacesComponents() throws RepositoryException, RepositoryConfigurationException
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryServiceImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryServiceImpl.java 2011-02-25 12:07:35 UTC (rev 4018)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryServiceImpl.java 2011-02-25 14:23:26 UTC (rev 4019)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.jcr.impl;
+import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.container.ExoContainer;
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.container.PortalContainer;
@@ -39,6 +40,7 @@
import org.picocontainer.Startable;
import java.io.InputStream;
+import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -144,16 +146,22 @@
throw new RepositoryConfigurationException("Repository container " + rEntry.getName() + " already started");
}
- RepositoryContainer repositoryContainer = new RepositoryContainer(parentContainer, rEntry, addNamespacesPlugins);
+ final RepositoryContainer repositoryContainer = new RepositoryContainer(parentContainer, rEntry, addNamespacesPlugins);
// Storing and starting the repository container under
// key=repository_name
try
{
repositoryContainers.put(rEntry.getName(), repositoryContainer);
- managerStartChanges.registerListeners(repositoryContainer);
-
- repositoryContainer.start();
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ managerStartChanges.registerListeners(repositoryContainer);
+ repositoryContainer.start();
+ return null;
+ }
+ });
}
catch (Throwable t)
{
@@ -418,11 +426,25 @@
repo.internalRemoveWorkspace(wsEntry.getName());
}
repconfig.getWorkspaceEntries().clear();
- RepositoryContainer repositoryContainer = repositoryContainers.get(name);
- repositoryContainer.stop();
+ final RepositoryContainer repositoryContainer = repositoryContainers.get(name);
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ repositoryContainer.stop();
+ return null;
+ }
+ });
repositoryContainers.remove(name);
config.getRepositoryConfigurations().remove(repconfig);
- parentContainer.unregisterComponent(repositoryContainer.getName());
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ parentContainer.unregisterComponent(repositoryContainer.getName());
+ return null;
+ }
+ });
}
catch (RepositoryConfigurationException e)
{
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java 2011-02-25 12:07:35 UTC (rev 4018)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/RepositoryImpl.java 2011-02-25 14:23:26 UTC (rev 4019)
@@ -18,6 +18,7 @@
*/
package org.exoplatform.services.jcr.impl.core;
+import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.services.jcr.access.AuthenticationPolicy;
import org.exoplatform.services.jcr.access.SystemIdentity;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
@@ -45,6 +46,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
@@ -217,16 +219,30 @@
}
catch (RepositoryConfigurationException e)
{
- WorkspaceContainer workspaceContainer = repositoryContainer.getWorkspaceContainer(wsConfig.getName());
- repositoryContainer.unregisterComponentByInstance(workspaceContainer);
- repositoryContainer.unregisterComponent(wsConfig.getName());
+ final WorkspaceContainer workspaceContainer = repositoryContainer.getWorkspaceContainer(wsConfig.getName());
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ repositoryContainer.unregisterComponentByInstance(workspaceContainer);
+ repositoryContainer.unregisterComponent(wsConfig.getName());
+ return null;
+ }
+ });
throw new RepositoryConfigurationException(e);
}
catch (RepositoryException e)
{
- WorkspaceContainer workspaceContainer = repositoryContainer.getWorkspaceContainer(wsConfig.getName());
- repositoryContainer.unregisterComponentByInstance(workspaceContainer);
- repositoryContainer.unregisterComponent(wsConfig.getName());
+ final WorkspaceContainer workspaceContainer = repositoryContainer.getWorkspaceContainer(wsConfig.getName());
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ repositoryContainer.unregisterComponentByInstance(workspaceContainer);
+ repositoryContainer.unregisterComponent(wsConfig.getName());
+ return null;
+ }
+ });
throw new RepositoryException(e);
}
}
@@ -269,9 +285,14 @@
+ " is not configured. Use RepositoryImpl.configWorkspace() method");
repositoryContainer.getWorkspaceContainer(workspaceName).getWorkspaceInitializer().initWorkspace();
-
- wsContainer.start();
-
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ wsContainer.start();
+ return null;
+ }
+ });
LOG.info("Workspace " + workspaceName + "@" + this.name + " is initialized");
}
@@ -447,7 +468,7 @@
* @param workspaceName workspace name
* @throws RepositoryException error of remove
*/
- public void internalRemoveWorkspace(String workspaceName) throws RepositoryException
+ public void internalRemoveWorkspace(final String workspaceName) throws RepositoryException
{
// Need privileges to manage repository.
SecurityManager security = System.getSecurityManager();
@@ -456,17 +477,31 @@
security.checkPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);
}
- WorkspaceContainer workspaceContainer = repositoryContainer.getWorkspaceContainer(workspaceName);
+ final WorkspaceContainer workspaceContainer = repositoryContainer.getWorkspaceContainer(workspaceName);
try
{
- workspaceContainer.stop();
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ workspaceContainer.stop();
+ return null;
+ }
+ });
}
catch (Exception e)
{
throw new RepositoryException(e);
}
- repositoryContainer.unregisterComponentByInstance(workspaceContainer);
- repositoryContainer.unregisterComponent(workspaceName);
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ repositoryContainer.unregisterComponentByInstance(workspaceContainer);
+ repositoryContainer.unregisterComponent(workspaceName);
+ return null;
+ }
+ });
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/ExoRepositoryStub.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/ExoRepositoryStub.java 2011-02-25 12:07:35 UTC (rev 4018)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/ExoRepositoryStub.java 2011-02-25 14:23:26 UTC (rev 4019)
@@ -145,16 +145,6 @@
if (!shoutDown)
{
- Runtime.getRuntime().addShutdownHook(new Thread()
- {
- public void run()
- {
- // database.close();
- servicesManager.stop();
-
- System.out.println("The container is stopped");
- }
- });
shoutDown = true;
}
Modified: kernel/trunk/exo.kernel.component.common/src/test/resources/test.policy
===================================================================
--- kernel/trunk/exo.kernel.component.common/src/test/resources/test.policy 2011-02-25 12:07:35 UTC (rev 4018)
+++ kernel/trunk/exo.kernel.component.common/src/test/resources/test.policy 2011-02-25 14:23:26 UTC (rev 4019)
@@ -10,6 +10,10 @@
permission java.lang.RuntimePermission "accessRPCService";
};
+grant codeBase "@TEST_CLASSES@-"{
+ permission java.lang.RuntimePermission "manageContainer";
+};
+
grant codeBase "@MAIN_CLASSES@../../../exo.kernel.commons.test/-"{
permission java.security.AllPermission;
};
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ConcurrentPicoContainer.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ConcurrentPicoContainer.java 2011-02-25 12:07:35 UTC (rev 4018)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ConcurrentPicoContainer.java 2011-02-25 14:23:26 UTC (rev 4019)
@@ -16,6 +16,7 @@
*/
package org.exoplatform.container;
+import org.exoplatform.container.security.ContainerPermissions;
import org.picocontainer.ComponentAdapter;
import org.picocontainer.MutablePicoContainer;
import org.picocontainer.Parameter;
@@ -218,6 +219,10 @@
public ComponentAdapter registerComponent(ComponentAdapter componentAdapter)
throws DuplicateComponentKeyRegistrationException
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_COMPONENT_PERMISSION);
+
Object componentKey = componentAdapter.getComponentKey();
if (componentKeyToAdapterCache.putIfAbsent(componentKey, componentAdapter) != null)
@@ -230,6 +235,10 @@
public ComponentAdapter unregisterComponent(Object componentKey)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_COMPONENT_PERMISSION);
+
ComponentAdapter adapter = componentKeyToAdapterCache.remove(componentKey);
componentAdapters.remove(adapter);
orderedComponentAdapters.remove(adapter);
@@ -504,11 +513,19 @@
public boolean addChildContainer(PicoContainer child)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
return children.add(child);
}
public boolean removeChildContainer(PicoContainer child)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
return children.remove(child);
}
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java 2011-02-25 12:07:35 UTC (rev 4018)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainer.java 2011-02-25 14:23:26 UTC (rev 4019)
@@ -19,9 +19,11 @@
package org.exoplatform.container;
import org.exoplatform.commons.utils.PropertyManager;
+import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.container.component.ComponentLifecyclePlugin;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.container.management.ManageableContainer;
+import org.exoplatform.container.security.ContainerPermissions;
import org.exoplatform.container.util.ContainerUtil;
import org.exoplatform.container.xml.Configuration;
import org.exoplatform.container.xml.InitParams;
@@ -31,6 +33,7 @@
import org.picocontainer.defaults.ComponentAdapterFactory;
import java.lang.reflect.Constructor;
+import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -96,27 +99,46 @@
public ExoContainer()
{
- context = new ExoContainerContext(this);
- context.setName(this.getClass().getName());
- registerComponentInstance(context);
+ context = new ExoContainerContext(this, this.getClass().getName());
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ registerComponentInstance(context);
+ return null;
+ }
+ });
+
this.parent = null;
}
public ExoContainer(PicoContainer parent)
{
super(parent);
- context = new ExoContainerContext(this);
- context.setName(this.getClass().getName());
- registerComponentInstance(context);
+ context = new ExoContainerContext(this, this.getClass().getName());
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ registerComponentInstance(context);
+ return null;
+ }
+ });
this.parent = parent;
}
public ExoContainer(ComponentAdapterFactory factory, PicoContainer parent)
{
super(factory, parent);
- context = new ExoContainerContext(this);
- context.setName(this.getClass().getName());
- registerComponentInstance(context);
+ context = new ExoContainerContext(this, this.getClass().getName());
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ registerComponentInstance(context);
+ return null;
+ }
+ });
this.parent = parent;
}
@@ -168,6 +190,10 @@
@Override
public void dispose()
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
destroyContainerInternal();
super.dispose();
}
@@ -178,6 +204,10 @@
*/
public void start(boolean init)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
if (init)
{
// Initialize the container first
@@ -189,6 +219,9 @@
@Override
public void start()
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
super.start();
startContainerInternal();
}
@@ -196,6 +229,10 @@
@Override
public void stop()
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
stopContainerInternal();
super.stop();
}
@@ -271,6 +308,10 @@
public void addComponentLifecylePlugin(ComponentLifecyclePlugin plugin)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
List<String> list = plugin.getManageableComponents();
for (String component : list)
componentLifecylePlugin_.put(component, plugin);
@@ -278,6 +319,10 @@
public void addContainerLifecylePlugin(ContainerLifecyclePlugin plugin)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
containerLifecyclePlugin_.add(plugin);
}
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainerContext.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainerContext.java 2011-02-25 12:07:35 UTC (rev 4018)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/ExoContainerContext.java 2011-02-25 14:23:26 UTC (rev 4019)
@@ -18,10 +18,12 @@
*/
package org.exoplatform.container;
+import org.exoplatform.container.security.ContainerPermissions;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Set;
/**
@@ -39,7 +41,7 @@
private HashMap<String, Object> attributes = new HashMap<String, Object>();
- private ExoContainer container;
+ private final ExoContainer container;
private String name;
@@ -50,6 +52,12 @@
this.container = container;
}
+ public ExoContainerContext(ExoContainer container, String name)
+ {
+ this.container = container;
+ this.name = name;
+ }
+
public ExoContainer getContainer()
{
return container;
@@ -114,6 +122,9 @@
public void setName(String name)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
this.name = name;
}
@@ -126,6 +137,10 @@
static void setTopContainer(ExoContainer cont)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
if (topContainer != null && cont != null)
throw new IllegalStateException("Two top level containers created, but must be only one.");
log.info("Set the top container in its context");
@@ -150,6 +165,9 @@
public static void setCurrentContainer(ExoContainer instance)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
currentContainer.set(instance);
}
@@ -164,7 +182,8 @@
public Set<String> getAttributeNames()
{
- return attributes.keySet();
+ // Gives a safe copy
+ return new HashSet<String>(attributes.keySet());
}
public Object getAttribute(String name)
@@ -174,6 +193,10 @@
public void setAttribute(String name, Object value)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
attributes.put(name, value);
}
}
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/PortalContainer.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/PortalContainer.java 2011-02-25 12:07:35 UTC (rev 4018)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/PortalContainer.java 2011-02-25 14:23:26 UTC (rev 4019)
@@ -23,6 +23,7 @@
import org.exoplatform.container.RootContainer.PortalContainerInitTask;
import org.exoplatform.container.definition.PortalContainerConfig;
import org.exoplatform.container.jmx.MX4JComponentAdapterFactory;
+import org.exoplatform.container.security.ContainerPermissions;
import org.exoplatform.container.xml.Configuration;
import org.exoplatform.container.xml.PortalContainerInfo;
import org.exoplatform.management.annotations.Managed;
@@ -141,14 +142,28 @@
*/
final ServletContext portalContext;
- public PortalContainer(RootContainer parent, ServletContext portalContext)
+ public PortalContainer(RootContainer parent, final ServletContext portalContext)
{
super(new MX4JComponentAdapterFactory(), parent);
- registerComponentInstance(ServletContext.class, portalContext);
- context.setName(portalContext.getServletContextName());
+ this.name = portalContext.getServletContextName();
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ context.setName(name);
+ return null;
+ }
+ });
pinfo_ = new PortalContainerInfo(portalContext);
- registerComponentInstance(PortalContainerInfo.class, pinfo_);
- this.name = portalContext.getServletContextName();
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ registerComponentInstance(ServletContext.class, portalContext);
+ registerComponentInstance(PortalContainerInfo.class, pinfo_);
+ return null;
+ }
+ });
final PortalContainerConfig config = parent.getPortalContainerConfig();
final List<String> dependencies = config == null ? null : config.getDependencies(name);
if (dependencies == null || dependencies.isEmpty())
@@ -239,6 +254,9 @@
*/
public synchronized void registerContext(ServletContext context)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
final WebAppInitContext webappCtx = new WebAppInitContext(context);
if (!webAppContexts.contains(webappCtx))
{
@@ -263,6 +281,10 @@
*/
public synchronized void unregisterContext(ServletContext context)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
final WebAppInitContext webappCtx = new WebAppInitContext(context);
if (webAppContexts.contains(webappCtx))
{
@@ -309,6 +331,10 @@
public SessionContainer createSessionContainer(String id, String owner)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
SessionContainer scontainer = getSessionManager().getSessionContainer(id);
if (scontainer != null)
getSessionManager().removeSessionContainer(id);
@@ -321,6 +347,10 @@
public void removeSessionContainer(String sessionID)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
getSessionManager().removeSessionContainer(sessionID);
}
@@ -351,7 +381,15 @@
if (container == null)
{
container = RootContainer.getInstance().getPortalContainer(DEFAULT_PORTAL_CONTAINER_NAME);
- PortalContainer.setInstance(container);
+ final PortalContainer currentPortalContainer = container;
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ PortalContainer.setInstance(currentPortalContainer);
+ return null;
+ }
+ });
}
return container;
}
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java 2011-02-25 12:07:35 UTC (rev 4018)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java 2011-02-25 14:23:26 UTC (rev 4019)
@@ -29,6 +29,7 @@
import org.exoplatform.container.definition.PortalContainerDefinition;
import org.exoplatform.container.monitor.jvm.J2EEServerInfo;
import org.exoplatform.container.monitor.jvm.OperatingSystemInfo;
+import org.exoplatform.container.security.ContainerPermissions;
import org.exoplatform.container.util.ContainerUtil;
import org.exoplatform.container.xml.Configuration;
import org.exoplatform.management.annotations.Managed;
@@ -123,7 +124,14 @@
}
});
this.profiles = profiles;
- this.registerComponentInstance(J2EEServerInfo.class, serverenv_);
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ registerComponentInstance(J2EEServerInfo.class, serverenv_);
+ return null;
+ }
+ });
}
public OperatingSystemInfo getOSEnvironment()
@@ -162,7 +170,7 @@
return serverenv_;
}
- public PortalContainer getPortalContainer(String name)
+ public PortalContainer getPortalContainer(final String name)
{
PortalContainer pcontainer = (PortalContainer)this.getComponentInstance(name);
if (pcontainer == null)
@@ -174,14 +182,29 @@
{
MockServletContext scontext = new MockServletContext(name);
pcontainer = new PortalContainer(this, scontext);
- PortalContainer.setInstance(pcontainer);
- ConfigurationManagerImpl cService = new MockConfigurationManagerImpl(scontext);
+ final PortalContainer currentPortalContainer = pcontainer;
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ PortalContainer.setInstance(currentPortalContainer);
+ return null;
+ }
+ });
+ final ConfigurationManagerImpl cService = new MockConfigurationManagerImpl(scontext);
cService.addConfiguration(ContainerUtil.getConfigurationURL("conf/portal/configuration.xml"));
cService.addConfiguration(ContainerUtil.getConfigurationURL("conf/portal/test-configuration.xml"));
cService.processRemoveConfiguration();
- pcontainer.registerComponentInstance(ConfigurationManager.class, cService);
- registerComponentInstance(name, pcontainer);
- pcontainer.start(true);
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ currentPortalContainer.registerComponentInstance(ConfigurationManager.class, cService);
+ registerComponentInstance(name, currentPortalContainer);
+ currentPortalContainer.start(true);
+ return null;
+ }
+ });
}
catch (Exception ex)
{
@@ -200,6 +223,10 @@
*/
public void registerPortalContainer(ServletContext context)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
PortalContainerConfig config = getPortalContainerConfig();
if (config.hasDefinition())
{
@@ -286,6 +313,10 @@
public synchronized void createPortalContainer(ServletContext context)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
// Keep the old ClassLoader
final ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
boolean hasChanged = false;
@@ -399,6 +430,10 @@
synchronized public void removePortalContainer(ServletContext servletContext)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
this.unregisterComponent(servletContext.getServletContextName());
}
@@ -417,8 +452,8 @@
{
try
{
- RootContainer rootContainer = new RootContainer();
- ConfigurationManagerImpl service = new ConfigurationManagerImpl(rootContainer.profiles);
+ final RootContainer rootContainer = new RootContainer();
+ final ConfigurationManagerImpl service = new ConfigurationManagerImpl(rootContainer.profiles);
service.addConfiguration(ContainerUtil.getConfigurationURL("conf/configuration.xml"));
if (PrivilegedSystemHelper.getProperty("maven.exoplatform.dir") != null)
{
@@ -432,13 +467,23 @@
service.addConfiguration("file:" + overrideConf);
}
service.processRemoveConfiguration();
- rootContainer.registerComponentInstance(ConfigurationManager.class, service);
- rootContainer.start(true);
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ rootContainer.registerComponentInstance(ConfigurationManager.class, service);
+ rootContainer.start(true);
+ return null;
+ }
+ });
return rootContainer;
}
catch (Exception e)
{
log.error("Could not build root container", e);
+ // The logger is not necessary configured so we have to use the standard
+ // output stream
+ e.printStackTrace();
return null;
}
}
@@ -475,8 +520,15 @@
{
time += System.currentTimeMillis();
log.info("Root container is built (build time " + time + "ms)");
- ExoContainerContext.setTopContainer(result);
singleton_ = result;
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ ExoContainerContext.setTopContainer(singleton_);
+ return null;
+ }
+ });
log.info("Root container booted");
}
else
@@ -497,6 +549,10 @@
static public void setInstance(RootContainer rcontainer)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
singleton_ = rcontainer;
}
@@ -536,6 +592,10 @@
*/
public void addInitTask(ServletContext context, PortalContainerInitTask task, String portalContainer)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
final PortalContainer container = getPortalContainer(portalContainer);
if (!task.alreadyExists(container))
{
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/SessionContainer.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/SessionContainer.java 2011-02-25 12:07:35 UTC (rev 4018)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/SessionContainer.java 2011-02-25 14:23:26 UTC (rev 4019)
@@ -19,6 +19,7 @@
package org.exoplatform.container;
import org.exoplatform.container.client.ClientInfo;
+import org.exoplatform.container.security.ContainerPermissions;
import java.util.HashMap;
@@ -28,7 +29,7 @@
*/
public class SessionContainer extends HashMap<Object, Object>
{
- private static ThreadLocal threadLocal_ = new ThreadLocal();
+ private static ThreadLocal<SessionContainer> threadLocal_ = new ThreadLocal<SessionContainer>();
final public static int INIT_STATUS = 0;
@@ -149,7 +150,7 @@
public static Object getComponent(Class key)
{
- SessionContainer scontainer = (SessionContainer)threadLocal_.get();
+ SessionContainer scontainer = getInstance();
return scontainer.get(key);
}
@@ -170,11 +171,15 @@
static public SessionContainer getInstance()
{
- return (SessionContainer)threadLocal_.get();
+ return threadLocal_.get();
}
static public void setInstance(SessionContainer scontainer)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
threadLocal_.set(scontainer);
}
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/SessionManagerImpl.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/SessionManagerImpl.java 2011-02-25 12:07:35 UTC (rev 4018)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/SessionManagerImpl.java 2011-02-25 14:23:26 UTC (rev 4019)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.container;
+import org.exoplatform.container.security.ContainerPermissions;
+
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
@@ -43,11 +45,19 @@
final public void removeSessionContainer(String id)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
remove(id);
}
final public void addSessionContainer(SessionContainer scontainer)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
put(scontainer.getSessionId(), scontainer);
}
}
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/StandaloneContainer.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/StandaloneContainer.java 2011-02-25 12:07:35 UTC (rev 4018)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/StandaloneContainer.java 2011-02-25 14:23:26 UTC (rev 4019)
@@ -36,6 +36,7 @@
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
+import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
import java.util.List;
@@ -83,8 +84,15 @@
//
configurationManager = new ConfigurationManagerImpl(configClassLoader, ExoContainer.getProfiles());
- this.registerComponentInstance(ConfigurationManager.class, configurationManager);
- registerComponentImplementation(SessionManagerImpl.class);
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ registerComponentInstance(ConfigurationManager.class, configurationManager);
+ registerComponentImplementation(SessionManagerImpl.class);
+ return null;
+ }
+ });
}
/**
@@ -137,7 +145,14 @@
if (container == null)
{
container = new StandaloneContainer(configClassLoader);
- ExoContainerContext.setTopContainer(container);
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ ExoContainerContext.setTopContainer(container);
+ return null;
+ }
+ });
if (useDefault)
container.initDefaultConf();
// initialize configurationURL
@@ -145,7 +160,14 @@
container.populate(configurationURL);
if (components != null)
container.registerArray(components);
- container.start();
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ container.start();
+ return null;
+ }
+ });
PrivilegedSystemHelper.setProperty("exo.standalone-container", StandaloneContainer.class.getName());
System.out.println("StandaloneContainer initialized using: " + configurationURL);
}
@@ -401,7 +423,14 @@
{
configurationManager.addConfiguration(conf);
configurationManager.processRemoveConfiguration();
- ContainerUtil.addComponents(this, configurationManager);
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ ContainerUtil.addComponents(StandaloneContainer.this, configurationManager);
+ return null;
+ }
+ });
}
}
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java 2011-02-25 12:07:35 UTC (rev 4018)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java 2011-02-25 14:23:26 UTC (rev 4019)
@@ -25,6 +25,7 @@
import org.exoplatform.container.RootContainer;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.container.monitor.jvm.J2EEServerInfo;
+import org.exoplatform.container.security.ContainerPermissions;
import org.exoplatform.container.util.ContainerUtil;
import org.exoplatform.container.xml.Deserializer;
import org.exoplatform.container.xml.InitParams;
@@ -375,6 +376,10 @@
*/
public synchronized void disablePortalContainer(String name)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
if (!portalContainerNamesDisabled.contains(name))
{
if (PropertyManager.isDevelopping())
@@ -437,6 +442,10 @@
*/
public synchronized void registerPortalContainerName(String name)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
if (!portalContainerNames.contains(name) && !portalContainerNamesDisabled.contains(name))
{
final List<String> lPortalContainerNames = new ArrayList<String>(portalContainerNames.size() + 1);
@@ -452,6 +461,10 @@
*/
public synchronized void unregisterPortalContainerName(String name)
{
+ SecurityManager security = System.getSecurityManager();
+ if (security != null)
+ security.checkPermission(ContainerPermissions.MANAGE_CONTAINER_PERMISSION);
+
if (portalContainerNames.contains(name))
{
final List<String> lPortalContainerNames = new ArrayList<String>(portalContainerNames);
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManageableContainer.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManageableContainer.java 2011-02-25 12:07:35 UTC (rev 4018)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManageableContainer.java 2011-02-25 14:23:26 UTC (rev 4019)
@@ -32,7 +32,6 @@
import org.picocontainer.PicoException;
import org.picocontainer.PicoRegistrationException;
import org.picocontainer.defaults.ComponentAdapterFactory;
-import org.picocontainer.defaults.DuplicateComponentKeyRegistrationException;
import java.util.Collection;
import java.util.Collections;
@@ -156,13 +155,6 @@
return server;
}
- @Override
- public ComponentAdapter registerComponent(ComponentAdapter componentAdapter)
- throws DuplicateComponentKeyRegistrationException
- {
- return super.registerComponent(componentAdapter);
- }
-
public ComponentAdapter registerComponentInstance(Object componentKey, Object componentInstance)
throws PicoRegistrationException
{
Added: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/security/ContainerPermissions.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/security/ContainerPermissions.java (rev 0)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/security/ContainerPermissions.java 2011-02-25 14:23:26 UTC (rev 4019)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2011 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.container.security;
+
+import java.security.Permission;
+
+/**
+ * This interface defines all the permissions used by the project kernel.container
+ *
+ * @author <a href="mailto:nicolas.filotto@exoplatform.com">Nicolas Filotto</a>
+ * @version $Id$
+ *
+ */
+public interface ContainerPermissions
+{
+ /**
+ * Any operations applied on a container have to be protected with this permission
+ */
+ public static final Permission MANAGE_CONTAINER_PERMISSION = new RuntimePermission("manageContainer");
+
+ /**
+ * Any component modifications have to be protected with this permission
+ */
+ public static final Permission MANAGE_COMPONENT_PERMISSION = new RuntimePermission("manageComponent");
+}
Modified: kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/web/PortalContainerCreator.java
===================================================================
--- kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/web/PortalContainerCreator.java 2011-02-25 12:07:35 UTC (rev 4018)
+++ kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/web/PortalContainerCreator.java 2011-02-25 14:23:26 UTC (rev 4019)
@@ -18,9 +18,12 @@
*/
package org.exoplatform.container.web;
+import org.exoplatform.commons.utils.SecurityHelper;
import org.exoplatform.container.RootContainer;
import org.exoplatform.container.util.EnvSpecific;
+import java.security.PrivilegedAction;
+
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
@@ -53,8 +56,15 @@
try
{
EnvSpecific.initThreadEnv(ctx);
- RootContainer rootContainer = RootContainer.getInstance();
- rootContainer.createPortalContainers();
+ final RootContainer rootContainer = RootContainer.getInstance();
+ SecurityHelper.doPrivilegedAction(new PrivilegedAction<Void>()
+ {
+ public Void run()
+ {
+ rootContainer.createPortalContainers();
+ return null;
+ }
+ });
}
finally
{
Modified: kernel/trunk/exo.kernel.container/src/test/resources/test.policy
===================================================================
--- kernel/trunk/exo.kernel.container/src/test/resources/test.policy 2011-02-25 12:07:35 UTC (rev 4018)
+++ kernel/trunk/exo.kernel.container/src/test/resources/test.policy 2011-02-25 14:23:26 UTC (rev 4019)
@@ -7,6 +7,8 @@
};
grant codeBase "@TEST_CLASSES@-"{
+ permission java.lang.RuntimePermission "manageContainer";
+ permission java.lang.RuntimePermission "manageComponent";
};
grant codeBase "@MAIN_CLASSES@../../../exo.kernel.commons.test/-"{
Modified: ws/trunk/exo.ws.rest.core/src/test/resources/test.policy
===================================================================
--- ws/trunk/exo.ws.rest.core/src/test/resources/test.policy 2011-02-25 12:07:35 UTC (rev 4018)
+++ ws/trunk/exo.ws.rest.core/src/test/resources/test.policy 2011-02-25 14:23:26 UTC (rev 4019)
@@ -7,6 +7,7 @@
};
grant codeBase "@TEST_CLASSES@-"{
+ permission java.lang.RuntimePermission "manageComponent";
};
grant codeBase "@MAIN_CLASSES@../../../exo.ws.frameworks.json/-"{
Modified: ws/trunk/exo.ws.rest.ext/src/test/resources/test.policy
===================================================================
--- ws/trunk/exo.ws.rest.ext/src/test/resources/test.policy 2011-02-25 12:07:35 UTC (rev 4018)
+++ ws/trunk/exo.ws.rest.ext/src/test/resources/test.policy 2011-02-25 14:23:26 UTC (rev 4019)
@@ -7,6 +7,7 @@
};
grant codeBase "@TEST_CLASSES@-" {
+ permission java.lang.RuntimePermission "manageComponent";
};
grant codeBase "@MAIN_CLASSES@../../../exo.ws.commons/-"{
13 years, 2 months
exo-jcr SVN: r4018 - jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2011-02-25 07:07:35 -0500 (Fri, 25 Feb 2011)
New Revision: 4018
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/AbstractInputCacheStore.java
Log:
EXOJCR-832 : removing some UnsupportedOperationExceptions.
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/AbstractInputCacheStore.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/AbstractInputCacheStore.java 2011-02-25 10:29:18 UTC (rev 4017)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/AbstractInputCacheStore.java 2011-02-25 12:07:35 UTC (rev 4018)
@@ -74,7 +74,7 @@
@Override
protected void purgeInternal() throws CacheLoaderException
{
- throw new UnsupportedOperationException("This operation is not supported by this component.");
+ // This cacheStore only accepts data
}
/**
13 years, 2 months
exo-jcr SVN: r4017 - in jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query: ispn and 1 other directories.
by do-not-reply@jboss.org
Author: nzamosenchuk
Date: 2011-02-25 05:29:18 -0500 (Fri, 25 Feb 2011)
New Revision: 4017
Added:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/Indexer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/AbstractInputCacheStore.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/LocalIndexChangesFilter.java
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/ChangesKey.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/ISPNIndexChangesFilter.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/IndexerCacheStore.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java
Log:
EXOJCR-832 : Implementing IndexerCacheStore, extracting "Indexer" class from indexerCacheLoader.
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/Indexer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/Indexer.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/Indexer.java 2011-02-25 10:29:18 UTC (rev 4017)
@@ -0,0 +1,155 @@
+package org.exoplatform.services.jcr.impl.core.query;
+
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.impl.core.query.lucene.ChangesHolder;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * This class will update the indexes of the related workspace
+ */
+public class Indexer
+{
+ private static final Log log = ExoLogger.getLogger("exo.jcr.component.core.Indexer");
+
+ private final SearchManager searchManager;
+
+ private final SearchManager parentSearchManager;
+
+ private final QueryHandler handler;
+
+ private final QueryHandler parentHandler;
+
+ public Indexer(SearchManager searchManager, SearchManager parentSearchManager, QueryHandler handler,
+ QueryHandler parentHandler) throws RepositoryConfigurationException
+ {
+ this.searchManager = searchManager;
+ this.parentSearchManager = parentSearchManager;
+ this.handler = handler;
+ this.parentHandler = parentHandler;
+ }
+
+ /**
+ * Flushes lists of added/removed nodes to SearchManagers, starting indexing.
+ *
+ * @param addedNodes
+ * @param removedNodes
+ * @param parentAddedNodes
+ * @param parentRemovedNodes
+ */
+ public void updateIndex(Set<String> addedNodes, Set<String> removedNodes, Set<String> parentAddedNodes,
+ Set<String> parentRemovedNodes)
+ {
+ // pass lists to search manager
+ if (searchManager != null && (addedNodes.size() > 0 || removedNodes.size() > 0))
+ {
+ try
+ {
+ searchManager.updateIndex(removedNodes, addedNodes);
+ }
+ catch (RepositoryException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ }
+ catch (IOException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ try
+ {
+ handler.logErrorChanges(removedNodes, addedNodes);
+ }
+ catch (IOException ioe)
+ {
+ log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
+ }
+ }
+ }
+ // pass lists to parent search manager
+ if (parentSearchManager != null && (parentAddedNodes.size() > 0 || parentRemovedNodes.size() > 0))
+ {
+ try
+ {
+ parentSearchManager.updateIndex(parentRemovedNodes, parentAddedNodes);
+ }
+ catch (RepositoryException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ }
+ catch (IOException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ try
+ {
+ parentHandler.logErrorChanges(parentRemovedNodes, parentAddedNodes);
+ }
+ catch (IOException ioe)
+ {
+ log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
+ }
+ }
+ }
+ }
+
+ /**
+ * Flushes lists of added/removed nodes to SearchManagers, starting indexing.
+ */
+ public void updateIndex(ChangesHolder changes, ChangesHolder parentChanges)
+ {
+ // pass lists to search manager
+ if (searchManager != null && changes != null)
+ {
+ try
+ {
+ searchManager.apply(changes);
+ }
+ catch (RepositoryException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ }
+ catch (IOException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ try
+ {
+ handler.logErrorChanges(new HashSet<String>(changes.getRemove()), new HashSet<String>(changes
+ .getAddIds()));
+ }
+ catch (IOException ioe)
+ {
+ log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
+ }
+ }
+ }
+ // pass lists to parent search manager
+ if (parentSearchManager != null && parentChanges != null)
+ {
+ try
+ {
+ parentSearchManager.apply(parentChanges);
+ }
+ catch (RepositoryException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ }
+ catch (IOException e)
+ {
+ log.error("Error indexing changes " + e, e);
+ try
+ {
+ parentHandler.logErrorChanges(new HashSet<String>(parentChanges.getRemove()), new HashSet<String>(
+ parentChanges.getAddIds()));
+ }
+ catch (IOException ioe)
+ {
+ log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Property changes on: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/Indexer.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/AbstractInputCacheStore.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/AbstractInputCacheStore.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/AbstractInputCacheStore.java 2011-02-25 10:29:18 UTC (rev 4017)
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2011 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.core.query.ispn;
+
+import org.infinispan.container.entries.InternalCacheEntry;
+import org.infinispan.loaders.AbstractCacheStore;
+import org.infinispan.loaders.AbstractCacheStoreConfig;
+import org.infinispan.loaders.CacheLoaderConfig;
+import org.infinispan.loaders.CacheLoaderException;
+
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:nikolazius@gmail.com">Nikolay Zamosenchuk</a>
+ * @version $Id: AbstractInputCacheStore.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
+ *
+ */
+public abstract class AbstractInputCacheStore extends AbstractCacheStore
+{
+
+ /**
+ *
+ */
+ public AbstractInputCacheStore()
+ {
+ super();
+ }
+
+ /**
+ * @see org.infinispan.loaders.CacheLoader#getConfigurationClass()
+ */
+ public Class<? extends CacheLoaderConfig> getConfigurationClass()
+ {
+ return AbstractCacheStoreConfig.class;
+ }
+
+ /**
+ * @see org.infinispan.loaders.CacheStore#fromStream(java.io.ObjectInput)
+ */
+ public void fromStream(ObjectInput inputStream) throws CacheLoaderException
+ {
+ throw new UnsupportedOperationException("This operation is not supported by this component.");
+ }
+
+ /**
+ * @see org.infinispan.loaders.CacheStore#toStream(java.io.ObjectOutput)
+ */
+ public void toStream(ObjectOutput outputStream) throws CacheLoaderException
+ {
+ throw new UnsupportedOperationException("This operation is not supported by this component.");
+ }
+
+ /**
+ * @see org.infinispan.loaders.AbstractCacheStore#purgeInternal()
+ */
+ @Override
+ protected void purgeInternal() throws CacheLoaderException
+ {
+ throw new UnsupportedOperationException("This operation is not supported by this component.");
+ }
+
+ /**
+ * @see org.infinispan.loaders.CacheStore#clear()
+ */
+ public void clear() throws CacheLoaderException
+ {
+ throw new UnsupportedOperationException("This operation is not supported by this component.");
+ }
+
+ /**
+ * @see org.infinispan.loaders.CacheStore#remove(java.lang.Object)
+ */
+ public boolean remove(Object key) throws CacheLoaderException
+ {
+ // This cacheStore only accepts data
+ return false;
+ }
+
+ /**
+ * @see org.infinispan.loaders.CacheLoader#load(java.lang.Object)
+ */
+ public InternalCacheEntry load(Object key) throws CacheLoaderException
+ {
+ // This cacheStore only accepts data
+ return null;
+ }
+
+ /**
+ * @see org.infinispan.loaders.CacheLoader#load(int)
+ */
+ public Set<InternalCacheEntry> load(int numEntries) throws CacheLoaderException
+ {
+ // This cacheStore only accepts data
+ return null;
+ }
+
+ /**
+ * @see org.infinispan.loaders.CacheLoader#loadAll()
+ */
+ public Set<InternalCacheEntry> loadAll() throws CacheLoaderException
+ {
+ // This cacheStore only accepts data
+ return null;
+ }
+
+ /**
+ * @see org.infinispan.loaders.CacheLoader#loadAllKeys(java.util.Set)
+ */
+ public Set<Object> loadAllKeys(Set<Object> keysToExclude) throws CacheLoaderException
+ {
+ // This cacheStore only accepts data
+ return null;
+ }
+
+}
\ No newline at end of file
Property changes on: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/AbstractInputCacheStore.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/ChangesKey.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/ChangesKey.java 2011-02-25 08:27:21 UTC (rev 4016)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/ChangesKey.java 2011-02-25 10:29:18 UTC (rev 4017)
@@ -30,6 +30,8 @@
*/
public class ChangesKey extends CacheKey
{
+ private static final long serialVersionUID = 8597037282459379392L;
+
private final int wsId;
ChangesKey(int wsId, String id)
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/ISPNIndexChangesFilter.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/ISPNIndexChangesFilter.java 2011-02-25 08:27:21 UTC (rev 4016)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/ISPNIndexChangesFilter.java 2011-02-25 10:29:18 UTC (rev 4017)
@@ -22,6 +22,7 @@
import org.exoplatform.services.jcr.config.QueryHandlerEntry;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
import org.exoplatform.services.jcr.impl.core.query.IndexerChangesFilter;
+import org.exoplatform.services.jcr.impl.core.query.IndexerIoModeHandler;
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;
@@ -34,6 +35,8 @@
import org.exoplatform.services.log.Log;
import org.infinispan.Cache;
import org.infinispan.CacheException;
+import org.infinispan.config.Configuration.CacheMode;
+import org.infinispan.loaders.CacheLoaderManager;
import java.io.IOException;
import java.io.Serializable;
@@ -78,55 +81,37 @@
this.wsId = searchManager.getWsId().hashCode();
- // initialize IndexerCacheLoader
- // IndexerCacheStore indexerCacheStore = new IndexerCacheStore();
- //
- // // try to get pushState parameters, since they are set programmatically only
- // // Boolean pushState = config.getParameterBoolean(PARAM_JBOSSCACHE_PUSHSTATE, false);
- // // Long pushStateTimeOut = config.getParameterTime(PARAM_JBOSSCACHE_PUSHSTATE_TIMEOUT, 10000L);
- //
- // // insert CacheLoaderConfig
ISPNCacheFactory<Serializable, Object> factory = new ISPNCacheFactory<Serializable, Object>(cfm);
this.cache = factory.createCache("Indexer-" + searchManager.getWsId(), config);
- //
- // // Could have change of cache
- // CacheLoaderManager cacheLoaderManager =
- // cache.getAdvancedCache().getComponentRegistry().getComponent(CacheLoaderManager.class);
- // IndexerCacheStore cacheStore = (IndexerCacheStore)cacheLoaderManager.getCacheLoader();
- // This code make it possible to use the JBossCacheIndexChangesFilter in
- // a non-cluster environment
- // if (cache.getConfiguration().getCacheMode() == CacheMode.LOCAL)
- // {
- // // Activate the cache loader
- // try
- // {
- // cacheStore.activeStatusChanged(true);
- // }
- // catch (PushStateException e)
- // {
- // // ignore me;
- // }
- // }
- // indexerCacheLoader = (IndexerCacheLoader)issCacheLoader.getCacheLoader();
- //
- // indexerCacheLoader.register(searchManager, parentSearchManager, handler, parentHandler);
- // IndexerIoModeHandler modeHandler = indexerCacheLoader.getModeHandler();
- // handler.setIndexerIoModeHandler(modeHandler);
- // parentHandler.setIndexerIoModeHandler(modeHandler);
- //
- // if (!parentHandler.isInitialized())
- // {
- // parentHandler.setIndexInfos(new ISPNIndexInfos(searchManager.getWsId(), cache, true, modeHandler));
- // parentHandler.setIndexUpdateMonitor(new ISPNIndexUpdateMonitor(searchManager.getWsId(), cache, true, modeHandler));
- // parentHandler.init();
- // }
- // if (!handler.isInitialized())
- // {
- // handler.setIndexInfos(new ISPNIndexInfos(searchManager.getWsId(), cache, false, modeHandler));
- // handler.setIndexUpdateMonitor(new ISPNIndexUpdateMonitor(searchManager.getWsId(), cache, false, modeHandler));
- // handler.init();
- // }
+ CacheLoaderManager cacheLoaderManager =
+ cache.getAdvancedCache().getComponentRegistry().getComponent(CacheLoaderManager.class);
+ IndexerCacheStore cacheStore = (IndexerCacheStore)cacheLoaderManager.getCacheLoader();
+
+ // This code make it possible to use the ISPNIndexChangesFilter in a non-cluster environment
+ if (cache.getConfiguration().getCacheMode() == CacheMode.LOCAL)
+ {
+ cacheStore.activeStatusChanged(true);
+ }
+
+ cacheStore.register(searchManager, parentSearchManager, handler, parentHandler);
+ IndexerIoModeHandler modeHandler = cacheStore.getModeHandler();
+ handler.setIndexerIoModeHandler(modeHandler);
+ parentHandler.setIndexerIoModeHandler(modeHandler);
+
+ if (!parentHandler.isInitialized())
+ {
+ parentHandler.setIndexInfos(new ISPNIndexInfos(searchManager.getWsId(), cache, true, modeHandler));
+ parentHandler.setIndexUpdateMonitor(new ISPNIndexUpdateMonitor(searchManager.getWsId(), cache, true,
+ modeHandler));
+ parentHandler.init();
+ }
+ if (!handler.isInitialized())
+ {
+ handler.setIndexInfos(new ISPNIndexInfos(searchManager.getWsId(), cache, false, modeHandler));
+ handler.setIndexUpdateMonitor(new ISPNIndexUpdateMonitor(searchManager.getWsId(), cache, false, modeHandler));
+ handler.init();
+ }
}
/**
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/IndexerCacheStore.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/IndexerCacheStore.java 2011-02-25 08:27:21 UTC (rev 4016)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/IndexerCacheStore.java 2011-02-25 10:29:18 UTC (rev 4017)
@@ -1,386 +1,326 @@
-/*
- * Copyright (C) 2003-2009 eXo Platform SAS.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Affero General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, see<http://www.gnu.org/licenses/>.
- */
-package org.exoplatform.services.jcr.impl.core.query.ispn;
-
-import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
-import org.exoplatform.services.jcr.impl.core.query.IndexerIoMode;
-import org.exoplatform.services.jcr.impl.core.query.IndexerIoModeHandler;
-import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
-import org.exoplatform.services.jcr.impl.core.query.SearchManager;
-import org.exoplatform.services.jcr.impl.core.query.jbosscache.ChangesFilterListsWrapper;
-import org.exoplatform.services.jcr.impl.core.query.jbosscache.JBossCacheIndexChangesFilter;
-import org.exoplatform.services.jcr.impl.core.query.lucene.ChangesHolder;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-import org.infinispan.container.entries.InternalCacheEntry;
-import org.infinispan.lifecycle.ComponentStatus;
-import org.infinispan.loaders.AbstractCacheStore;
-import org.infinispan.loaders.CacheLoaderConfig;
-import org.infinispan.loaders.CacheLoaderException;
-import org.jboss.cache.Fqn;
-
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import javax.jcr.RepositoryException;
-
-/**
- * Created by The eXo Platform SAS.
- *
- * Date: 23.02.2011
- *
- * @author <a href="mailto:anatoliy.bazko@exoplatform.com.ua">Anatoliy Bazko</a>
- * @version $Id: IndexerCacheStore.java 34360 2010-11-11 11:11:11Z tolusha $
- */
-public class IndexerCacheStore extends AbstractCacheStore
-{
- private static final Log log = ExoLogger.getLogger("exo.jcr.component.core.IndexerCacheStore");
-
- /**
- * A map of all the indexers that has been registered.
- */
- private final Map<Fqn<String>, Indexer> indexers = new HashMap<Fqn<String>, Indexer>();
-
- protected volatile IndexerIoModeHandler modeHandler;
-
- /**
- * This method will register a new Indexer according to the given parameters.
- *
- * @param searchManager
- * @param parentSearchManager
- * @param handler
- * @param parentHandler
- * @throws RepositoryConfigurationException
- */
- public void register(SearchManager searchManager, SearchManager parentSearchManager, QueryHandler handler,
- QueryHandler parentHandler) throws RepositoryConfigurationException
- {
- indexers.put(Fqn.fromElements(searchManager.getWsId()), new Indexer(searchManager, parentSearchManager, handler,
- parentHandler));
- if (log.isDebugEnabled())
- {
- log.debug("Register " + searchManager.getWsId() + " " + this + " in " + indexers);
- }
- }
-
- /**
- * @see org.jboss.cache.loader.CacheLoader#put(org.jboss.cache.Fqn, java.lang.Object, java.lang.Object)
- */
- public Object put(Fqn name, Object key, Object value) throws Exception
- {
- if (key.equals(JBossCacheIndexChangesFilter.LISTWRAPPER) && value instanceof ChangesFilterListsWrapper)
- {
- if (log.isDebugEnabled())
- {
- log.info("Received list wrapper, start indexing...");
- }
- // updating index
- ChangesFilterListsWrapper wrapper = (ChangesFilterListsWrapper)value;
- try
- {
- Indexer indexer = indexers.get(name.getParent());
- if (indexer == null)
- {
- log.warn("No indexer could be found for the fqn " + name.getParent());
- if (log.isDebugEnabled())
- {
- log.debug("The current content of the map of indexers is " + indexers);
- }
- }
- else if (wrapper.withChanges())
- {
- indexer.updateIndex(wrapper.getChanges(), wrapper.getParentChanges());
- }
- else
- {
- indexer.updateIndex(wrapper.getAddedNodes(), wrapper.getRemovedNodes(), wrapper.getParentAddedNodes(),
- wrapper.getParentRemovedNodes());
- }
- }
- finally
- {
- if (modeHandler.getMode() == IndexerIoMode.READ_WRITE)
- {
- // remove the data from the cache
- // cache.removeNode(name);
- }
- }
- }
- return null;
- }
-
- /**
- * Switches Indexer mode from RO to RW, or from RW to RO
- *
- * @param ioMode
- */
- void setMode(IndexerIoMode ioMode)
- {
- if (modeHandler != null)
- {
- modeHandler.setMode(ioMode);
- }
- }
-
- /**
- * Get the mode handler.
- */
- IndexerIoModeHandler getModeHandler()
- {
- if (modeHandler == null)
- {
- if (cache.getStatus() != ComponentStatus.RUNNING)
- {
- throw new IllegalStateException("The cache should be started first");
- }
- synchronized (this)
- {
- if (modeHandler == null)
- {
- boolean isCoordinator = cache.getAdvancedCache().getRpcManager().getTransport().isCoordinator();
- this.modeHandler =
- new IndexerIoModeHandler(isCoordinator ? IndexerIoMode.READ_WRITE : IndexerIoMode.READ_ONLY);
- }
- }
- }
- return modeHandler;
- }
-
- /**
- * This class will update the indexes of the related workspace
- */
- private static class Indexer
- {
-
- private final SearchManager searchManager;
-
- private final SearchManager parentSearchManager;
-
- private final QueryHandler handler;
-
- private final QueryHandler parentHandler;
-
- public Indexer(SearchManager searchManager, SearchManager parentSearchManager, QueryHandler handler,
- QueryHandler parentHandler) throws RepositoryConfigurationException
- {
- this.searchManager = searchManager;
- this.parentSearchManager = parentSearchManager;
- this.handler = handler;
- this.parentHandler = parentHandler;
- }
-
- /**
- * Flushes lists of added/removed nodes to SearchManagers, starting indexing.
- *
- * @param addedNodes
- * @param removedNodes
- * @param parentAddedNodes
- * @param parentRemovedNodes
- */
- protected void updateIndex(Set<String> addedNodes, Set<String> removedNodes, Set<String> parentAddedNodes,
- Set<String> parentRemovedNodes)
- {
- // pass lists to search manager
- if (searchManager != null && (addedNodes.size() > 0 || removedNodes.size() > 0))
- {
- try
- {
- searchManager.updateIndex(removedNodes, addedNodes);
- }
- catch (RepositoryException e)
- {
- log.error("Error indexing changes " + e, e);
- }
- catch (IOException e)
- {
- log.error("Error indexing changes " + e, e);
- try
- {
- handler.logErrorChanges(removedNodes, addedNodes);
- }
- catch (IOException ioe)
- {
- log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
- }
- }
- }
- // pass lists to parent search manager
- if (parentSearchManager != null && (parentAddedNodes.size() > 0 || parentRemovedNodes.size() > 0))
- {
- try
- {
- parentSearchManager.updateIndex(parentRemovedNodes, parentAddedNodes);
- }
- catch (RepositoryException e)
- {
- log.error("Error indexing changes " + e, e);
- }
- catch (IOException e)
- {
- log.error("Error indexing changes " + e, e);
- try
- {
- parentHandler.logErrorChanges(parentRemovedNodes, parentAddedNodes);
- }
- catch (IOException ioe)
- {
- log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
- }
- }
- }
- }
-
- /**
- * Flushes lists of added/removed nodes to SearchManagers, starting indexing.
- */
- protected void updateIndex(ChangesHolder changes, ChangesHolder parentChanges)
- {
- // pass lists to search manager
- if (searchManager != null && changes != null)
- {
- try
- {
- searchManager.apply(changes);
- }
- catch (RepositoryException e)
- {
- log.error("Error indexing changes " + e, e);
- }
- catch (IOException e)
- {
- log.error("Error indexing changes " + e, e);
- try
- {
- handler.logErrorChanges(new HashSet<String>(changes.getRemove()), new HashSet<String>(changes
- .getAddIds()));
- }
- catch (IOException ioe)
- {
- log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
- }
- }
- }
- // pass lists to parent search manager
- if (parentSearchManager != null && parentChanges != null)
- {
- try
- {
- parentSearchManager.apply(parentChanges);
- }
- catch (RepositoryException e)
- {
- log.error("Error indexing changes " + e, e);
- }
- catch (IOException e)
- {
- log.error("Error indexing changes " + e, e);
- try
- {
- parentHandler.logErrorChanges(new HashSet<String>(parentChanges.getRemove()), new HashSet<String>(
- parentChanges.getAddIds()));
- }
- catch (IOException ioe)
- {
- log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
- }
- }
- }
- }
- }
-
- @Override
- public void store(InternalCacheEntry entry) throws CacheLoaderException
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void fromStream(ObjectInput inputStream) throws CacheLoaderException
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void toStream(ObjectOutput outputStream) throws CacheLoaderException
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void clear() throws CacheLoaderException
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public boolean remove(Object key) throws CacheLoaderException
- {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public InternalCacheEntry load(Object key) throws CacheLoaderException
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Set<InternalCacheEntry> loadAll() throws CacheLoaderException
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Set<InternalCacheEntry> load(int numEntries) throws CacheLoaderException
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Set<Object> loadAllKeys(Set<Object> keysToExclude) throws CacheLoaderException
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Class<? extends CacheLoaderConfig> getConfigurationClass()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- protected void purgeInternal() throws CacheLoaderException
- {
- // TODO Auto-generated method stub
-
- }
-}
+/*
+ * Copyright (C) 2011 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.core.query.ispn;
+
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.impl.core.query.Indexer;
+import org.exoplatform.services.jcr.impl.core.query.IndexerIoMode;
+import org.exoplatform.services.jcr.impl.core.query.IndexerIoModeHandler;
+import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
+import org.exoplatform.services.jcr.impl.core.query.SearchManager;
+import org.exoplatform.services.jcr.impl.core.query.jbosscache.ChangesFilterListsWrapper;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.infinispan.Cache;
+import org.infinispan.container.entries.InternalCacheEntry;
+import org.infinispan.lifecycle.ComponentStatus;
+import org.infinispan.loaders.CacheLoaderConfig;
+import org.infinispan.loaders.CacheLoaderException;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.marshall.StreamingMarshaller;
+import org.infinispan.notifications.Listener;
+import org.infinispan.notifications.cachemanagerlistener.annotation.CacheStarted;
+import org.infinispan.notifications.cachemanagerlistener.annotation.ViewChanged;
+import org.infinispan.notifications.cachemanagerlistener.event.Event;
+import org.infinispan.notifications.cachemanagerlistener.event.ViewChangedEvent;
+import org.infinispan.remoting.transport.Address;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:nikolazius@gmail.com">Nikolay Zamosenchuk</a>
+ * @version $Id: IndexCacheLoader.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
+ *
+ */
+public class IndexerCacheStore extends AbstractInputCacheStore
+{
+
+ protected CacheListener listener;
+
+ /**
+ * Address instance that allows SingletonStore to find out whether it became the coordinator of the cluster, or
+ * whether it stopped being it. This dictates whether the SingletonStore is active or not.
+ */
+ private Address localAddress;
+
+ /**
+ * Whether the the current cache is the coordinator and therefore SingletonStore is active. Being active means
+ * delegating calls to the underlying cache loader.
+ */
+ private volatile boolean coordinator;
+
+ EmbeddedCacheManager cacheManager;
+
+ protected volatile IndexerIoModeHandler modeHandler;
+
+ /**
+ * A map of all the indexers that has been registered
+ */
+ private final Map<Integer, Indexer> indexers = new HashMap<Integer, Indexer>();
+
+ private static final Log log = ExoLogger.getLogger("exo.jcr.component.core.IndexerCacheLoader");
+
+ /**
+ * This method will register a new Indexer according to the given parameters.
+ *
+ * @param searchManager
+ * @param parentSearchManager
+ * @param handler
+ * @param parentHandler
+ * @throws RepositoryConfigurationException
+ */
+ public void register(SearchManager searchManager, SearchManager parentSearchManager, QueryHandler handler,
+ QueryHandler parentHandler) throws RepositoryConfigurationException
+ {
+ indexers.put(searchManager.getWsId().hashCode(), new Indexer(searchManager, parentSearchManager, handler,
+ parentHandler));
+ if (log.isDebugEnabled())
+ {
+ log.debug("Register " + searchManager.getWsId() + " " + this + " in " + indexers);
+ }
+ }
+
+ @Override
+ public void init(CacheLoaderConfig config, Cache<?, ?> cache, StreamingMarshaller m) throws CacheLoaderException
+ {
+ super.init(config, cache, m);
+ this.cacheManager = cache == null ? null : (EmbeddedCacheManager)cache.getCacheManager();
+ listener = new CacheListener();
+ cache.addListener(listener);
+ }
+
+ /**
+ * @see org.infinispan.loaders.CacheStore#store(org.infinispan.container.entries.InternalCacheEntry)
+ */
+ public void store(InternalCacheEntry entry) throws CacheLoaderException
+ {
+ if (entry.getValue() instanceof ChangesFilterListsWrapper && entry.getKey() instanceof ChangesKey)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.info("Received list wrapper, start indexing...");
+ }
+ // updating index
+ ChangesFilterListsWrapper wrapper = (ChangesFilterListsWrapper)entry.getValue();
+ ChangesKey key = (ChangesKey)entry.getKey();
+ try
+ {
+ Indexer indexer = indexers.get(key.getWsId());
+ if (indexer == null)
+ {
+ log.warn("No indexer could be found for the cache entry " + key.toString());
+ if (log.isDebugEnabled())
+ {
+ log.debug("The current content of the map of indexers is " + indexers);
+ }
+ }
+ else if (wrapper.withChanges())
+ {
+ indexer.updateIndex(wrapper.getChanges(), wrapper.getParentChanges());
+ }
+ else
+ {
+ indexer.updateIndex(wrapper.getAddedNodes(), wrapper.getRemovedNodes(), wrapper.getParentAddedNodes(),
+ wrapper.getParentRemovedNodes());
+ }
+ }
+ finally
+ {
+ if (modeHandler.getMode() == IndexerIoMode.READ_WRITE)
+ {
+ // remove the data from the cache
+ cache.remove(key);
+ }
+ }
+ }
+ }
+
+ /**
+ * Set the mode handler
+ * @param modeHandler
+ */
+ IndexerIoModeHandler getModeHandler()
+ {
+ if (modeHandler == null)
+ {
+
+ if (cache.getStatus() != ComponentStatus.RUNNING)
+ {
+ throw new IllegalStateException("The cache should be started first");
+ }
+ synchronized (this)
+ {
+ if (modeHandler == null)
+ {
+ this.modeHandler =
+ new IndexerIoModeHandler(cacheManager.isCoordinator() ? IndexerIoMode.READ_WRITE
+ : IndexerIoMode.READ_ONLY);
+ }
+ }
+ }
+ return modeHandler;
+ }
+
+ /**
+ * Indicates whether the current cache is the coordinator of the cluster. This implementation assumes that the
+ * coordinator is the first member in the list.
+ *
+ * @param newView View instance containing the new view of the cluster
+ * @return whether the current cache is the coordinator or not.
+ */
+ private boolean isCoordinator(List<Address> newView, Address currentAddress)
+ {
+ if (!currentAddress.equals(localAddress))
+ {
+ localAddress = currentAddress;
+ }
+ if (localAddress != null)
+ {
+ return !newView.isEmpty() && localAddress.equals(newView.get(0));
+ }
+ else
+ {
+ /* Invalid new view, so previous value returned */
+ return coordinator;
+ }
+ }
+
+ /**
+ * Method called when the cache either becomes the coordinator or stops being the coordinator. If it becomes the
+ * coordinator, it can optionally start the in-memory state transfer to the underlying cache store.
+ *
+ * @param newActiveState true if the cache just became the coordinator, false if the cache stopped being the
+ * coordinator.
+ */
+ protected void activeStatusChanged(boolean newActiveState)
+ {
+ coordinator = newActiveState;
+
+ if (modeHandler != null)
+ {
+ modeHandler.setMode(coordinator ? IndexerIoMode.READ_WRITE : IndexerIoMode.READ_ONLY);
+ log.info("Set indexer io mode to:" + (coordinator ? IndexerIoMode.READ_WRITE : IndexerIoMode.READ_ONLY));
+ }
+
+ if (coordinator)
+ {
+ doPushState();
+ }
+ }
+
+ protected void doPushState()
+ {
+ // final boolean debugEnabled = log.isDebugEnabled();
+ //
+ // if (debugEnabled)
+ // {
+ // log.debug("start pushing in-memory state to cache cacheLoader collection");
+ // }
+ //
+ // // merging all lists stored in memory
+ // Collection<NodeSPI> children = cache.getRoot().getChildren();
+ // for (NodeSPI wsChildren : children)
+ // {
+ // final Set<String> removedNodes = new HashSet<String>();
+ // final Set<String> addedNodes = new HashSet<String>();
+ // final Set<String> parentRemovedNodes = new HashSet<String>();
+ // final Set<String> parentAddedNodes = new HashSet<String>();
+ // Collection<NodeSPI> changes = wsChildren.getChildren();
+ // for (NodeSPI aChildren : changes)
+ // {
+ // Fqn<?> fqn = aChildren.getFqn();
+ // Object value = cache.get(fqn, JBossCacheIndexChangesFilter.LISTWRAPPER);
+ // if (value instanceof ChangesFilterListsWrapper)
+ // {
+ // // get wrapper object
+ // ChangesFilterListsWrapper listsWrapper = (ChangesFilterListsWrapper)value;
+ // if (listsWrapper.withChanges())
+ // {
+ // if (listsWrapper.getChanges() != null)
+ // {
+ // // get search manager lists
+ // addedNodes.addAll(listsWrapper.getChanges().getAddIds());
+ // removedNodes.addAll(listsWrapper.getChanges().getRemove());
+ // }
+ // if (listsWrapper.getParentChanges() != null)
+ // {
+ // // parent search manager lists
+ // parentAddedNodes.addAll(listsWrapper.getParentChanges().getAddIds());
+ // parentRemovedNodes.addAll(listsWrapper.getParentChanges().getRemove());
+ // }
+ // }
+ // else
+ // {
+ // // get search manager lists
+ // addedNodes.addAll(listsWrapper.getAddedNodes());
+ // removedNodes.addAll(listsWrapper.getRemovedNodes());
+ // // parent search manager lists
+ // parentAddedNodes.addAll(listsWrapper.getParentAddedNodes());
+ // parentRemovedNodes.addAll(listsWrapper.getParentAddedNodes());
+ // }
+ // }
+ // }
+ // String id = IdGenerator.generate();
+ // cache.put(Fqn.fromRelativeElements(wsChildren.getFqn(), id), JBossCacheIndexChangesFilter.LISTWRAPPER,
+ // new ChangesFilterListsWrapper(addedNodes, removedNodes, parentAddedNodes, parentRemovedNodes));
+ // // Once we put the merged changes into the cache we can remove other changes from the cache
+ // for (NodeSPI aChildren : children)
+ // {
+ // // Remove the node from the cache and do it asynchronously
+ // cache.getInvocationContext().getOptionOverrides().setForceAsynchronous(true);
+ // cache.removeNode(aChildren.getFqn());
+ // }
+ // }
+ // if (debugEnabled)
+ // {
+ // log.debug("in-memory state passed to cache cacheLoader successfully");
+ // }
+ // return null;
+ }
+
+ @Listener
+ public class CacheListener
+ {
+ @CacheStarted
+ public void cacheStarted(Event e)
+ {
+ localAddress = cacheManager.getAddress();
+ coordinator = cacheManager.isCoordinator();
+ }
+
+ /**
+ * The cluster formation changed, so determine whether the current cache stopped being the coordinator or became
+ * the coordinator. This method can lead to an optional in memory to cache loader state push, if the current cache
+ * became the coordinator. This method will report any issues that could potentially arise from this push.
+ */
+ @ViewChanged
+ public void viewChange(ViewChangedEvent event)
+ {
+ boolean tmp = isCoordinator(event.getNewMembers(), event.getLocalAddress());
+
+ if (coordinator != tmp)
+ {
+ activeStatusChanged(tmp);
+ }
+ }
+ }
+
+}
Added: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/LocalIndexChangesFilter.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/LocalIndexChangesFilter.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/LocalIndexChangesFilter.java 2011-02-25 10:29:18 UTC (rev 4017)
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2009 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.core.query.ispn;
+
+import org.exoplatform.container.configuration.ConfigurationManager;
+import org.exoplatform.services.jcr.config.QueryHandlerEntry;
+import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.impl.core.query.IndexerChangesFilter;
+import org.exoplatform.services.jcr.impl.core.query.IndexerIoModeHandler;
+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.core.query.jbosscache.ChangesFilterListsWrapper;
+import org.exoplatform.services.jcr.impl.core.query.lucene.ChangesHolder;
+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;
+import org.infinispan.Cache;
+import org.infinispan.CacheException;
+import org.infinispan.loaders.CacheLoaderManager;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Set;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * This type of ChangeFilter offers an ability for each cluster instance to have own
+ * local index (stack of indexes, from persistent to volatile). It uses ISPN cache for
+ * Lucene Documents and UUIDs delivery. Each node works in ReadWrite mode, so manages
+ * it own volatile, merger, local list of persisted indexes and stand-alone
+ * UpdateInProgressMonitor implementation.
+ * This implementation is similar to ISPNIndexChangesFilter but does not use
+ * ISPNIndexInfoss and ISPNIndexUpdateMonitor classes.
+ *
+ * @author <a href="mailto:anatoliy.bazko@gmail.com">Anatoliy Bazko</a>
+ * @version $Id: LocalIndexChangesFilter.java 34360 2009-07-22 23:58:59Z tolusha $
+ */
+public class LocalIndexChangesFilter extends IndexerChangesFilter
+{
+ /**
+ * Logger instance for this class
+ */
+ private final Log log = ExoLogger.getLogger("exo.jcr.component.core.LocalIndexChangesFilter");
+
+ private final Cache<Serializable, Object> cache;
+
+ private final int wsId;
+
+ /**
+ * LocalIndexChangesFilter constructor.
+ */
+ public LocalIndexChangesFilter(SearchManager searchManager, SearchManager parentSearchManager,
+ QueryHandlerEntry config, IndexingTree indexingTree, IndexingTree parentIndexingTree, QueryHandler handler,
+ QueryHandler parentHandler, ConfigurationManager cfm) throws IOException, RepositoryException,
+ RepositoryConfigurationException
+ {
+ super(searchManager, parentSearchManager, config, indexingTree, parentIndexingTree, handler, parentHandler, cfm);
+
+ this.wsId = searchManager.getWsId().hashCode();
+
+ ISPNCacheFactory<Serializable, Object> factory = new ISPNCacheFactory<Serializable, Object>(cfm);
+ this.cache = factory.createCache("Indexer-" + searchManager.getWsId(), config);
+
+ CacheLoaderManager cacheLoaderManager =
+ cache.getAdvancedCache().getComponentRegistry().getComponent(CacheLoaderManager.class);
+ IndexerCacheStore cacheStore = (IndexerCacheStore)cacheLoaderManager.getCacheLoader();
+
+ cacheStore.register(searchManager, parentSearchManager, handler, parentHandler);
+ IndexerIoModeHandler modeHandler = cacheStore.getModeHandler();
+ handler.setIndexerIoModeHandler(modeHandler);
+ parentHandler.setIndexerIoModeHandler(modeHandler);
+
+ // using default updateMonitor and default
+ if (!parentHandler.isInitialized())
+ {
+ parentHandler.init();
+ }
+ if (!handler.isInitialized())
+ {
+ handler.init();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void doUpdateIndex(Set<String> removedNodes, Set<String> addedNodes, Set<String> parentRemovedNodes,
+ Set<String> parentAddedNodes)
+ {
+
+ ChangesHolder changes = searchManager.getChanges(removedNodes, addedNodes);
+ ChangesHolder parentChanges = parentSearchManager.getChanges(parentRemovedNodes, parentAddedNodes);
+
+ if (changes == null && parentChanges == null)
+ {
+ return;
+ }
+
+ ChangesKey changesKey = new ChangesKey(wsId, IdGenerator.generate());
+ try
+ {
+ PrivilegedISPNCacheHelper.put(cache, changesKey, new ChangesFilterListsWrapper(changes, parentChanges));
+ }
+ catch (CacheException e)
+ {
+ log.error(e.getLocalizedMessage(), e);
+ logErrorChanges(handler, removedNodes, addedNodes);
+ logErrorChanges(parentHandler, parentRemovedNodes, parentAddedNodes);
+ }
+ }
+
+ /**
+ * Log errors.
+ *
+ * @param logHandler
+ * @param removedNodes
+ * @param addedNodes
+ */
+ private void logErrorChanges(QueryHandler logHandler, Set<String> removedNodes, Set<String> addedNodes)
+ {
+ try
+ {
+ logHandler.logErrorChanges(addedNodes, removedNodes);
+ }
+ catch (IOException ioe)
+ {
+ log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
+ }
+ }
+}
Property changes on: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ispn/LocalIndexChangesFilter.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java 2011-02-25 08:27:21 UTC (rev 4016)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java 2011-02-25 10:29:18 UTC (rev 4017)
@@ -17,11 +17,11 @@
package org.exoplatform.services.jcr.impl.core.query.jbosscache;
import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.impl.core.query.Indexer;
import org.exoplatform.services.jcr.impl.core.query.IndexerIoMode;
import org.exoplatform.services.jcr.impl.core.query.IndexerIoModeHandler;
import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
import org.exoplatform.services.jcr.impl.core.query.SearchManager;
-import org.exoplatform.services.jcr.impl.core.query.lucene.ChangesHolder;
import org.exoplatform.services.jcr.impl.storage.jbosscache.AbstractWriteOnlyCacheLoader;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -29,15 +29,10 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
-import java.io.IOException;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
-import javax.jcr.RepositoryException;
-
/**
* @author <a href="mailto:nikolazius@gmail.com">Nikolay Zamosenchuk</a>
* @version $Id: IndexerCacheLoader.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
@@ -191,146 +186,4 @@
}
return modeHandler;
}
-
- /**
- * This class will update the indexes of the related workspace
- */
- private static class Indexer
- {
-
- private final SearchManager searchManager;
-
- private final SearchManager parentSearchManager;
-
- private final QueryHandler handler;
-
- private final QueryHandler parentHandler;
-
- public Indexer(SearchManager searchManager, SearchManager parentSearchManager, QueryHandler handler,
- QueryHandler parentHandler) throws RepositoryConfigurationException
- {
- this.searchManager = searchManager;
- this.parentSearchManager = parentSearchManager;
- this.handler = handler;
- this.parentHandler = parentHandler;
- }
-
- /**
- * Flushes lists of added/removed nodes to SearchManagers, starting indexing.
- *
- * @param addedNodes
- * @param removedNodes
- * @param parentAddedNodes
- * @param parentRemovedNodes
- */
- protected void updateIndex(Set<String> addedNodes, Set<String> removedNodes, Set<String> parentAddedNodes,
- Set<String> parentRemovedNodes)
- {
- // pass lists to search manager
- if (searchManager != null && (addedNodes.size() > 0 || removedNodes.size() > 0))
- {
- try
- {
- searchManager.updateIndex(removedNodes, addedNodes);
- }
- catch (RepositoryException e)
- {
- log.error("Error indexing changes " + e, e);
- }
- catch (IOException e)
- {
- log.error("Error indexing changes " + e, e);
- try
- {
- handler.logErrorChanges(removedNodes, addedNodes);
- }
- catch (IOException ioe)
- {
- log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
- }
- }
- }
- // pass lists to parent search manager
- if (parentSearchManager != null && (parentAddedNodes.size() > 0 || parentRemovedNodes.size() > 0))
- {
- try
- {
- parentSearchManager.updateIndex(parentRemovedNodes, parentAddedNodes);
- }
- catch (RepositoryException e)
- {
- log.error("Error indexing changes " + e, e);
- }
- catch (IOException e)
- {
- log.error("Error indexing changes " + e, e);
- try
- {
- parentHandler.logErrorChanges(parentRemovedNodes, parentAddedNodes);
- }
- catch (IOException ioe)
- {
- log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
- }
- }
- }
- }
-
- /**
- * Flushes lists of added/removed nodes to SearchManagers, starting indexing.
- */
- protected void updateIndex(ChangesHolder changes, ChangesHolder parentChanges)
- {
- // pass lists to search manager
- if (searchManager != null && changes != null)
- {
- try
- {
- searchManager.apply(changes);
- }
- catch (RepositoryException e)
- {
- log.error("Error indexing changes " + e, e);
- }
- catch (IOException e)
- {
- log.error("Error indexing changes " + e, e);
- try
- {
- handler.logErrorChanges(new HashSet<String>(changes.getRemove()), new HashSet<String>(changes
- .getAddIds()));
- }
- catch (IOException ioe)
- {
- log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
- }
- }
- }
- // pass lists to parent search manager
- if (parentSearchManager != null && parentChanges != null)
- {
- try
- {
- parentSearchManager.apply(parentChanges);
- }
- catch (RepositoryException e)
- {
- log.error("Error indexing changes " + e, e);
- }
- catch (IOException e)
- {
- log.error("Error indexing changes " + e, e);
- try
- {
- parentHandler.logErrorChanges(new HashSet<String>(parentChanges.getRemove()), new HashSet<String>(
- parentChanges.getAddIds()));
- }
- catch (IOException ioe)
- {
- log.warn("Exception occure when errorLog writed. Error log is not complete. " + ioe, ioe);
- }
- }
- }
- }
- }
}
13 years, 2 months
exo-jcr SVN: r4016 - jcr/branches/1.12.x/patch/1.12.8-GA/JCR-1584.
by do-not-reply@jboss.org
Author: paristote
Date: 2011-02-25 03:27:21 -0500 (Fri, 25 Feb 2011)
New Revision: 4016
Modified:
jcr/branches/1.12.x/patch/1.12.8-GA/JCR-1584/readme.txt
Log:
JCR-1584 update the readme
Modified: jcr/branches/1.12.x/patch/1.12.8-GA/JCR-1584/readme.txt
===================================================================
--- jcr/branches/1.12.x/patch/1.12.8-GA/JCR-1584/readme.txt 2011-02-25 03:02:49 UTC (rev 4015)
+++ jcr/branches/1.12.x/patch/1.12.8-GA/JCR-1584/readme.txt 2011-02-25 08:27:21 UTC (rev 4016)
@@ -9,40 +9,40 @@
Problem description
What is the problem to fix?
+ConstraintViolationException when Importing Version history of an nt:folder node having an nt:file child node.
+Steps to reproduce:
- * SysViewImporter tests nt:versionedChild nodes - does it allowed as child for nt:folder node. This is incorrevt, since nt:versionedChild allowed in any place below frozen node.
- * SystemViewStreamExporter exports pure nodes Version history. It is correct. But there is problem when we import version history of node, that have versionable subnode. And remove this node tree after export. In this case version history of versioned subnode will be lost.
+ 1. Create a web content named for example wc1
+ 2. Under wc1/medias/images add a node of type nt:file (upload an image for example IMG_0374.JPG)
+ 3. Create many versions of this document
+ 4. Export wc1 with its version history in the system view format
+ 5. Stop the server,clean the database and start the server again
+ 6. Import wc1 with its version history
+ In console, there is a ConstraintViolationException.
Fix description
+Problem analysis
+The issue comes from the export data process, there is something wrong with the exported data:
+
+ * Before exporting, the primary type of "IMG_0374.JPG" node is nt:file. After exporting, it becomes nt:versionedChild
+ * In importing process, because nt:versionedChild node type is not allowed as child's node type for parent node type (nt:folder) so nodeTypeDataManager.isChildNodePrimaryTypeAllowed() function returns false and an ConstraintViolationException is thrown.
+
+Root cause: SysViewImporter tests nt:versionedChild nodes whether it is allowed as child for nt:folder node. This is incorrect, since nt:versionedChild is allowed in any place below frozen node.
+
How is the problem fixed?
* In case if exported node is nt:versionableChild and it is a descendant of frozen node - there is no child node primary type validation.
- * SystemViewStreamExporter exports versioned subnodes version history as sv:versionedChild structure into <sv:node>nt:verstionedChild</sv:node>
- * SysViewImporter imports all version histories in <sv:versionedChild> tags, and stores these version UUIDs in Context as "importedSubversions"-named list.
- * VersionHistoryImporter uses this list to update versionable child node properties (versionHistory, baseVerasion, predecessors) with actual values.
Patch information:
-Patch files: JCR-1584.patch
+Patch files: JCR-1584.patch
Tests to perform
Reproduction test
- * Steps to reproduce:
- 1)Create a web content named for example wc1
- 2)Under wc1/medias/images add a node of type nt:file(upload an image for example IMG_0374.JPG)
- 3)Create many version of this document
- 3)Export wc1 with its version history in the system view format
- 4)Stop the server,clean the database and start the server again
- 5)Import wc1 with its version history
- In console, you will get a ConstraintViolationException
+ * Cf. above
-After investigation, the root cause comes from the export data process, there is something wrong with the exported data (the attached image shows it):
-
- * Before exporting, the primary type of "IMG_0374.JPG" node is nt:file. After exporting, it becomes nt:versionedChild
- * In importing process, because nt:versionedChild node type is not allowed as child's node type for parent node type (nt:folder) so nodeTypeDataManager.isChildNodePrimaryTypeAllowed() function returns false and an ConstraintViolationException is throwed
-
Tests performed at DevLevel
* Patch contains TestImportVersionedChild
@@ -70,11 +70,11 @@
Can this bug fix have any side effects on current client projects?
- * SysViewExporter class has new constructor with additional parameter.
+ * no
Is there a performance risk/cost?
- * Yes. There are additional validations. Also export/import of big nodes tree with many versionable nodes may take more time.
+ * Yes. There are additional validations at import.
Validation (PM/Support/QA)
@@ -86,4 +86,5 @@
QA Feedbacks
*
+Labels parameters
13 years, 2 months
exo-jcr SVN: r4015 - in jcr/branches/1.12.x: exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing and 1 other directories.
by do-not-reply@jboss.org
Author: paristote
Date: 2011-02-24 22:02:49 -0500 (Thu, 24 Feb 2011)
New Revision: 4015
Added:
jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/TestImportVersionedChild.java
jcr/branches/1.12.x/patch/1.12.8-GA/JCR-1584/readme.txt
Modified:
jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/SystemViewImporter.java
Log:
JCR-1584
What is the problem to fix?
* SysViewImporter tests nt:versionedChild nodes - does it allowed as child for nt:folder node. This is incorrevt, since nt:versionedChild allowed in any place below frozen node.
* SystemViewStreamExporter exports pure nodes Version history. It is correct. But there is problem when we import version history of node, that have versionable subnode. And remove this node tree after export. In this case version history of versioned subnode will be lost.
How is the problem fixed?
* In case if exported node is nt:versionableChild and it is a descendant of frozen node - there is no child node primary type validation.
* SystemViewStreamExporter exports versioned subnodes version history as sv:versionedChild structure into <sv:node>nt:verstionedChild</sv:node>
* SysViewImporter imports all version histories in <sv:versionedChild> tags, and stores these version UUIDs in Context as "importedSubversions"-named list.
* VersionHistoryImporter uses this list to update versionable child node properties (versionHistory, baseVerasion, predecessors) with actual values.
Modified: jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/SystemViewImporter.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/SystemViewImporter.java 2011-02-25 02:48:27 UTC (rev 4014)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/importing/SystemViewImporter.java 2011-02-25 03:02:49 UTC (rev 4015)
@@ -418,9 +418,16 @@
{
NodeData parentNodeData = getParent();
// nodeTypeDataManager.findChildNodeDefinition(primaryTypeName,)
- if (!nodeTypeDataManager.isChildNodePrimaryTypeAllowed(primaryTypeName, parentNodeData.getPrimaryTypeName(),
- parentNodeData.getMixinTypeNames()))
+
+ // check is nt:versionedChild subnode of frozenNode
+ if (nodeData.getQPath().getDepth() > 6 && primaryTypeName.equals(Constants.NT_VERSIONEDCHILD)
+ && nodeData.getQPath().getEntries()[5].equals(Constants.JCR_FROZENNODE))
{
+ //do nothing
+ }
+ else if (!nodeTypeDataManager.isChildNodePrimaryTypeAllowed(primaryTypeName, parentNodeData
+ .getPrimaryTypeName(), parentNodeData.getMixinTypeNames()))
+ {
throw new ConstraintViolationException("Can't add node " + nodeData.getQName().getAsString() + " to "
+ parentNodeData.getQPath().getAsString() + " node type " + sName
+ " is not allowed as child's node type for parent node type "
Added: jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/TestImportVersionedChild.java
===================================================================
--- jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/TestImportVersionedChild.java (rev 0)
+++ jcr/branches/1.12.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/TestImportVersionedChild.java 2011-02-25 03:02:49 UTC (rev 4015)
@@ -0,0 +1,278 @@
+/*
+ * Copyright (C) 2003-2011 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.services.jcr.api.importing;
+
+import org.exoplatform.commons.utils.MimeTypeResolver;
+import org.exoplatform.services.jcr.JcrAPIBaseTest;
+import org.exoplatform.services.jcr.dataflow.ItemState;
+import org.exoplatform.services.jcr.dataflow.PlainChangesLog;
+import org.exoplatform.services.jcr.dataflow.PlainChangesLogImpl;
+import org.exoplatform.services.jcr.impl.core.NodeImpl;
+import org.exoplatform.services.jcr.impl.core.PropertyImpl;
+import org.exoplatform.services.jcr.impl.core.SessionDataManager;
+import org.exoplatform.services.jcr.util.VersionHistoryImporter;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.Calendar;
+
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>Date:
+ *
+ * @author <a href="karpenko.sergiy(a)gmail.com">Karpenko Sergiy</a>
+ * @version $Id: TestImportImage.java 111 2008-11-11 11:11:11Z serg $
+ */
+public class TestImportVersionedChild extends JcrAPIBaseTest
+{
+
+ Node testRoot;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ testRoot = this.root.addNode("parent", "nt:folder");
+ root.save();
+ }
+
+ public void tearDown() throws Exception
+ {
+ testRoot.remove();
+ root.save();
+ super.tearDown();
+ }
+
+ protected void loadTestTree() throws Exception
+ {
+ // wc1/medias/picture
+ Node wc1 = testRoot.addNode("wc1", "nt:folder");
+ wc1.addMixin("mix:versionable");
+ testRoot.save();
+ Node medias = wc1.addNode("medias", "nt:folder");
+
+ Node picture = medias.addNode("picture", "nt:file");
+ picture.addMixin("mix:versionable");
+
+ Node res = picture.addNode("jcr:content", "nt:resource");
+ res.setProperty("jcr:lastModified", Calendar.getInstance());
+ res.setProperty("jcr:data", new ByteArrayInputStream("bla bla".getBytes()));
+ MimeTypeResolver mimres = new MimeTypeResolver();
+ res.setProperty("jcr:mimeType", mimres.getMimeType("screen.txt"));
+ root.save();
+ }
+
+ public void testImportVersionHistoryPreloadChildVersionHistory() throws Exception
+ {
+ loadTestTree();
+ Node wc1 = (NodeImpl)session.getItem("/parent/wc1");
+ Node picture = (NodeImpl)session.getItem("/parent/wc1/medias/picture");
+
+ // make checkin/checkout a lot
+
+ wc1.checkin();
+ wc1.checkout();
+
+ picture.checkin();
+ picture.checkout();
+
+ // export import version history and node
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ session.exportSystemView("/parent/wc1", out, false, false);
+
+ ByteArrayOutputStream childvhout = new ByteArrayOutputStream();
+ session.exportSystemView(picture.getVersionHistory().getPath(), childvhout, false, false);
+
+ ByteArrayOutputStream vhout = new ByteArrayOutputStream();
+ session.exportSystemView(wc1.getVersionHistory().getPath(), vhout, false, false);
+
+ // prepare data for version import
+
+ String versionHistory = wc1.getProperty("jcr:versionHistory").getValue().getString();
+ String baseVersion = wc1.getProperty("jcr:baseVersion").getValue().getString();
+ Value[] jcrPredecessors = wc1.getProperty("jcr:predecessors").getValues();
+ StringBuilder jcrPredecessorsBuilder = new StringBuilder();
+ String[] predecessorsHistory;
+ for (Value value : jcrPredecessors)
+ {
+ if (jcrPredecessorsBuilder.length() > 0)
+ jcrPredecessorsBuilder.append(",");
+ jcrPredecessorsBuilder.append(value.getString());
+ }
+ if (jcrPredecessorsBuilder.toString().indexOf(",") > -1)
+ {
+ predecessorsHistory = jcrPredecessorsBuilder.toString().split(",");
+ }
+ else
+ {
+ predecessorsHistory = new String[]{jcrPredecessorsBuilder.toString()};
+ }
+
+ // prepare data for child version import
+
+ String chversionHistory = picture.getProperty("jcr:versionHistory").getValue().getString();
+ String chbaseVersion = picture.getProperty("jcr:baseVersion").getValue().getString();
+ Value[] chjcrPredecessors = picture.getProperty("jcr:predecessors").getValues();
+ StringBuilder chjcrPredecessorsBuilder = new StringBuilder();
+ String[] chpredecessorsHistory;
+ for (Value value : chjcrPredecessors)
+ {
+ if (chjcrPredecessorsBuilder.length() > 0)
+ chjcrPredecessorsBuilder.append(",");
+ chjcrPredecessorsBuilder.append(value.getString());
+ }
+ if (chjcrPredecessorsBuilder.toString().indexOf(",") > -1)
+ {
+ chpredecessorsHistory = chjcrPredecessorsBuilder.toString().split(",");
+ }
+ else
+ {
+ chpredecessorsHistory = new String[]{chjcrPredecessorsBuilder.toString()};
+ }
+
+ // remove node
+ wc1.remove();
+ session.save();
+
+ out.close();
+ vhout.close();
+
+ // import
+ session.importXML("/parent", new ByteArrayInputStream(out.toByteArray()),
+ ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, true);
+
+ session.save();
+
+ wc1 = (NodeImpl)session.getItem("/parent/wc1");
+ picture = wc1.getNode("medias").getNode("picture");
+
+ VersionHistoryImporter chversionHistoryImporter =
+ new VersionHistoryImporter((NodeImpl)picture, new ByteArrayInputStream(childvhout.toByteArray()),
+ chbaseVersion, chpredecessorsHistory, chversionHistory);
+ chversionHistoryImporter.doImport();
+ session.save();
+
+ VersionHistoryImporter versionHistoryImporter =
+ new VersionHistoryImporter((NodeImpl)wc1, new ByteArrayInputStream(vhout.toByteArray()), baseVersion,
+ predecessorsHistory, versionHistory);
+ versionHistoryImporter.doImport();
+ session.save();
+
+ assertTrue(picture.isNodeType("mix:versionable"));
+ assertEquals(chversionHistory, picture.getProperty("jcr:versionHistory").getValue().getString());
+ assertEquals(chbaseVersion, picture.getProperty("jcr:baseVersion").getValue().getString());
+ assertEquals(chpredecessorsHistory[0], picture.getProperty("jcr:predecessors").getValues()[0].getString());
+ }
+
+ public void testImportVersionHistory() throws Exception
+ {
+ loadTestTree();
+ Node wc1 = (NodeImpl)session.getItem("/parent/wc1");
+
+ // make checkin/checkout
+ wc1.checkin();
+ wc1.checkout();
+
+ // export import version history and node
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ session.exportSystemView("/parent/wc1", out, false, false);
+
+ ByteArrayOutputStream vhout = new ByteArrayOutputStream();
+ session.exportSystemView(wc1.getVersionHistory().getPath(), vhout, false, false);
+
+ // prepare data for version import
+ String versionHistory = wc1.getProperty("jcr:versionHistory").getValue().getString();
+ String baseVersion = wc1.getProperty("jcr:baseVersion").getValue().getString();
+ Value[] jcrPredecessors = wc1.getProperty("jcr:predecessors").getValues();
+ StringBuilder jcrPredecessorsBuilder = new StringBuilder();
+ String[] predecessorsHistory;
+ for (Value value : jcrPredecessors)
+ {
+ if (jcrPredecessorsBuilder.length() > 0)
+ jcrPredecessorsBuilder.append(",");
+ jcrPredecessorsBuilder.append(value.getString());
+ }
+ if (jcrPredecessorsBuilder.toString().indexOf(",") > -1)
+ {
+ predecessorsHistory = jcrPredecessorsBuilder.toString().split(",");
+ }
+ else
+ {
+ predecessorsHistory = new String[]{jcrPredecessorsBuilder.toString()};
+ }
+
+ // remove node
+ wc1.remove();
+ session.save();
+
+ out.close();
+ vhout.close();
+
+ // import
+ session.importXML("/parent", new ByteArrayInputStream(out.toByteArray()),
+ ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, true);
+
+ session.save();
+
+ wc1 = (NodeImpl)session.getItem("/parent/wc1");
+
+ VersionHistoryImporter versionHistoryImporter =
+ new VersionHistoryImporter((NodeImpl)wc1, new ByteArrayInputStream(vhout.toByteArray()), baseVersion,
+ predecessorsHistory, versionHistory);
+ versionHistoryImporter.doImport();
+ session.save();
+
+ Node picture = wc1.getNode("medias").getNode("picture");
+ assertTrue(picture.isNodeType("mix:versionable"));
+
+ //try to remove wc1, there must be RepositoryException
+ try
+ {
+ wc1.remove();
+ session.save();
+ fail();
+ }
+ catch (RepositoryException e)
+ {
+ // OK - wc1 Version History contain nt:versionedChild with link to non exist Version history
+
+ // remove bugy version history
+ SessionDataManager dataManager = session.getTransientNodesManager();
+ NodeImpl vhPicture =
+ (NodeImpl)session.getItem("/jcr:system/jcr:versionStorage/" + versionHistory
+ + "/1/jcr:frozenNode/medias/picture");
+
+ assertTrue(vhPicture.isNodeType("nt:versionedChild"));
+
+ PlainChangesLog changesLogDelete = new PlainChangesLogImpl();
+ changesLogDelete.add(ItemState.createDeletedState(((PropertyImpl)vhPicture.getProperty("jcr:primaryType"))
+ .getData()));
+ changesLogDelete.add(ItemState.createDeletedState(((PropertyImpl)vhPicture
+ .getProperty("jcr:childVersionHistory")).getData()));
+ for (ItemState itemState : changesLogDelete.getAllStates())
+ {
+ dataManager.delete(itemState.getData(), itemState.getAncestorToSave());
+ }
+ session.save();
+ }
+ }
+}
Added: jcr/branches/1.12.x/patch/1.12.8-GA/JCR-1584/readme.txt
===================================================================
--- jcr/branches/1.12.x/patch/1.12.8-GA/JCR-1584/readme.txt (rev 0)
+++ jcr/branches/1.12.x/patch/1.12.8-GA/JCR-1584/readme.txt 2011-02-25 03:02:49 UTC (rev 4015)
@@ -0,0 +1,89 @@
+Summary
+
+ * Status: ConstraintViolationException when Importing Version history of an nt:folder node having an nt:file child node
+ * CCP Issue: CCP-736, Product Jira Issue: JCR-1584
+ * Fixes: ECMS-1903
+ * Complexity: N/A
+
+The Proposal
+Problem description
+
+What is the problem to fix?
+
+ * SysViewImporter tests nt:versionedChild nodes - does it allowed as child for nt:folder node. This is incorrevt, since nt:versionedChild allowed in any place below frozen node.
+ * SystemViewStreamExporter exports pure nodes Version history. It is correct. But there is problem when we import version history of node, that have versionable subnode. And remove this node tree after export. In this case version history of versioned subnode will be lost.
+
+Fix description
+
+How is the problem fixed?
+
+ * In case if exported node is nt:versionableChild and it is a descendant of frozen node - there is no child node primary type validation.
+ * SystemViewStreamExporter exports versioned subnodes version history as sv:versionedChild structure into <sv:node>nt:verstionedChild</sv:node>
+ * SysViewImporter imports all version histories in <sv:versionedChild> tags, and stores these version UUIDs in Context as "importedSubversions"-named list.
+ * VersionHistoryImporter uses this list to update versionable child node properties (versionHistory, baseVerasion, predecessors) with actual values.
+
+Patch information:
+Patch files: JCR-1584.patch
+
+Tests to perform
+
+Reproduction test
+
+ * Steps to reproduce:
+ 1)Create a web content named for example wc1
+ 2)Under wc1/medias/images add a node of type nt:file(upload an image for example IMG_0374.JPG)
+ 3)Create many version of this document
+ 3)Export wc1 with its version history in the system view format
+ 4)Stop the server,clean the database and start the server again
+ 5)Import wc1 with its version history
+ In console, you will get a ConstraintViolationException
+
+After investigation, the root cause comes from the export data process, there is something wrong with the exported data (the attached image shows it):
+
+ * Before exporting, the primary type of "IMG_0374.JPG" node is nt:file. After exporting, it becomes nt:versionedChild
+ * In importing process, because nt:versionedChild node type is not allowed as child's node type for parent node type (nt:folder) so nodeTypeDataManager.isChildNodePrimaryTypeAllowed() function returns false and an ConstraintViolationException is throwed
+
+Tests performed at DevLevel
+
+ * Patch contains TestImportVersionedChild
+
+Tests performed at QA/Support Level
+*
+
+
+Documentation changes
+
+Documentation changes:
+ * none
+
+
+Configuration changes
+
+Configuration changes:
+ * none
+
+Will previous configuration continue to work?
+ * yes
+
+
+Risks and impacts
+
+Can this bug fix have any side effects on current client projects?
+
+ * SysViewExporter class has new constructor with additional parameter.
+
+Is there a performance risk/cost?
+
+ * Yes. There are additional validations. Also export/import of big nodes tree with many versionable nodes may take more time.
+
+Validation (PM/Support/QA)
+
+PM Comment
+* Patch approved by the PM
+
+Support Comment
+* Patch validated
+
+QA Feedbacks
+*
+
13 years, 2 months