You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by md...@apache.org on 2013/11/20 15:33:20 UTC

svn commit: r1543826 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter: NodeTypeFilter.java PathFilter.java UuidFilter.java

Author: mduerig
Date: Wed Nov 20 14:33:19 2013
New Revision: 1543826

URL: http://svn.apache.org/r1543826
Log:
OAK-1133: Observation listener PLUS
Memoise filter evaluation

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/NodeTypeFilter.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/PathFilter.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UuidFilter.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/NodeTypeFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/NodeTypeFilter.java?rev=1543826&r1=1543825&r2=1543826&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/NodeTypeFilter.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/NodeTypeFilter.java Wed Nov 20 14:33:19 2013
@@ -28,6 +28,7 @@ import org.apache.jackrabbit.oak.core.Im
 import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
 import org.apache.jackrabbit.oak.plugins.observation.filter.EventGenerator.Filter;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.util.LazyValue;
 
 /**
  * {@code EventTypeFilter} filters based on the node type of the
@@ -42,6 +43,22 @@ public class NodeTypeFilter implements F
     private final ReadOnlyNodeTypeManager ntManager;
     private final String[] ntNames;
 
+    private final LazyValue<Boolean> include = new LazyValue<Boolean>() {
+        @Override
+        protected Boolean createValue() {
+            ImmutableTree associatedParent = afterTree.exists()
+                    ? afterTree
+                    : beforeTree;
+
+            for (String ntName : ntNames) {
+                if (ntManager.isNodeType(associatedParent, ntName)) {
+                    return true;
+                }
+            }
+            return false;
+        }
+    };
+
     /**
      * Create a new {@code Filter} instance that includes an event when the type of the
      * associated parent node is of one of the node types in {@code ntNames}.
@@ -61,22 +78,22 @@ public class NodeTypeFilter implements F
 
     @Override
     public boolean includeAdd(PropertyState after) {
-        return includeByType();
+        return include.get();
     }
 
     @Override
     public boolean includeChange(PropertyState before, PropertyState after) {
-        return includeByType();
+        return include.get();
     }
 
     @Override
     public boolean includeDelete(PropertyState before) {
-        return includeByType();
+        return include.get();
     }
 
     @Override
     public boolean includeAdd(String name, NodeState after) {
-        return includeByType();
+        return include.get();
     }
 
     @Override
@@ -86,12 +103,12 @@ public class NodeTypeFilter implements F
 
     @Override
     public boolean includeDelete(String name, NodeState before) {
-        return includeByType();
+        return include.get();
     }
 
     @Override
     public boolean includeMove(String sourcePath, String destPath, NodeState moved) {
-        return includeByType();
+        return include.get();
     }
 
     @Override
@@ -100,19 +117,4 @@ public class NodeTypeFilter implements F
                 beforeTree.getChild(name), afterTree.getChild(name), ntManager, ntNames);
     }
 
-    //------------------------------------------------------------< private >---
-
-    private boolean includeByType() {
-        ImmutableTree associatedParent = afterTree.exists()
-            ? afterTree
-            : beforeTree;
-
-        for (String ntName : ntNames) {
-            if (ntManager.isNodeType(associatedParent, ntName)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/PathFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/PathFilter.java?rev=1543826&r1=1543825&r2=1543826&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/PathFilter.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/PathFilter.java Wed Nov 20 14:33:19 2013
@@ -20,6 +20,7 @@
 package org.apache.jackrabbit.oak.plugins.observation.filter;
 
 import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.commons.PathUtils.isAncestor;
 
 import javax.annotation.Nonnull;
 
@@ -28,6 +29,7 @@ import org.apache.jackrabbit.oak.commons
 import org.apache.jackrabbit.oak.core.ImmutableTree;
 import org.apache.jackrabbit.oak.plugins.observation.filter.EventGenerator.Filter;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.util.LazyValue;
 
 /**
  * {@code EventTypeFilter} filters based on the path of the <em>associated parent node</em> as
@@ -41,6 +43,22 @@ public class PathFilter implements Filte
     private final String path;
     private final boolean deep;
 
+    private final LazyValue<Boolean> include = new LazyValue<Boolean>() {
+        @Override
+        protected Boolean createValue() {
+            String associatedParentPath = afterTree.exists()
+                    ? afterTree.getPath()
+                    : beforeTree.getPath();
+
+            boolean equalPaths = path.equals(associatedParentPath);
+            if (!deep) {
+                return equalPaths;
+            } else {
+                return equalPaths || isAncestor(path, associatedParentPath);
+            }
+        }
+    };
+
     /**
      * Create a new {@code Filter} instance that includes an event when the path of the
      * associated parent node matches the one of this filter or - when the {@code deep}
@@ -60,75 +78,52 @@ public class PathFilter implements Filte
 
     @Override
     public boolean includeAdd(PropertyState after) {
-        return includeByPath();
+        return include.get();
     }
 
     @Override
     public boolean includeChange(PropertyState before, PropertyState after) {
-        return includeByPath();
+        return include.get();
     }
 
     @Override
     public boolean includeDelete(PropertyState before) {
-        return includeByPath();
+        return include.get();
     }
 
     @Override
     public boolean includeAdd(String name, NodeState after) {
-        return includeByPath();
+        return include.get();
     }
 
     @Override
     public boolean includeChange(String name, NodeState before, NodeState after) {
-        return includeByPath();
+        return include.get();
     }
 
     @Override
     public boolean includeDelete(String name, NodeState before) {
-        return includeByPath();
+        return include.get();
     }
 
     @Override
     public boolean includeMove(String sourcePath, String destPath, NodeState moved) {
-        return includeByPath();
+        return include.get();
     }
 
     @Override
     public Filter create(String name, NodeState before, NodeState after) {
-        if (includeChildren(name)) {
+        String associatedParentPath = afterTree.exists()
+            ? PathUtils.concat(afterTree.getPath(), name)
+            : PathUtils.concat(beforeTree.getPath(), name);
+
+        if (isAncestor(associatedParentPath, path) ||
+                path.equals(associatedParentPath) ||
+                deep && isAncestor(path, associatedParentPath)) {
             return new PathFilter(beforeTree, afterTree.getChild(name), path, deep);
         } else {
             return null;
         }
     }
 
-    //------------------------------------------------------------< private >---
-
-    private boolean includeByPath() {
-        String path = afterTree.exists()
-            ? afterTree.getPath()
-            : beforeTree.getPath();
-
-        boolean equalPaths = this.path.equals(path);
-        if (!deep && !equalPaths) {
-            return false;
-        }
-
-        if (deep && !(PathUtils.isAncestor(this.path, path) || equalPaths)) {
-            return false;
-        }
-        return true;
-    }
-
-    private boolean includeChildren(String name) {
-        String path = afterTree.exists()
-            ? PathUtils.concat(afterTree.getPath(), name)
-            : PathUtils.concat(beforeTree.getPath(), name);
-
-        return PathUtils.isAncestor(path, this.path) ||
-                path.equals((this.path)) ||
-                deep && PathUtils.isAncestor(this.path, path);
-    }
-
-
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UuidFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UuidFilter.java?rev=1543826&r1=1543825&r2=1543826&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UuidFilter.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UuidFilter.java Wed Nov 20 14:33:19 2013
@@ -28,6 +28,7 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.observation.filter.EventGenerator.Filter;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.util.LazyValue;
 
 /**
  * {@code EventTypeFilter} filters based on the uuid of the
@@ -41,6 +42,32 @@ public class UuidFilter implements Filte
     private final NodeState after;
     private final String[] uuids;
 
+    private final LazyValue<Boolean> include = new LazyValue<Boolean>() {
+        @Override
+        protected Boolean createValue() {
+            if (uuids.length == 0) {
+                return false;
+            }
+
+            NodeState associatedParent = after.exists()
+                ? after
+                : before;
+
+            PropertyState uuidProperty = associatedParent.getProperty(JcrConstants.JCR_UUID);
+            if (uuidProperty == null) {
+                return false;
+            }
+
+            String parentUuid = uuidProperty.getValue(Type.STRING);
+            for (String uuid : uuids) {
+                if (parentUuid.equals(uuid)) {
+                    return true;
+                }
+            }
+            return false;
+        }
+    };
+
     /**
      * Create a new {@code Filter} instance that includes an event when the uuid of the
      * associated parent node matches one of the uuids of this filter.
@@ -58,22 +85,22 @@ public class UuidFilter implements Filte
 
     @Override
     public boolean includeAdd(PropertyState after) {
-        return includeByUuid();
+        return include.get();
     }
 
     @Override
     public boolean includeChange(PropertyState before, PropertyState after) {
-        return includeByUuid();
+        return include.get();
     }
 
     @Override
     public boolean includeDelete(PropertyState before) {
-        return includeByUuid();
+        return include.get();
     }
 
     @Override
     public boolean includeAdd(String name, NodeState after) {
-        return includeByUuid();
+        return include.get();
     }
 
     @Override
@@ -83,12 +110,12 @@ public class UuidFilter implements Filte
 
     @Override
     public boolean includeDelete(String name, NodeState before) {
-        return includeByUuid();
+        return include.get();
     }
 
     @Override
     public boolean includeMove(String sourcePath, String destPath, NodeState moved) {
-        return includeByUuid();
+        return include.get();
     }
 
     @Override
@@ -96,29 +123,4 @@ public class UuidFilter implements Filte
         return new UuidFilter(before, after, uuids);
     }
 
-    //------------------------------------------------------------< private >---
-
-    private boolean includeByUuid() {
-        if (uuids.length == 0) {
-            return false;
-        }
-
-        NodeState associatedParent = after.exists()
-            ? after
-            : before;
-
-        PropertyState uuidProperty = associatedParent.getProperty(JcrConstants.JCR_UUID);
-        if (uuidProperty == null) {
-            return false;
-        }
-
-        String parentUuid = uuidProperty.getValue(Type.STRING);
-        for (String uuid : uuids) {
-            if (parentUuid.equals(uuid)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
 }