jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1495436 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: plugins/observation/ChangeDispatcher.java plugins/observation/ChangeProcessor.java plugins/observation/EventFilter.java spi/state/NodeStateUtils.java
Date Fri, 21 Jun 2013 13:43:22 GMT
Author: mduerig
Date: Fri Jun 21 13:43:22 2013
New Revision: 1495436

URL: http://svn.apache.org/r1495436
Log:
OAK-144 Implement Observation
diff only subtree at given path if a path filter is set for an observation listener

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeDispatcher.java
    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/plugins/observation/EventFilter.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateUtils.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeDispatcher.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeDispatcher.java?rev=1495436&r1=1495435&r2=1495436&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeDispatcher.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeDispatcher.java
Fri Jun 21 13:43:22 2013
@@ -21,6 +21,7 @@ package org.apache.jackrabbit.oak.plugin
 import static com.google.common.base.Objects.toStringHelper;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.apache.jackrabbit.oak.plugins.observation.ObservationConstants.OAK_UNKNOWN;
+import static org.apache.jackrabbit.oak.spi.state.NodeStateUtils.getNode;
 
 import java.util.Queue;
 import java.util.Set;
@@ -250,10 +251,11 @@ public class ChangeDispatcher {
         /**
          * {@link NodeStateDiff} of the changes
          * @param diff  node state diff instance for traversing the changes.
+         * @param path  path where diffing should start
          */
-        public void diff(RecursingNodeStateDiff diff) {
+        public void diff(RecursingNodeStateDiff diff, String path) {
             NodeStateDiff secureDiff = SecureNodeStateDiff.wrap(diff);
-            after.compareAgainstBaseState(before, secureDiff);
+            getNode(after, path).compareAgainstBaseState(getNode(before, path), secureDiff);
         }
 
         @Override

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=1495436&r1=1495435&r2=1495436&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
Fri Jun 21 13:43:22 2013
@@ -162,9 +162,10 @@ class ChangeProcessor implements Runnabl
         try {
             ChangeSet changes = changeListener.getChanges();
             while (!stopping && changes != null) {
-                if (!(filterRef.get().excludeLocal() && changes.isLocal(observationManager.getContentSession())))
{
+                EventFilter filter = filterRef.get();
+                if (!(filter.excludeLocal() && changes.isLocal(observationManager.getContentSession())))
{
                     EventGeneratingNodeStateDiff diff = new EventGeneratingNodeStateDiff(changes);
-                    changes.diff(VisibleDiff.wrap(diff));
+                    changes.diff(VisibleDiff.wrap(diff), filter.getPath());
                     if (!stopping) {
                         diff.sendEvents();
                     }
@@ -212,7 +213,7 @@ class ChangeProcessor implements Runnabl
 
         public EventGeneratingNodeStateDiff(ChangeSet changes) {
             // FIXME parent nodes should be the root here
-            this(changes, "/", new ArrayList<Iterator<Event>>(PURGE_LIMIT), null,
null, null, "");
+            this(changes, filterRef.get().getPath(), new ArrayList<Iterator<Event>>(PURGE_LIMIT),
null, null, null, "");
         }
 
         public void sendEvents() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventFilter.java?rev=1495436&r1=1495435&r2=1495436&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventFilter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventFilter.java
Fri Jun 21 13:43:22 2013
@@ -93,6 +93,10 @@ class EventFilter {
             .toString();
     }
 
+    public String getPath() {
+        return path;
+    }
+
     //-----------------------------< internal >---------------------------------
 
     private boolean include(int eventType) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateUtils.java?rev=1495436&r1=1495435&r2=1495436&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateUtils.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateUtils.java
Fri Jun 21 13:43:22 2013
@@ -16,12 +16,15 @@
  */
 package org.apache.jackrabbit.oak.spi.state;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.commons.PathUtils;
 
 /**
  * Utility method for code that deals with node states.
@@ -47,4 +50,19 @@ public final class NodeStateUtils {
         PropertyState ps = nodeState.getProperty(JcrConstants.JCR_PRIMARYTYPE);
         return (ps == null) ? null : ps.getValue(Type.NAME);
     }
+
+    /**
+     * Get a possibly non existing child node of a node.
+     * @param node  node whose child node to get
+     * @param path  path of the child node
+     * @return  child node of {@code node} at {@code path}.
+     */
+    @Nonnull
+    public static NodeState getNode(@Nonnull NodeState node, @Nonnull String path) {
+        for (String name : PathUtils.elements(checkNotNull(path))) {
+            node = node.getChildNode(checkNotNull(name));
+        }
+        return node;
+    }
+
 }



Mime
View raw message