jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1354071 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/core/ main/java/org/apache/jackrabbit/oak/kernel/ main/java/org/apache/jackrabbit/oak/spi/commit/ test/java/org/apache/jackrabbit/oak/kernel/
Date Tue, 26 Jun 2012 15:49:09 GMT
Author: jukka
Date: Tue Jun 26 15:49:08 2012
New Revision: 1354071

URL: http://svn.apache.org/viewvc?rev=1354071&view=rev
Log:
OAK-153: Split the CommitHook interface

Drop afterCommit from CommitEditor

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitEditor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EmptyEditor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ValidatingEditor.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java?rev=1354071&r1=1354070&r2=1354071&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
Tue Jun 26 15:49:08 2012
@@ -91,11 +91,11 @@ public class ContentRepositoryImpl imple
             validatorProvider = createDefaultValidatorProvider();
         }
 
-        List<CommitEditor> hooks = new ArrayList<CommitEditor>();
-        hooks.add(new ValidatingEditor(validatorProvider));
-        CompositeEditor compositeHook = new CompositeEditor(hooks);
+        List<CommitEditor> editors = new ArrayList<CommitEditor>();
+        editors.add(new ValidatingEditor(validatorProvider));
+        CompositeEditor editor = new CompositeEditor(editors);
 
-        nodeStore = new KernelNodeStore(microKernel, compositeHook);
+        nodeStore = new KernelNodeStore(microKernel, editor);
         QueryIndexProvider qip = (indexProvider == null) ? getDefaultIndexProvider(microKernel)
: indexProvider;
         queryEngine = new QueryEngineImpl(nodeStore, microKernel, qip);
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java?rev=1354071&r1=1354070&r2=1354071&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
Tue Jun 26 15:49:08 2012
@@ -36,9 +36,9 @@ public class KernelNodeStore extends Mem
     private final MicroKernel kernel;
 
     /**
-     * Commit hook.
+     * Commit editor.
      */
-    private final CommitEditor commitHook;
+    private final CommitEditor editor;
 
     /**
      * Value factory backed by the {@link #kernel} instance.
@@ -50,12 +50,12 @@ public class KernelNodeStore extends Mem
      */
     private KernelNodeState root;
 
