[exo-jcr-commits] exo-jcr SVN: r1151 - in jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query: jbosscache and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Dec 23 05:44:34 EST 2009


Author: nzamosenchuk
Date: 2009-12-23 05:44:33 -0500 (Wed, 23 Dec 2009)
New Revision: 1151

Added:
   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/AbstractQueryHandler.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/DefaultChangesFilter.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java
   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/lucene/IndexInfos.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
Log:
EXOJCR-327: IndexInfos class gets Directory by setter now, and methods read(), write(), exists() doesn't get a directory as parameter. Changed IndexInfos lifecycle, it is now created by Changes filter and passed to QueryHandler and then passed to MultiIndex.

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java	2009-12-23 08:59:41 UTC (rev 1150)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/AbstractQueryHandler.java	2009-12-23 10:44:33 UTC (rev 1151)
@@ -23,6 +23,8 @@
 
 import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
 import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos;
+import org.exoplatform.services.jcr.impl.core.query.lucene.MultiIndex;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -65,6 +67,11 @@
     */
    protected IndexerIoMode ioMode = IndexerIoMode.READ_ONLY;
 
+   /**
+    * {@link IndexInfos} instance that is passed to {@link MultiIndex}
+    */
+   protected IndexInfos indexInfos;
+
    public boolean isInitialized()
    {
       return initialized;
@@ -205,4 +212,12 @@
       return idleTime;
    }
 
+   /**
+    * @see org.exoplatform.services.jcr.impl.core.query.QueryHandler#setIndexInfos(org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos)
+    */
+   public void setIndexInfos(IndexInfos indexInfos)
+   {
+      this.indexInfos = indexInfos;
+   }
+
 }

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/DefaultChangesFilter.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/DefaultChangesFilter.java	2009-12-23 08:59:41 UTC (rev 1150)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/DefaultChangesFilter.java	2009-12-23 10:44:33 UTC (rev 1151)
@@ -20,6 +20,7 @@
 
 import org.exoplatform.services.jcr.config.QueryHandlerEntry;
 import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
+import org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
 
@@ -58,10 +59,12 @@
 
       if (!parentHandler.isInitialized())
       {
+         parentHandler.setIndexInfos(new IndexInfos());
          parentHandler.init();
       }
       if (!handler.isInitialized())
       {
+         parentHandler.setIndexInfos(new IndexInfos());
          handler.init();
       }
    }

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java	2009-12-23 08:59:41 UTC (rev 1150)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/QueryHandler.java	2009-12-23 10:44:33 UTC (rev 1151)
@@ -21,6 +21,8 @@
 import org.exoplatform.services.jcr.datamodel.NodeData;
 import org.exoplatform.services.jcr.impl.core.SessionDataManager;
 import org.exoplatform.services.jcr.impl.core.SessionImpl;
+import org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos;
+import org.exoplatform.services.jcr.impl.core.query.lucene.MultiIndex;
 import org.exoplatform.services.jcr.impl.core.query.lucene.QueryHits;
 
 import java.io.IOException;
@@ -152,4 +154,11 @@
     */
    public QueryHits executeQuery(Query query) throws IOException;
 
+   /**
+    * Sets {@link IndexInfos} instance to QueryHandler, which is later passed to {@link MultiIndex}.
+    * 
+    * @param indexInfos
+    */
+   public void setIndexInfos(IndexInfos indexInfos);
+
 }

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	2009-12-23 08:59:41 UTC (rev 1150)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/jbosscache/JbossCacheIndexChangesFilter.java	2009-12-23 10:44:33 UTC (rev 1151)
@@ -26,6 +26,7 @@
 import org.exoplatform.services.jcr.impl.core.query.IndexingTree;
 import org.exoplatform.services.jcr.impl.core.query.QueryHandler;
 import org.exoplatform.services.jcr.impl.core.query.SearchManager;
+import org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos;
 import org.exoplatform.services.jcr.util.IdGenerator;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
@@ -126,10 +127,12 @@
 
       if (!parentHandler.isInitialized())
       {
+         parentHandler.setIndexInfos(new JbossCacheIndexInfos(cache));
          parentHandler.init();
       }
       if (!handler.isInitialized())
       {
+         handler.setIndexInfos(new JbossCacheIndexInfos(cache));
          handler.init();
       }
 

