jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1536625 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/MoveDetector.java oak-jcr/pom.xml
Date Tue, 29 Oct 2013 09:39:31 GMT
Author: mduerig
Date: Tue Oct 29 09:39:31 2013
New Revision: 1536625

URL: http://svn.apache.org/r1536625
Log:
OAK-144 Implement observation
Limited support for NODE_MOVED events

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/MoveDetector.java
    jackrabbit/oak/trunk/oak-jcr/pom.xml

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java?rev=1536625&r1=1536624&r2=1536625&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java
Tue Oct 29 09:39:31 2013
@@ -22,20 +22,25 @@ import static com.google.common.base.Pre
 import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.collect.Iterators.concat;
 import static com.google.common.collect.Lists.newArrayList;
+import static java.util.Collections.emptyMap;
 import static javax.jcr.observation.Event.NODE_ADDED;
+import static javax.jcr.observation.Event.NODE_MOVED;
 import static javax.jcr.observation.Event.NODE_REMOVED;
 import static javax.jcr.observation.Event.PROPERTY_ADDED;
 import static javax.jcr.observation.Event.PROPERTY_REMOVED;
+import static org.apache.jackrabbit.oak.commons.PathUtils.getName;
 import static org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager.getIdentifier;
 
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.atomic.AtomicReference;
 
 import javax.jcr.observation.Event;
 import javax.jcr.observation.EventListener;
 
 import com.google.common.collect.ForwardingIterator;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterators;
 import org.apache.jackrabbit.api.jmx.EventListenerMBean;
 import org.apache.jackrabbit.commons.iterator.EventIteratorAdapter;
@@ -51,8 +56,9 @@ import org.apache.jackrabbit.oak.namepat
 import org.apache.jackrabbit.oak.plugins.observation.ChangeDispatcher.ChangeSet;
 import org.apache.jackrabbit.oak.plugins.observation.ChangeDispatcher.Listener;
 import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
-import org.apache.jackrabbit.oak.spi.commit.Validator;
 import org.apache.jackrabbit.oak.spi.commit.VisibleValidator;
+import org.apache.jackrabbit.oak.spi.state.MoveDetector;
+import org.apache.jackrabbit.oak.spi.state.MoveValidator;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.whiteboard.Registration;
 import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
@@ -182,7 +188,7 @@ public class ChangeProcessor {
         }
     }
 
-    private class EventGeneratingValidator extends ForwardingIterator<Event> implements
Validator {
+    private class EventGeneratingValidator extends ForwardingIterator<Event> implements
MoveValidator {
         private final String userId;
         private final String message;
         private final long timestamp;
@@ -229,7 +235,8 @@ public class ChangeProcessor {
             try {
                 if (eventIterator == null) {
                     SecureValidator.compare(beforeTree, afterTree,
-                            new VisibleValidator(this, true, true));
+                            new VisibleValidator(
+                                    new MoveDetector(this, afterTree.getPath()), true, true));
                     eventIterator = concat(events.iterator(), concat(childEvents.iterator()));
                 }
                 return eventIterator;
@@ -271,7 +278,7 @@ public class ChangeProcessor {
         }
 
         @Override
-        public Validator childNodeAdded(String name, NodeState after) {
+        public MoveValidator childNodeAdded(String name, NodeState after) {
             EventFilter eventFilter = filterRef.get();
             if (eventFilter.include(NODE_ADDED, afterTree)) {
                 events.add(createEvent(NODE_ADDED, afterTree.getChild(name)));
@@ -283,7 +290,7 @@ public class ChangeProcessor {
         }
 
         @Override
-        public Validator childNodeDeleted(String name, NodeState before) {
+        public MoveValidator childNodeDeleted(String name, NodeState before) {
             EventFilter eventFilter = filterRef.get();
             if (eventFilter.include(NODE_REMOVED, beforeTree)) {
                 events.add(createEvent(NODE_REMOVED, beforeTree.getChild(name)));
@@ -295,28 +302,43 @@ public class ChangeProcessor {
         }
 
         @Override
-        public Validator childNodeChanged(String name, NodeState before, NodeState after)
{
+        public MoveValidator childNodeChanged(String name, NodeState before, NodeState after)
{
             if (filterRef.get().includeChildren(afterTree.getPath())) {
                 childEvents.add(new EventGeneratingValidator(this, name));
             }
             return null;
         }
 
+        @Override
+        public void move(String sourcePath, String destPath, NodeState moved)
+                throws CommitFailedException {
+            if (filterRef.get().include(NODE_MOVED, afterTree)) {
+                events.add(createEvent(NODE_MOVED, afterTree.getChild(getName(destPath)),
+                        ImmutableMap.of(
+                            "srcAbsPath", namePathMapper.getJcrPath(sourcePath),
+                            "destAbsPath", namePathMapper.getJcrPath(destPath))));
+            }
+        }
+
         //------------------------------------------------------------< internal >---
 
         private Event createEvent(int eventType, Tree tree) {
-            return createEvent(eventType, tree.getPath(), getIdentifier(tree));
+            return createEvent(eventType, tree.getPath(), getIdentifier(tree), emptyMap());
+        }
+
+        private Event createEvent(int eventType, Tree tree, Map<?, ?> info) {
+            return createEvent(eventType, tree.getPath(), getIdentifier(tree), info);
         }
 
         private Event createEvent(int eventType, Tree parent, PropertyState property) {
             String path = PathUtils.concat(parent.getPath(), property.getName());
-            return createEvent(eventType, path, getIdentifier(parent));
+            return createEvent(eventType, path, getIdentifier(parent), emptyMap());
         }
 
-        private Event createEvent(int eventType, String path, String id) {
+        private Event createEvent(int eventType, String path, String id, Map<?, ?>
info) {
             return new EventImpl(
                     eventType, namePathMapper.getJcrPath(path), userId, id,
-                    null /* TODO: info map */, timestamp, message, external);
+                    info, timestamp, message, external);
         }
 
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/MoveDetector.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/MoveDetector.java?rev=1536625&r1=1536624&r2=1536625&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/MoveDetector.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/MoveDetector.java
Tue Oct 29 09:39:31 2013
@@ -56,7 +56,7 @@ public class MoveDetector extends Defaul
     private final MoveValidator moveValidator;
     private final String path;
 
-    private MoveDetector(MoveValidator moveValidator, String path) {
+    public MoveDetector(MoveValidator moveValidator, String path) {
         this.moveValidator = moveValidator;
         this.path = path;
     }

Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1536625&r1=1536624&r2=1536625&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Tue Oct 29 09:39:31 2013
@@ -74,9 +74,6 @@
       org.apache.jackrabbit.test.api.LifecycleTest
 
       <!-- Observation -->
-      org.apache.jackrabbit.test.api.observation.NodeMovedTest#testMoveNode
-      org.apache.jackrabbit.test.api.observation.NodeMovedTest#testMoveTree
-      org.apache.jackrabbit.test.api.observation.NodeMovedTest#testMoveWithRemove
       org.apache.jackrabbit.test.api.observation.GetIdentifierTest#testNodeMoved
       org.apache.jackrabbit.test.api.observation.LockingTest#testAddLockToNode
       org.apache.jackrabbit.test.api.observation.LockingTest#testRemoveLockFromNode



Mime
View raw message