-    public KernelNodeStore(MicroKernel kernel, CommitEditor commitHook) {
+    public KernelNodeStore(MicroKernel kernel, CommitEditor editor) {
         assert kernel != null;
-        assert commitHook != null;
+        assert editor != null;
 
         this.kernel = kernel;
-        this.commitHook = commitHook;
+        this.editor = editor;
         this.valueFactory = new CoreValueFactoryImpl(kernel);
         this.root = new KernelNodeState(
                 kernel, valueFactory, "/", kernel.getHeadRevision());
@@ -89,7 +89,7 @@ public class KernelNodeStore extends Mem
     }
 
     @Nonnull
-    CommitEditor getCommitHook() {
-        return commitHook;
+    CommitEditor getCommitEditor() {
+        return editor;
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java?rev=1354071&r1=1354070&r2=1354071&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
Tue Jun 26 15:49:08 2012
@@ -123,15 +123,15 @@ class KernelNodeStoreBranch implements N
     @Override
     public KernelNodeState merge() throws CommitFailedException {
         MicroKernel kernel = store.getKernel();
-        CommitEditor commitHook = store.getCommitHook();
+        CommitEditor editor = store.getCommitEditor();
 
         NodeState preMergeRoot = store.getRoot();
         NodeState oldRoot = preMergeRoot;
-        NodeState toCommit = commitHook.beforeCommit(store, oldRoot, currentRoot);
+        NodeState toCommit = editor.beforeCommit(store, oldRoot, currentRoot);
         while (!currentRoot.equals(toCommit)) {
             setRoot(toCommit);
             oldRoot = store.getRoot();
-            toCommit = commitHook.beforeCommit(store, oldRoot, currentRoot);
+            toCommit = editor.beforeCommit(store, oldRoot, currentRoot);
         }
 
         try {
@@ -140,7 +140,6 @@ class KernelNodeStoreBranch implements N
             currentRoot = null;
             committed = null;
             KernelNodeState committed = new KernelNodeState(kernel, getValueFactory(), "/",
mergedRevision);
-            commitHook.afterCommit(store, preMergeRoot, committed);
             return committed;
         }
         catch (MicroKernelException e) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitEditor.java?rev=1354071&r1=1354070&r2=1354071&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitEditor.java
Tue Jun 26 15:49:08 2012
@@ -23,29 +23,17 @@ import org.apache.jackrabbit.oak.spi.sta
 import javax.annotation.Nonnull;
 
 /**
- * Extension point for custom functionality to be performed before and
- * after content changes are committed. The repository core will call
- * all available commit hooks in sequence for all commits it makes or
- * sees. The control flows roughly like this:
- * <pre>
- * NodeStore store = ...;
- * NodeState before = ...;
- * NodeState after = ...;
- *
- * for (CommitHook hook : hooks) {
- *     after = hook.preCommit(store, before, after);
- * }
- *
- * after = branch.merge();
- *
- * for (CommitHook hook : hooks) {
- *     hook.afterCommit(store, before, after);
- * }
- * </pre>
+ * Extension point for validating and modifying content changes. Available
+ * commit editors are called in sequence to process incoming content changes
+ * before they get persisted and shared with other clients.
+ * <p>
+ * A commit editor can throw a {@link CommitFailedException} for a particular
+ * change to prevent it from being persisted, or it can modify the changes
+ * for example to update an in-content index or to add auto-generated content.
  * <p>
  * Note that instead of implementing this interface directly, most commit
- * hooks are better expressed as implementations of the more specific
- * extension interfaces defined in this package.
+ * editors and validators are better expressed as implementations of the
+ * more specific extension interfaces defined in this package.
  */
 public interface CommitEditor {
 
@@ -71,37 +59,4 @@ public interface CommitEditor {
     NodeState beforeCommit(NodeStore store, NodeState before, NodeState after)
         throws CommitFailedException;
 
-    /**
-     * After-commit hook. The implementation can no longer modify the commit
-     * or make it fail due to an exception, but may update caches, trigger
-     * observation events or otherwise record the change.
-     * <p>
-     * After-commit hooks are called both for commits made locally against
-     * the repository instance to which the hook is registered and for any
-     * other changes committed by other repository instances in the same
-     * cluster.
-     * <p>
-     * The after-commit hooks do not necessarily reflect each individual
-     * commit made against the repository, but rather more generic updates
-     * of the repository state that may include other, concurrently merged
-     * changes. However, the repository does guarantee that a given state is
-     * never returned by {@link NodeStore#getRoot()} before the respective
-     * after-commit hooks have been called. Also, the after-commit hooks are
-     * all linear in the sense that the {@code after} state of one hook
-     * invocation is guaranteed to be the {@code before} state of the next
-     * hook invocation. This sequence of changes only applies while a hook
-     * is registered with a specific repository instance, and is thus for
-     * example <em>not</me> guaranteed across repository restarts.
-     * <p>
-     * After-commit hooks are executed synchronously within the context of
-     * a repository instance, so to prevent delaying access to latest changes
-     * the after-commit hooks should avoid any potentially blocking
-     * operations.
-     *
-     * @param store the node store that contains the repository content
-     * @param before content tree before the commit
-     * @param after content tree after the commit
-     */
-    void afterCommit(NodeStore store, NodeState before, NodeState after);
-
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java?rev=1354071&r1=1354070&r2=1354071&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java
Tue Jun 26 15:49:08 2012
@@ -48,10 +48,4 @@ public class CompositeEditor implements 
         return newState;
     }
 
-    @Override
-    public void afterCommit(NodeStore store, NodeState before, NodeState after) {
-        for (CommitEditor hook : hooks) {
-            hook.afterCommit(store, before, after);
-        }
-    }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EmptyEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EmptyEditor.java?rev=1354071&r1=1354070&r2=1354071&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EmptyEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EmptyEditor.java
Tue Jun 26 15:49:08 2012
@@ -49,10 +49,4 @@ public class EmptyEditor implements Comm
         return after;
     }
 
-    @Override
-    public void afterCommit(
-            NodeStore store, NodeState before, NodeState after) {
-        // do nothing
-    }
-
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ValidatingEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ValidatingEditor.java?rev=1354071&r1=1354070&r2=1354071&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ValidatingEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ValidatingEditor.java
Tue Jun 26 15:49:08 2012
@@ -25,7 +25,7 @@ import org.apache.jackrabbit.oak.spi.sta
 import static org.apache.jackrabbit.oak.plugins.memory.MemoryNodeState.EMPTY_NODE;
 
 /**
- * This commit hook implementation validates the changes to be committed
+ * This commit editor implementation validates the changes to be committed
  * against all {@link Validator}s provided by the {@link ValidatorProvider}
  * passed to the class' constructor.
  */
@@ -51,11 +51,6 @@ public class ValidatingEditor implements
         return after;
     }
 
-    @Override
-    public void afterCommit(NodeStore store, NodeState before, NodeState after) {
-        // nothing to do here
-    }
-
     //------------------------------------------------------------< private >---
 
     private static class ValidatorDiff implements NodeStateDiff {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreTest.java?rev=1354071&r1=1354070&r2=1354071&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreTest.java
Tue Jun 26 15:49:08 2012
@@ -140,14 +140,15 @@ public class KernelNodeStoreTest extends
         final NodeState newRoot = rootBuilder.getNodeState();
 
         commitWithHook(newRoot, new EmptyEditor() {
-            @Override
-            public void afterCommit(NodeStore store, NodeState before, NodeState after) {
-                assertNull(before.getChildNode("test").getChildNode("newNode"));
-                assertNotNull(after.getChildNode("test").getChildNode("newNode"));
-                assertNull(after.getChildNode("test").getChildNode("a"));
-                assertEquals(fortyTwo, after.getChildNode("test").getChildNode("newNode").getProperty("n").getValue());
-                assertEquals(newRoot, after);
-            }
+// TODO: OAK-153 - use the Observer interface to observe content changes
+//            @Override
+//            public void afterCommit(NodeStore store, NodeState before, NodeState after)
{
+//                assertNull(before.getChildNode("test").getChildNode("newNode"));
+//                assertNotNull(after.getChildNode("test").getChildNode("newNode"));
+//                assertNull(after.getChildNode("test").getChildNode("a"));
+//                assertEquals(fortyTwo, after.getChildNode("test").getChildNode("newNode").getProperty("n").getValue());
+//                assertEquals(newRoot, after);
+//            }
         });
     }
 
@@ -218,10 +219,6 @@ public class KernelNodeStoreTest extends
             return delegate.beforeCommit(store, before, after);
         }
 
-        @Override
-        public void afterCommit(NodeStore store, NodeState before, NodeState after) {
-            delegate.afterCommit(store, before, after);
-        }
     }
 
 }



Mime
View raw message