jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1489788 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: plugins/observation/ChangeProcessor.java spi/state/VisibleDiff.java
Date Wed, 05 Jun 2013 10:03:32 GMT
Author: mduerig
Date: Wed Jun  5 10:03:32 2013
New Revision: 1489788

URL: http://svn.apache.org/r1489788
Log:
OAK-775 Implement backward compatible observation
Factor visibility checks into separate NodeStateDiff wrapper class

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/VisibleDiff.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ChangeProcessor.java

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=1489788&r1=1489787&r2=1489788&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
Wed Jun  5 10:03:32 2013
@@ -42,6 +42,7 @@ import org.apache.jackrabbit.oak.spi.sta
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
 import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
+import org.apache.jackrabbit.oak.spi.state.VisibleDiff;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Marker;
@@ -133,7 +134,7 @@ class ChangeProcessor implements Runnabl
             if (changes != null &&
                     !(filterRef.get().excludeLocal() && changes.isLocal(observationManager.getContentSession())))
{
                 EventGeneratingNodeStateDiff diff = new EventGeneratingNodeStateDiff(changes);
-                changes.diff(diff);
+                changes.diff(VisibleDiff.wrap(diff));
                 if (!stopping) {
                     diff.sendEvents();
                 }
@@ -231,8 +232,7 @@ class ChangeProcessor implements Runnabl
 
         @Override
         public boolean propertyAdded(PropertyState after) {
-            if (!NodeStateUtils.isHidden(after.getName())
-                    && filterRef.get().include(Event.PROPERTY_ADDED, jcrPath(), associatedParentNode))
{
+            if (filterRef.get().include(Event.PROPERTY_ADDED, jcrPath(), associatedParentNode))
{
                 Event event = generatePropertyEvent(Event.PROPERTY_ADDED, path, after);
                 events.add(Iterators.singletonIterator(event));
             }
@@ -241,8 +241,7 @@ class ChangeProcessor implements Runnabl
 
         @Override
         public boolean propertyChanged(PropertyState before, PropertyState after) {
-            if (!NodeStateUtils.isHidden(before.getName())
-                    && filterRef.get().include(Event.PROPERTY_CHANGED, jcrPath(),
associatedParentNode)) {
+            if (filterRef.get().include(Event.PROPERTY_CHANGED, jcrPath(), associatedParentNode))
{
                 Event event = generatePropertyEvent(Event.PROPERTY_CHANGED, path, after);
                 events.add(Iterators.singletonIterator(event));
             }
@@ -251,8 +250,7 @@ class ChangeProcessor implements Runnabl
 
         @Override
         public boolean propertyDeleted(PropertyState before) {
-            if (!NodeStateUtils.isHidden(before.getName())
-                    && filterRef.get().include(Event.PROPERTY_REMOVED, jcrPath(),
associatedParentNode)) {
+            if (filterRef.get().include(Event.PROPERTY_REMOVED, jcrPath(), associatedParentNode))
{
                 Event event = generatePropertyEvent(Event.PROPERTY_REMOVED, path, before);
                 events.add(Iterators.singletonIterator(event));
             }
@@ -261,8 +259,7 @@ class ChangeProcessor implements Runnabl
 
         @Override
         public boolean childNodeAdded(String name, NodeState after) {
-            if (!NodeStateUtils.isHidden(name)
-                    && filterRef.get().includeChildren(jcrPath())) {
+            if (filterRef.get().includeChildren(jcrPath())) {
                 Iterator<Event> events = generateNodeEvents(Event.NODE_ADDED, path,
name, after);
                 this.events.add(events);
                 if (++childNodeCount > PURGE_LIMIT) {
@@ -274,8 +271,7 @@ class ChangeProcessor implements Runnabl
 
         @Override
         public boolean childNodeDeleted(String name, NodeState before) {
-            if (!NodeStateUtils.isHidden(name)
-                    && filterRef.get().includeChildren(jcrPath())) {
+            if (filterRef.get().includeChildren(jcrPath())) {
                 Iterator<Event> events = generateNodeEvents(Event.NODE_REMOVED, path,
name, before);
                 this.events.add(events);
             }
@@ -284,11 +280,10 @@ class ChangeProcessor implements Runnabl
 
         @Override
         public boolean childNodeChanged(String name, NodeState before, NodeState after) {
-            if (!NodeStateUtils.isHidden(name)
-                    && filterRef.get().includeChildren(jcrPath())) {
+            if (filterRef.get().includeChildren(jcrPath())) {
                 EventGeneratingNodeStateDiff diff = new EventGeneratingNodeStateDiff(
                         changes, PathUtils.concat(path, name), events, after);
-                if (!after.compareAgainstBaseState(before, diff)) {
+                if (!after.compareAgainstBaseState(before, VisibleDiff.wrap(diff))) {
                     return false;
                 }
                 if (events.size() > PURGE_LIMIT) {

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/VisibleDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/VisibleDiff.java?rev=1489788&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/VisibleDiff.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/VisibleDiff.java
Wed Jun  5 10:03:32 2013
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.jackrabbit.oak.spi.state;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.spi.state.NodeStateUtils.isHidden;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+
+/**
+ * {@code NodeStateDiff} wrapper that passes only changes to non-hidden nodes and properties
+ * (i.e. ones whose names don't start with a colon) to the given delegate diff.
+ *
+ * @since Oak 0.9
+ */
+public class VisibleDiff implements NodeStateDiff {
+    private final NodeStateDiff diff;
+
+    @Nonnull
+    public static NodeStateDiff wrap(@Nonnull NodeStateDiff diff) {
+        return new VisibleDiff(checkNotNull(diff));
+    }
+
+    public VisibleDiff(NodeStateDiff diff) {
+        this.diff = checkNotNull(diff);
+    }
+
+    @Override
+    public boolean propertyAdded(PropertyState after) {
+        if (!isHidden(after.getName())) {
+            return diff.propertyAdded(after);
+        } else {
+            return true;
+        }
+    }
+
+    @Override
+    public boolean propertyChanged(PropertyState before, PropertyState after) {
+        if (!isHidden(after.getName())) {
+            return diff.propertyChanged(before, after);
+        } else {
+            return true;
+        }
+    }
+
+    @Override
+    public boolean propertyDeleted(PropertyState before) {
+        if (!isHidden(before.getName())) {
+            return diff.propertyDeleted(before);
+        } else {
+            return true;
+        }
+    }
+
+    @Override
+    public boolean childNodeAdded(String name, NodeState after) {
+        if (!isHidden(name)) {
+            return diff.childNodeAdded(name, after);
+        } else {
+            return true;
+        }
+    }
+
+    @Override
+    public boolean childNodeChanged(String name, NodeState before, NodeState after) {
+        if (!isHidden(name)) {
+            return diff.childNodeChanged(name, before, after);
+        } else {
+            return true;
+        }
+    }
+
+    @Override
+    public boolean childNodeDeleted(String name, NodeState before) {
+        if (!isHidden(name)) {
+            return diff.childNodeDeleted(name, before);
+        } else {
+            return true;
+        }
+    }
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/VisibleDiff.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/VisibleDiff.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message