[exo-jcr-commits] exo-jcr SVN: r942 - in jcr/branches/1.12.0-JBC/component/core/src: test/resources/conf/standalone and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Dec 8 05:38:30 EST 2009
Author: nzamosenchuk
Date: 2009-12-08 05:38:29 -0500 (Tue, 08 Dec 2009)
New Revision: 942
Added:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingletonStoreCacheLoader.java
Removed:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingleStoreCacheLoader.java
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java
jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jbosscache-indexer-config-exoloader_db1_ws.xml
Log:
EXOJCR-291: Indexer CacheLoader hierarchy updated to new cache usage scheme.
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java 2009-12-08 10:18:27 UTC (rev 941)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerCacheLoader.java 2009-12-08 10:38:29 UTC (rev 942)
@@ -38,16 +38,15 @@
{
private final Log log = ExoLogger.getLogger(this.getClass().getName());
- public static String ADDED = "$add".intern();
+ private SearchManager searchManager;
- public static String REMOVED = "$remove".intern();
+ private SearchManager parentSearchManager;
- private SearchManager searchManager;
-
- @Inject
- public void init(SearchManager searchManager) throws RepositoryConfigurationException
+ public void init(SearchManager searchManager, SearchManager parentSearchManager)
+ throws RepositoryConfigurationException
{
this.searchManager = searchManager;
+ this.parentSearchManager = parentSearchManager;
}
@Override
@@ -57,21 +56,32 @@
{
log.info("Received list of modifications");
}
+ final Set<String> addedNodes = new HashSet<String>();
final Set<String> removedNodes = new HashSet<String>();
- final Set<String> addedNodes = new HashSet<String>();
+
+ final Set<String> parentAddedNodes = new HashSet<String>();
+ final Set<String> parentRemovedNodes = new HashSet<String>();
for (Modification m : modifications)
{
if (m.getType() == ModificationType.PUT_KEY_VALUE && m.getFqn().size() == 1)
{
- if (m.getKey().equals(ADDED) && m.getValue() instanceof Set<?>)
+ if (m.getKey().equals(JbossCacheIndexChangesFilter.ADDED) && m.getValue() instanceof Set<?>)
{
addedNodes.addAll((Set<String>)m.getValue());
}
- else if (m.getKey().equals(REMOVED) && m.getValue() instanceof Set<?>)
+ else if (m.getKey().equals(JbossCacheIndexChangesFilter.REMOVED) && m.getValue() instanceof Set<?>)
{
removedNodes.addAll((Set<String>)m.getValue());
}
+ if (m.getKey().equals(JbossCacheIndexChangesFilter.PARENT_ADDED) && m.getValue() instanceof Set<?>)
+ {
+ parentAddedNodes.addAll((Set<String>)m.getValue());
+ }
+ else if (m.getKey().equals(JbossCacheIndexChangesFilter.PARENT_REMOVED) && m.getValue() instanceof Set<?>)
+ {
+ parentRemovedNodes.addAll((Set<String>)m.getValue());
+ }
}
else
{
@@ -82,10 +92,29 @@
}
}
new StubSearchManager().updateIndex(addedNodes, removedNodes);
- if (searchManager!=null)
+ if (searchManager != null)
{
- searchManager.updateIndex(removedNodes, addedNodes);
+ try
+ {
+ searchManager.updateIndex(removedNodes, addedNodes);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
}
+ if (parentSearchManager != null)
+ {
+ try
+ {
+ parentSearchManager.updateIndex(parentRemovedNodes, parentAddedNodes);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
}
class StubSearchManager
Deleted: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingleStoreCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingleStoreCacheLoader.java 2009-12-08 10:18:27 UTC (rev 941)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingleStoreCacheLoader.java 2009-12-08 10:38:29 UTC (rev 942)
@@ -1,101 +0,0 @@
-/*
- * 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.jbosscache;
-
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.NodeSPI;
-import org.jboss.cache.loader.SingletonStoreCacheLoader;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.Callable;
-
-/**
- * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
- * @version $Id: IndexerSingleStoraCacheLoader.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
- *
- */
-public class IndexerSingleStoreCacheLoader extends SingletonStoreCacheLoader
-{
-
- private final Log log = ExoLogger.getLogger(this.getClass().getName());
-
- @Override
- protected void activeStatusChanged(boolean newActiveState) throws PushStateException
- {
- // at first change indexer mode
- modeChanged(newActiveState);
- // and them push states if needed
- super.activeStatusChanged(newActiveState);
-
- }
-
- /**
- * Changes indexer mode RO->RW, RW->RO
- *
- * @param enableWrite
- * true when this node of cluster is coordinator, means that indexer is RW
- * false means that indexer is read only, and this node of cluster is no a coordinator
- */
- protected void modeChanged(boolean enableWrite)
- {
- }
-
- @Override
- protected Callable<?> createPushStateTask()
- {
- return new Callable()
- {
- public Object call() throws Exception
- {
- final boolean debugEnabled = log.isDebugEnabled();
-
- if (debugEnabled)
- log.debug("start pushing in-memory state to cache cacheLoader collection");
-
- final Set<String> removedNodes = new HashSet<String>();
- final Set<String> addedNodes = new HashSet<String>();
-
- // merging all lists stored in memory
- Collection<NodeSPI> children = cache.getRoot().getChildrenDirect();
- for (NodeSPI aChildren : children)
- {
- Fqn fqn = aChildren.getFqn();
- Object value = cache.get(fqn, IndexerCacheLoader.ADDED);
- if (value != null && value instanceof Set<?>)
- {
- addedNodes.addAll((Set<String>)value);
- };
- value = cache.get(fqn, IndexerCacheLoader.REMOVED);
- if (value != null && value instanceof Set<?>)
- {
- removedNodes.addAll((Set<String>)value);
- };
- }
- //TODO: recover logic is here, lists are: removedNodes and addedNodes
- if (debugEnabled)
- log.debug("in-memory state passed to cache cacheLoader successfully");
- return null;
- }
- };
- }
-}
Copied: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingletonStoreCacheLoader.java (from rev 936, jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingleStoreCacheLoader.java)
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingletonStoreCacheLoader.java (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/IndexerSingletonStoreCacheLoader.java 2009-12-08 10:38:29 UTC (rev 942)
@@ -0,0 +1,113 @@
+/*
+ * 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.jbosscache;
+
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.NodeSPI;
+import org.jboss.cache.loader.SingletonStoreCacheLoader;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.Callable;
+
+/**
+ * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
+ * @version $Id: IndexerSingleStoraCacheLoader.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
+ *
+ */
+public class IndexerSingletonStoreCacheLoader extends SingletonStoreCacheLoader
+{
+
+ private final Log log = ExoLogger.getLogger(this.getClass().getName());
+
+ @Override
+ protected void activeStatusChanged(boolean newActiveState) throws PushStateException
+ {
+ // at first change indexer mode
+ modeChanged(newActiveState);
+ // and them push states if needed
+ super.activeStatusChanged(newActiveState);
+
+ }
+
+ /**
+ * Changes indexer mode RO->RW, RW->RO
+ *
+ * @param enableWrite
+ * true when this node of cluster is coordinator, means that indexer is RW
+ * false means that indexer is read only, and this node of cluster is no a coordinator
+ */
+ protected void modeChanged(boolean enableWrite)
+ {
+ }
+
+ @Override
+ protected Callable<?> createPushStateTask()
+ {
+ return new Callable()
+ {
+ public Object call() throws Exception
+ {
+ final boolean debugEnabled = log.isDebugEnabled();
+
+ if (debugEnabled)
+ log.debug("start pushing in-memory state to cache cacheLoader collection");
+
+ 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>();
+ // merging all lists stored in memory
+ Collection<NodeSPI> children = cache.getRoot().getChildrenDirect();
+ for (NodeSPI aChildren : children)
+ {
+ Fqn fqn = aChildren.getFqn();
+ Object value = cache.get(fqn, JbossCacheIndexChangesFilter.ADDED);
+ if (value != null && value instanceof Set<?>)
+ {
+ addedNodes.addAll((Set<String>)value);
+ };
+ value = cache.get(fqn, JbossCacheIndexChangesFilter.REMOVED);
+ if (value != null && value instanceof Set<?>)
+ {
+ removedNodes.addAll((Set<String>)value);
+ };
+ value = cache.get(fqn, JbossCacheIndexChangesFilter.PARENT_ADDED);
+ if (value != null && value instanceof Set<?>)
+ {
+ parentAddedNodes.addAll((Set<String>)value);
+ };
+ value = cache.get(fqn, JbossCacheIndexChangesFilter.PARENT_REMOVED);
+ if (value != null && value instanceof Set<?>)
+ {
+ parentRemovedNodes.addAll((Set<String>)value);
+ };
+ }
+ //TODO: recover logic is here, lists are: removedNodes and addedNodes
+ if (debugEnabled)
+ log.debug("in-memory state passed to cache cacheLoader successfully");
+ return null;
+ }
+ };
+ }
+}
Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java 2009-12-08 10:18:27 UTC (rev 941)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java 2009-12-08 10:38:29 UTC (rev 942)
@@ -24,11 +24,16 @@
import org.exoplatform.services.jcr.impl.core.query.IndexerChangesFilter;
import org.exoplatform.services.jcr.impl.core.query.IndexingTree;
import org.exoplatform.services.jcr.impl.core.query.SearchManager;
+import org.exoplatform.services.jcr.util.IdGenerator;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.jboss.cache.Cache;
import org.jboss.cache.CacheFactory;
+import org.jboss.cache.CacheSPI;
import org.jboss.cache.DefaultCacheFactory;
+import org.jboss.cache.config.CacheLoaderConfig;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig.SingletonStoreConfig;
import java.io.Serializable;
import java.util.Set;
@@ -47,6 +52,14 @@
private final Cache<Serializable, Object> cache;
+ public static String ADDED = "$add".intern();
+
+ public static String REMOVED = "$remove".intern();
+
+ public static String PARENT_ADDED = "$padd".intern();
+
+ public static String PARENT_REMOVED = "$premove".intern();
+
/**
* @param searchManager
* @param config
@@ -62,6 +75,30 @@
CacheFactory<Serializable, Object> factory = new DefaultCacheFactory<Serializable, Object>();
log.info("JBoss Cache configuration used: " + jbcConfig);
this.cache = factory.createCache(jbcConfig, false);
+ ((CacheSPI<Serializable, Object>)cache).getComponentRegistry().registerComponent(searchManager,
+ SearchManager.class);
+
+ // initialize IndexerCacheLoader
+ IndexerCacheLoader indexerCacheLoader = new IndexerCacheLoader();
+ // inject dependencies
+ indexerCacheLoader.init(searchManager, parentSearchManager);
+ // set SingltonStoreCacheLoader
+ SingletonStoreConfig singletonStoreConfig = new SingletonStoreConfig();
+ singletonStoreConfig.setClassName(IndexerSingletonStoreCacheLoader.class.getName());
+ // create CacheLoaderConfig
+ IndividualCacheLoaderConfig individualCacheLoaderConfig = new IndividualCacheLoaderConfig();
+ // set SingletonStoreConfig
+ individualCacheLoaderConfig.setSingletonStoreConfig(singletonStoreConfig);
+ // set CacheLoader
+ individualCacheLoaderConfig.setCacheLoader(indexerCacheLoader);
+ // set parameters
+ individualCacheLoaderConfig.setFetchPersistentState(false);
+ individualCacheLoaderConfig.setAsync(false);
+ // create CacheLoaderConfig
+ CacheLoaderConfig cacheLoaderConfig = new CacheLoaderConfig();
+ cacheLoaderConfig.addIndividualCacheLoaderConfig(individualCacheLoaderConfig);
+ // insert CacheLoaderConfig
+ this.cache.getConfiguration().setCacheLoaderConfig(cacheLoaderConfig);
this.cache.create();
this.cache.start();
@@ -74,8 +111,16 @@
protected void doUpdateIndex(Set<String> removedNodes, Set<String> addedNodes, Set<String> parentRemovedNodes,
Set<String> parentAddedNodes)
{
- // TODO Auto-generated method stub
+ cache.startBatch();
+ String id = IdGenerator.generate();
+ cache.put(id, ADDED, addedNodes);
+ cache.put(id, PARENT_ADDED, parentAddedNodes);
+
+ cache.put(id, REMOVED, removedNodes);
+ cache.put(id, PARENT_REMOVED, parentRemovedNodes);
+
+ cache.endBatch(true);
}
}
Modified: jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jbosscache-indexer-config-exoloader_db1_ws.xml
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jbosscache-indexer-config-exoloader_db1_ws.xml 2009-12-08 10:18:27 UTC (rev 941)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/resources/conf/standalone/test-jbosscache-indexer-config-exoloader_db1_ws.xml 2009-12-08 10:38:29 UTC (rev 942)
@@ -7,7 +7,7 @@
transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup" />
<clustering mode="replication" clusterName="JBoss-Cache-Indexer-Cluster_db1_ws">
-
+ <stateRetrieval timeout="20000" fetchInMemoryState="false"/>
<jgroupsConfig>
<!--UDP discard_incompatible_packets="true" enable_bundling="false" enable_diagnostics="false" ip_ttl="2"
loopback="false" max_bundle_size="64000" max_bundle_timeout="30" mcast_addr="228.10.10.10"
@@ -50,31 +50,31 @@
<sync />
<!-- Alternatively, to use async replication, comment out the element above and uncomment the element below. -->
<!-- <async /> -->
- </clustering>
+ </clustering><!--
<loaders passivation="false" shared="false">
- <loader class="org.jboss.cache.loader.FileCacheLoader" async="false"
+ loader class="org.jboss.cache.loader.FileCacheLoader" async="false"
fetchPersistentState="true" ignoreModifications="false"
purgeOnStartup="false">
<properties>
location=/tmp/test-jboss-cache/proxy
</properties>
- </loader>
+ </loader
- <!-- loader class="org.exoplatform.services.jcr.impl.storage.jbosscache.JDBCCacheLoader"
+ loader class="org.exoplatform.services.jcr.impl.storage.jbosscache.JDBCCacheLoader"
async="false" fetchPersistentState="true" ignoreModifications="false" purgeOnStartup="false">
<properties>
</properties>
- </loader-->
+ </loader
- <!-- loader class="org.exoplatform.services.jcr.impl.core.query.cacheloader.IndexerCacheLoader"
+ <loader class="org.exoplatform.services.jcr.impl.core.query.jbosscache.IndexerCacheLoader"
async="false" fetchPersistentState="false" ignoreModifications="false" purgeOnStartup="false">
<properties>
</properties>
- </loader-->
+ </loader>
</loaders>
- <!-- Enable batching -->
+ --><!-- Enable batching -->
<invocationBatching enabled="true"/>
</jbosscache>
More information about the exo-jcr-commits
mailing list