[exo-jcr-commits] exo-jcr SVN: r1353 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Jan 12 05:52:22 EST 2010
Author: skabashnyuk
Date: 2010-01-12 05:52:22 -0500 (Tue, 12 Jan 2010)
New Revision: 1353
Added:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexInfos.java
Removed:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java
Modified:
jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java
Log:
EXOJCR-331 : set resident for root. Renamed JBossCacheIndexInfos
Copied: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexInfos.java (from rev 1349, jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java)
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexInfos.java (rev 0)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexInfos.java 2010-01-12 10:52:22 UTC (rev 1353)
@@ -0,0 +1,183 @@
+/*
+ * 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.jcr.impl.core.query.IndexerIoMode;
+import org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos;
+import org.exoplatform.services.jcr.impl.core.query.lucene.MultiIndex;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.jboss.cache.Cache;
+import org.jboss.cache.Fqn;
+import org.jboss.cache.Node;
+import org.jboss.cache.notifications.annotation.CacheListener;
+import org.jboss.cache.notifications.annotation.NodeModified;
+import org.jboss.cache.notifications.event.NodeModifiedEvent;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Set;
+
+/**
+ * List of indexes is stored in FS and all operations with it are wrapped by IndexInfos class. In
+ * standalone mode index and so the list of indexes are managed by indexer and can't be changed
+ * externally.
+ * But in cluster environment all JCR Indexers are reading from shared file system and only one
+ * cluster node is writing this index. So read-only cluster nodes should be notified when content
+ * of index (actually list of index segments) is changed.
+ * This class is responsible for storing list of segments (indexes) in distributed JBoss Cache
+ * instance.
+ *
+ * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
+ * @version $Id: JbossCacheIndexInfos.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
+ *
+ */
+ at CacheListener
+public class JBossCacheIndexInfos extends IndexInfos
+{
+
+ private final Log log = ExoLogger.getLogger(this.getClass().getName());
+
+ private static final String INDEX_NAMES = "$names".intern();
+
+ private static final String SYSINDEX_NAMES = "$sysNames".intern();
+
+ private static final String LIST_KEY = "$listOfIndexes".intern();
+
+ private final Cache<Serializable, Object> cache;
+
+ /**
+ * Flag notifies if this IndexInfos is from system search manager or not.
+ */
+ private boolean system;
+
+ /**
+ * {@link IndexerIoMode} is used to define current mode.
+ */
+ private IndexerIoMode ioMode = IndexerIoMode.READ_WRITE;
+
+ /**
+ * This FQN points to cache node, where list of indexes for this {@link IndexInfos} instance is stored.
+ */
+ private final Fqn namesFqn;
+
+ /**
+ * @param cache instance of JbossCache that is used to deliver index names
+ */
+ public JBossCacheIndexInfos(Cache<Serializable, Object> cache, boolean system, IndexerIoMode ioMode)
+ {
+ this(DEFALUT_NAME, cache, system, ioMode);
+ }
+
+ /**
+ * @param fileName where index names are stored.
+ * @param cache instance of JbossCache that is used to deliver index names
+ */
+ public JBossCacheIndexInfos(String fileName, Cache<Serializable, Object> cache, boolean system, IndexerIoMode ioMode)
+ {
+ super(fileName);
+ this.cache = cache;
+ this.ioMode = ioMode;
+ // store parsed FQN to avoid it's parsing each time cache event is generated
+ namesFqn = Fqn.fromString(system ? SYSINDEX_NAMES : INDEX_NAMES);
+ Node<Serializable, Object> cacheRoot = cache.getRoot();
+
+ // prepare cache structures
+ cacheRoot.addChild(namesFqn).setResident(true);
+ if (ioMode == IndexerIoMode.READ_ONLY)
+ {
+ // Currently READ_ONLY is set, so new lists should be fired to multiIndex.
+ cache.addCacheListener(this);
+ }
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos#setIoMode(org.exoplatform.services.jcr.impl.core.query.IndexerIoMode)
+ */
+ @Override
+ public void setIoMode(IndexerIoMode ioMode) throws IOException
+ {
+ if (this.ioMode != ioMode)
+ {
+ log.info("New IoMode:" + ioMode);
+ super.setIoMode(ioMode);
+ if (ioMode == IndexerIoMode.READ_WRITE)
+ {
+ // Now is read-write. Index list is actual and shouldn't be refreshed.
+ // Remove listener to avoid asserting if ioMode is RO on each cache event
+ cache.removeCacheListener(this);
+ // re-read from FS current actual list.
+ super.read();
+ }
+ else
+ {
+ // Currently READ_ONLY is set, so new lists should be fired to multiIndex.
+ cache.addCacheListener(this);
+ }
+ }
+ }
+
+ /**
+ * @see org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos#write()
+ */
+ @Override
+ public void write() throws IOException
+ {
+ // if READ_WRITE and is dirty, then flush.
+ if (isDirty() && ioMode == IndexerIoMode.READ_WRITE)
+ {
+ // write to FS
+ super.write();
+ // write to cache
+ cache.put(namesFqn, LIST_KEY, getNames());
+ }
+ }
+
+ /**
+ * CacheListener method, that accepts event, when cache node changed. This class is registered as cache listener,
+ * only in READ_ONLY mode.
+ * @param event
+ */
+ @NodeModified
+ public void cacheNodeModified(NodeModifiedEvent event)
+ {
+ if (!event.isPre() && event.getFqn().equals(namesFqn))
+ {
+ // read from cache to update lists
+ Set<String> set = (Set<String>)cache.get(namesFqn, LIST_KEY);
+ if (set != null)
+ {
+ setNames(set);
+ // callback multiIndex to refresh lists
+ try
+ {
+ MultiIndex multiIndex = getMultiIndex();
+ if (multiIndex != null)
+ {
+ multiIndex.refreshIndexList();
+ }
+ }
+ catch (IOException e)
+ {
+ log.error("Failed to update indexes! " + e.getMessage(), e);
+ }
+ }
+ }
+ }
+}
Property changes on: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JBossCacheIndexInfos.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java 2010-01-12 10:01:51 UTC (rev 1352)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java 2010-01-12 10:52:22 UTC (rev 1353)
@@ -119,14 +119,14 @@
if (!parentHandler.isInitialized())
{
// TODO: uncomment it, when JbossCacheIndexInfos is finished.
- parentHandler.setIndexInfos(new JbossCacheIndexInfos(cache, true, ioMode));
+ parentHandler.setIndexInfos(new JBossCacheIndexInfos(cache, true, ioMode));
parentHandler.setIndexUpdateMonitor(new JbossCacheIndexUpdateMonitor(cache, ioMode));
parentHandler.init();
}
if (!handler.isInitialized())
{
// TODO: uncomment it, when JbossCacheIndexInfos is finished.
- handler.setIndexInfos(new JbossCacheIndexInfos(cache, false, ioMode));
+ handler.setIndexInfos(new JBossCacheIndexInfos(cache, false, ioMode));
handler.setIndexUpdateMonitor(new JbossCacheIndexUpdateMonitor(cache, ioMode));
handler.init();
}
Deleted: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java 2010-01-12 10:01:51 UTC (rev 1352)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexInfos.java 2010-01-12 10:52:22 UTC (rev 1353)
@@ -1,178 +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.jcr.impl.core.query.IndexerIoMode;
-import org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos;
-import org.exoplatform.services.jcr.impl.core.query.lucene.MultiIndex;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-import org.jboss.cache.Cache;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.notifications.annotation.CacheListener;
-import org.jboss.cache.notifications.annotation.NodeModified;
-import org.jboss.cache.notifications.event.NodeModifiedEvent;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.Set;
-
-/**
- * List of indexes is stored in FS and all operations with it are wrapped by IndexInfos class. In
- * standalone mode index and so the list of indexes are managed by indexer and can't be changed
- * externally.
- * But in cluster environment all JCR Indexers are reading from shared file system and only one
- * cluster node is writing this index. So read-only cluster nodes should be notified when content
- * of index (actually list of index segments) is changed.
- * This class is responsible for storing list of segments (indexes) in distributed JBoss Cache
- * instance.
- *
- * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
- * @version $Id: JbossCacheIndexInfos.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
- *
- */
- at CacheListener
-public class JbossCacheIndexInfos extends IndexInfos
-{
-
- private final Log log = ExoLogger.getLogger(this.getClass().getName());
-
- private static final String INDEX_NAMES = "$names".intern();
-
- private static final String SYSINDEX_NAMES = "$sysNames".intern();
-
- private static final String LIST_KEY = "$listOfIndexes".intern();
-
- private final Cache<Serializable, Object> cache;
-
- /**
- * Flag notifies if this IndexInfos is from system search manager or not.
- */
- private boolean system;
-
- /**
- * {@link IndexerIoMode} is used to define current mode.
- */
- private IndexerIoMode ioMode = IndexerIoMode.READ_WRITE;
-
- /**
- * This FQN points to cache node, where list of indexes for this {@link IndexInfos} instance is stored.
- */
- private final Fqn namesFqn;
-
- /**
- * @param cache instance of JbossCache that is used to deliver index names
- */
- public JbossCacheIndexInfos(Cache<Serializable, Object> cache, boolean system, IndexerIoMode ioMode)
- {
- this(DEFALUT_NAME, cache, system, ioMode);
- }
-
- /**
- * @param fileName where index names are stored.
- * @param cache instance of JbossCache that is used to deliver index names
- */
- public JbossCacheIndexInfos(String fileName, Cache<Serializable, Object> cache, boolean system, IndexerIoMode ioMode)
- {
- super(fileName);
- this.cache = cache;
- this.ioMode = ioMode;
- // store parsed FQN to avoid it's parsing each time cache event is generated
- namesFqn = Fqn.fromString(system ? SYSINDEX_NAMES : INDEX_NAMES);
- if (ioMode == IndexerIoMode.READ_ONLY)
- {
- // Currently READ_ONLY is set, so new lists should be fired to multiIndex.
- cache.addCacheListener(this);
- }
- }
-
- /**
- * @see org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos#setIoMode(org.exoplatform.services.jcr.impl.core.query.IndexerIoMode)
- */
- @Override
- public void setIoMode(IndexerIoMode ioMode) throws IOException
- {
- if (this.ioMode != ioMode)
- {
- log.info("New IoMode:" + ioMode);
- super.setIoMode(ioMode);
- if (ioMode == IndexerIoMode.READ_WRITE)
- {
- // Now is read-write. Index list is actual and shouldn't be refreshed.
- // Remove listener to avoid asserting if ioMode is RO on each cache event
- cache.removeCacheListener(this);
- // re-read from FS current actual list.
- super.read();
- }
- else
- {
- // Currently READ_ONLY is set, so new lists should be fired to multiIndex.
- cache.addCacheListener(this);
- }
- }
- }
-
- /**
- * @see org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos#write()
- */
- @Override
- public void write() throws IOException
- {
- // if READ_WRITE and is dirty, then flush.
- if (isDirty() && ioMode == IndexerIoMode.READ_WRITE)
- {
- // write to FS
- super.write();
- // write to cache
- cache.put(namesFqn, LIST_KEY, getNames());
- }
- }
-
- /**
- * CacheListener method, that accepts event, when cache node changed. This class is registered as cache listener,
- * only in READ_ONLY mode.
- * @param event
- */
- @NodeModified
- public void cacheNodeModified(NodeModifiedEvent event)
- {
- if (!event.isPre() && event.getFqn().equals(namesFqn))
- {
- // read from cache to update lists
- Set<String> set = (Set<String>)cache.get(namesFqn, LIST_KEY);
- if (set != null)
- {
- setNames(set);
- // callback multiIndex to refresh lists
- try
- {
- MultiIndex multiIndex = getMultiIndex();
- if (multiIndex != null)
- {
- multiIndex.refreshIndexList();
- }
- }
- catch (IOException e)
- {
- log.error("Failed to update indexes! " + e.getMessage(), e);
- }
- }
- }
- }
-}
More information about the exo-jcr-commits
mailing list