Added: 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	2009-12-23 10:44:33 UTC (rev 1151)
@@ -0,0 +1,66 @@
+/*
+ * 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.apache.lucene.store.Directory;
+import org.exoplatform.services.jcr.impl.core.query.lucene.IndexInfos;
+import org.jboss.cache.Cache;
+import java.io.IOException;
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
+ * @version $Id: JbossCacheIndexInfos.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
+ *
+ */
+public class JbossCacheIndexInfos extends IndexInfos
+{
+
+   private final Cache<Serializable, Object> cache;
+
+   /**
+    * @param cache instance of JbossCache that is used to deliver index names
+    */
+   public JbossCacheIndexInfos(Cache<Serializable, Object> cache)
+   {
+      this(DEFALUT_NAME, cache);
+   }
+
+   /**
+    * @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)
+   {
+      super(fileName);
+      this.cache = cache;
+   }
+
+   @Override
+   public void write() throws IOException
+   {
+      boolean dirty = this.dirty;
+      super.write();
+      if (dirty)
+      {
+         // send to cache new list.
+      }
+   }
+
+}


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/lucene/IndexInfos.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexInfos.java	2009-12-23 08:59:41 UTC (rev 1150)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/IndexInfos.java	2009-12-23 10:44:33 UTC (rev 1151)
@@ -33,10 +33,15 @@
 /**
  * Stores a sequence of index names.
  */
-class IndexInfos
+public class IndexInfos
 {
 
    /**
+    * Default file name, that is used if not defined;
+    */
+   public final static String DEFALUT_NAME = "indexes";
+
+   /**
     * For new segment names.
     */
    protected int counter = 0;
@@ -62,11 +67,19 @@
    protected final String name;
 
    /**
-    * Used to call-back, when index list is changed
+    * Directory, where index names file is stored.
     */
-   protected MultiIndex multiIndex = null;
+   protected Directory dir;
 
    /**
+    * Creates a new IndexInfos using <code>"indexes"</code> as a filename.
+    */
+   public IndexInfos()
+   {
+      this(DEFALUT_NAME);
+   }
+
+   /**
     * Creates a new IndexInfos using <code>fileName</code>.
     *
     * @param fileName the name of the file where infos are stored.
@@ -84,7 +97,7 @@
     * @return <code>true</code> if it exists; <code>false</code> otherwise.
     * @throws IOException if an error occurs while reading from the directory.
     */
-   public boolean exists(Directory dir) throws IOException
+   public boolean exists() throws IOException
    {
       return dir.fileExists(name);
    }
@@ -105,7 +118,7 @@
     * @param dir the directory from where to read the index infos.
     * @throws IOException if an error occurs.
     */
-   public void read(Directory dir) throws IOException
+   public void read() throws IOException
    {
       InputStream in = new IndexInputStream(dir.openInput(name));
       try
@@ -131,7 +144,7 @@
     * @param dir the directory where to write the index infos.
     * @throws IOException if an error occurs.
     */
-   public void write(Directory dir) throws IOException
+   public void write() throws IOException
    {
       // do not write if not dirty
       if (!dirty)
@@ -252,12 +265,11 @@
    }
 
    /**
-    * Injects MultiIndex instance that is used to callback, when list of indexes if changed.
-    * Default implementation (IndexInfos class) actually doesn't use it. 
-    * @param multiIndex
+    * Sets direcotry, where file with index names is stored. 
+    * @param dir
     */
-   public void setMultiIndex(MultiIndex multiIndex)
+   public void setDir(Directory dir)
    {
-      this.multiIndex = multiIndex;
+      this.dir = dir;
    }
 }

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java	2009-12-23 08:59:41 UTC (rev 1150)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/MultiIndex.java	2009-12-23 10:44:33 UTC (rev 1151)
@@ -86,7 +86,7 @@
    /**
     * Names of active persistent index directories.
     */
-   private IndexInfos indexNames = new IndexInfos("indexes");
+   private IndexInfos indexNames;
 
    /**
     * Names of index directories that can be deleted.
@@ -225,7 +225,8 @@
     * @throws IOException
     *             if an error occurs
     */
-   MultiIndex(SearchIndex handler, IndexingTree indexingTree, IndexerIoMode ioMode) throws IOException
+   MultiIndex(SearchIndex handler, IndexingTree indexingTree, IndexerIoMode ioMode, IndexInfos indexInfos)
+      throws IOException
    {
       this.ioMode = ioMode;
       this.directoryManager = handler.getDirectoryManager();
@@ -235,9 +236,11 @@
       this.indexingTree = indexingTree;
       this.nsMappings = handler.getNamespaceMappings();
       this.flushTask = null;
-      if (indexNames.exists(indexDir))
+      this.indexNames = indexInfos;
+      this.indexNames.setDir(indexDir);
+      if (indexNames.exists())
       {
-         indexNames.read(indexDir);
+         indexNames.read();
       }
 
       // as of 1.5 deletable file is not used anymore
@@ -1053,7 +1056,7 @@
          }
          executeAndLog(new Commit(getTransactionId()));
 
-         indexNames.write(indexDir);
+         indexNames.write();
 
          // reset redo log
          redoLog.clear();
@@ -2430,10 +2433,10 @@
       // release reader if any
       releaseMultiReader();
       // get new indexInfo
-      IndexInfos newIndexNames = new IndexInfos("indexes");
-      if (newIndexNames.exists(indexDir))
+      IndexInfos newIndexNames = new IndexInfos();
+      if (newIndexNames.exists())
       {
-         newIndexNames.read(indexDir);
+         newIndexNames.read();
       }
       // prepare added/removed sets
       Set<String> removed = new HashSet<String>(indexNames.getNames());
@@ -2478,7 +2481,7 @@
    }
 
    /**
-    * Refresh list of indexes. Used to be called from IndexInfos. New, actual list is read from 
+    * Refresh list of indexes. Used to be called from CacheLoader. New, actual list is read from 
     * IndexInfos.
     * @throws IOException
     */

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java	2009-12-23 08:59:41 UTC (rev 1150)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/SearchIndex.java	2009-12-23 10:44:33 UTC (rev 1151)
@@ -515,7 +515,8 @@
       indexingConfig = createIndexingConfiguration(nsMappings);
       analyzer.setIndexingConfig(indexingConfig);
 
-      index = new MultiIndex(this, context.getIndexingTree(), ioMode);
+      index =
+         new MultiIndex(this, context.getIndexingTree(), ioMode, indexInfos == null ? new IndexInfos() : indexInfos);
       // if RW mode, create initial index and start check
       if (ioMode == IndexerIoMode.READ_WRITE)
       {



More information about the exo-jcr-commits mailing list