jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1485651 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/
Date Thu, 23 May 2013 11:33:28 GMT
Author: alexparvulescu
Date: Thu May 23 11:33:28 2013
New Revision: 1485651

URL: http://svn.apache.org/r1485651
Log:
OAK-763 Asynchronous indexing

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneIndexHelper.java
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java?rev=1485651&r1=1485650&r2=1485651&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java Thu May
23 11:33:28 2013
@@ -33,6 +33,7 @@ import org.apache.jackrabbit.oak.api.Roo
 import org.apache.jackrabbit.oak.core.ContentRepositoryImpl;
 import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
 import org.apache.jackrabbit.oak.plugins.commit.ConflictHook;
+import org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate;
 import org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider;
 import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
 import org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider;
@@ -94,6 +95,13 @@ public class Oak {
 
     private String defaultWorkspaceName = DEFAULT_WORKSPACE_NAME;
 
+    /**
+     * Flag controlling the asynchronous indexing behavior. If false (default)
+     * there will be no background indexing happening.
+     * 
+     */
+    private boolean asyncIndexing = false;
+
     public Oak(NodeStore store) {
         this.store = checkNotNull(store);
     }
@@ -237,6 +245,19 @@ public class Oak {
         return this;
     }
 
+    /**
+     * Enable the asynchronous (background) indexing behavior.
+     * 
+     * Please not that when enabling the background indexer, you need to take
+     * care of calling
+     * <code>#shutdown<code> on the <code>executor<code> provided
for this Oak instance.
+     * 
+     */
+    public Oak withAsyncIndexing() {
+        this.asyncIndexing = true;
+        return this;
+    }
+
     @Nonnull
     public ScheduledExecutorService getExecutorService() {
         return this.executor;
@@ -252,6 +273,10 @@ public class Oak {
         initHooks.add(new EditorHook(CompositeEditorProvider
                 .compose(editorProviders)));
 
+        if (asyncIndexing) {
+            new AsyncIndexUpdate(store, executor, indexEditors);
+        }
+
         // FIXME: OAK-810 move to proper workspace initialization
         // initialize default workspace
         Iterable<WorkspaceInitializer> workspaceInitializers =

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java?rev=1485651&r1=1485650&r2=1485651&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java Thu
May 23 11:33:28 2013
@@ -138,6 +138,11 @@ public class Jcr {
         return this;
     }
 
+    public Jcr withAsyncIndexing() {
+        oak.withAsyncIndexing();
+        return this;
+    }
+
     public Repository createRepository() {
         return new RepositoryImpl(
                 oak.createContentRepository(), 

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneIndexHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneIndexHelper.java?rev=1485651&r1=1485650&r2=1485651&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneIndexHelper.java
(original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneIndexHelper.java
Thu May 23 11:33:28 2013
@@ -50,31 +50,22 @@ public class LuceneIndexHelper {
     public static NodeBuilder newLuceneIndexDefinition(
             @Nonnull NodeBuilder index, @Nonnull String name,
             @Nullable Set<String> propertyTypes) {
-        if (index.hasChildNode(name)) {
-            return index.child(name);
-        }
-        index = index.child(name);
-        index.setProperty(JCR_PRIMARYTYPE, INDEX_DEFINITIONS_NODE_TYPE, NAME)
-                .setProperty(TYPE_PROPERTY_NAME, TYPE_LUCENE)
-                .setProperty(REINDEX_PROPERTY_NAME, true);
-        if (propertyTypes != null && !propertyTypes.isEmpty()) {
-            index.setProperty(PropertyStates.createProperty(
-                    INCLUDE_PROPERTY_TYPES, propertyTypes, Type.STRINGS));
-        }
-        return index;
+        return newLuceneIndexDefinition(index, name, propertyTypes, false);
     }
 
-    public static NodeBuilder newLuceneAsyncIndexDefinition(
+    public static NodeBuilder newLuceneIndexDefinition(
             @Nonnull NodeBuilder index, @Nonnull String name,
-            @Nullable Set<String> propertyTypes) {
+            @Nullable Set<String> propertyTypes, boolean async) {
         if (index.hasChildNode(name)) {
             return index.child(name);
         }
         index = index.child(name);
         index.setProperty(JCR_PRIMARYTYPE, INDEX_DEFINITIONS_NODE_TYPE, NAME)
                 .setProperty(TYPE_PROPERTY_NAME, TYPE_LUCENE)
-                .setProperty(ASYNC_PROPERTY_NAME, true)
                 .setProperty(REINDEX_PROPERTY_NAME, true);
+        if (async) {
+            index.setProperty(ASYNC_PROPERTY_NAME, true);
+        }
         if (propertyTypes != null && !propertyTypes.isEmpty()) {
             index.setProperty(PropertyStates.createProperty(
                     INCLUDE_PROPERTY_TYPES, propertyTypes, Type.STRINGS));
@@ -85,6 +76,14 @@ public class LuceneIndexHelper {
     public static NodeBuilder newLuceneFileIndexDefinition(
             @Nonnull NodeBuilder index, @Nonnull String name,
             @Nullable Set<String> propertyTypes, @Nonnull String path) {
+        return newLuceneFileIndexDefinition(index, name, propertyTypes, path,
+                false);
+    }
+
+    public static NodeBuilder newLuceneFileIndexDefinition(
+            @Nonnull NodeBuilder index, @Nonnull String name,
+            @Nullable Set<String> propertyTypes, @Nonnull String path,
+            boolean async) {
         if (index.hasChildNode(name)) {
             return index.child(name);
         }
@@ -94,6 +93,9 @@ public class LuceneIndexHelper {
                 .setProperty(PERSISTENCE_NAME, PERSISTENCE_FILE)
                 .setProperty(PERSISTENCE_PATH, path)
                 .setProperty(REINDEX_PROPERTY_NAME, true);
+        if (async) {
+            index.setProperty(ASYNC_PROPERTY_NAME, true);
+        }
         if (propertyTypes != null && !propertyTypes.isEmpty()) {
             index.setProperty(PropertyStates.createProperty(
                     INCLUDE_PROPERTY_TYPES, propertyTypes, Type.STRINGS));

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java?rev=1485651&r1=1485650&r2=1485651&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java
(original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java
Thu May 23 11:33:28 2013
@@ -34,6 +34,8 @@ public class LuceneInitializerHelper imp
 
     private final String filePath;
 
+    private boolean async = false;
+
     public LuceneInitializerHelper(String name) {
         this(name, LuceneIndexHelper.JR_PROPERTY_INCLUDES);
     }
@@ -49,6 +51,11 @@ public class LuceneInitializerHelper imp
         this.filePath = filePath;
     }
 
+    public LuceneInitializerHelper async() {
+        async = true;
+        return this;
+    }
+
     @Override
     public NodeState initialize(NodeState state) {
         if (state.hasChildNode(INDEX_DEFINITIONS_NAME)
@@ -60,10 +67,10 @@ public class LuceneInitializerHelper imp
 
         if (filePath == null) {
             newLuceneIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME),
-                    name, propertyTypes);
+                    name, propertyTypes, async);
         } else {
             newLuceneFileIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME),
-                    name, propertyTypes, filePath);
+                    name, propertyTypes, filePath, async);
         }
         return builder.getNodeState();
     }



Mime
View raw message