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 ju...@apache.org on 2014/01/28 17:06:32 UTC
svn commit: r1562102 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation:
./ filter/ handler/
Author: jukka
Date: Tue Jan 28 16:06:31 2014
New Revision: 1562102
URL: http://svn.apache.org/r1562102
Log:
OAK-1133: Observation listener PLUS
Restore the listener interface that I removed in r1561710, renamed to
a handler for similarity with other callback interfaces like
org.xml.sax.ContentHandler and to avoid confusion with JCR's EventListener.
Also introduced a nodeReordered() method for more fine-grained handling
of reorderings.
Adjusted the EventFilter.includeReorder() method to also take a destName
argument so it can be included in the filtering decisions. For example
reorderings to before hidden or non-accessible nodes should probably not
be reported.
Include a FilteredHandler class that hides the event filtering mechanism
below the ChangeHandler interface.
Added:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/handler/
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/handler/ChangeHandler.java (with props)
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/handler/FilteredHandler.java (with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventGenerator.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/ACFilter.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/ConstantFilter.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/EventFilter.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/EventTypeFilter.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/Filters.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/GlobbingPathFilter.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UniversalFilter.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/VisibleFilter.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventGenerator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventGenerator.java?rev=1562102&r1=1562101&r2=1562102&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventGenerator.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventGenerator.java Tue Jan 28 16:06:31 2014
@@ -278,11 +278,12 @@ public class EventGenerator implements E
if (a != b && beforeName.equals(afterName)) {
beforeNames.set(b, beforeNames.get(a));
beforeNames.set(a, beforeName);
+ String destName = beforeNames.get(a + 1);
NodeState afterChild = this.after.getChildNode(afterName);
- if (filter.includeReorder(afterName, afterChild)) {
+ if (filter.includeReorder(destName, afterName, afterChild)) {
Map<String, String> info = ImmutableMap.of(
- "srcChildRelPath", context.getJcrName(beforeName),
- "destChildRelPath", context.getJcrName(beforeNames.get(a + 1)));
+ "srcChildRelPath", context.getJcrName(afterName),
+ "destChildRelPath", context.getJcrName(destName));
ImmutableTree tree = new ImmutableTree(afterTree, afterName, afterChild);
events.add(new EventImpl(context, NODE_MOVED, tree, info));
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/ACFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/ACFilter.java?rev=1562102&r1=1562101&r2=1562102&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/ACFilter.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/ACFilter.java Tue Jan 28 16:06:31 2014
@@ -93,11 +93,13 @@ public class ACFilter implements EventFi
@Override
public boolean includeMove(String sourcePath, String name, NodeState moved) {
+ // TODO: check access to the source path, it might not be accessible
return treePermission.getChildPermission(name, moved).canRead();
}
@Override
- public boolean includeReorder(String name, NodeState reordered) {
+ public boolean includeReorder(String destName, String name, NodeState reordered) {
+ // TODO: check access to the dest name, it might not be accessible
return treePermission.getChildPermission(name, reordered).canRead();
}
@@ -105,4 +107,5 @@ public class ACFilter implements EventFi
public EventFilter create(String name, NodeState before, NodeState after) {
return new ACFilter(treePermission.getChildPermission(name, after));
}
+
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/ConstantFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/ConstantFilter.java?rev=1562102&r1=1562101&r2=1562102&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/ConstantFilter.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/ConstantFilter.java Tue Jan 28 16:06:31 2014
@@ -66,7 +66,7 @@ public class ConstantFilter implements E
}
@Override
- public boolean includeReorder(String name, NodeState reordered) {
+ public boolean includeReorder(String destName, String name, NodeState reordered) {
return include;
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/EventFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/EventFilter.java?rev=1562102&r1=1562101&r2=1562102&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/EventFilter.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/EventFilter.java Tue Jan 28 16:06:31 2014
@@ -77,11 +77,12 @@ public interface EventFilter {
/**
* Include a reordered node
+ * @param destName name of the {@code orderBefore()} destination node
* @param name name of the reordered node
* @param reordered the reordered node
* @return {@code true} if the node should be included
*/
- boolean includeReorder(String name, NodeState reordered);
+ boolean includeReorder(String destName, String name, NodeState reordered);
/**
* Factory for creating a filter instance for the given child node
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/EventTypeFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/EventTypeFilter.java?rev=1562102&r1=1562101&r2=1562102&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/EventTypeFilter.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/EventTypeFilter.java Tue Jan 28 16:06:31 2014
@@ -77,7 +77,7 @@ public class EventTypeFilter implements
}
@Override
- public boolean includeReorder(String name, NodeState reordered) {
+ public boolean includeReorder(String destName, String name, NodeState reordered) {
return includeByEvent(Event.NODE_MOVED);
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/Filters.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/Filters.java?rev=1562102&r1=1562101&r2=1562102&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/Filters.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/Filters.java Tue Jan 28 16:06:31 2014
@@ -152,9 +152,9 @@ public final class Filters {
}
@Override
- public boolean includeReorder(String name, NodeState reordered) {
+ public boolean includeReorder(String destName, String name, NodeState reordered) {
for (EventFilter filter : filters) {
- if (filter.includeReorder(name, reordered)) {
+ if (filter.includeReorder(destName, name, reordered)) {
return true;
}
}
@@ -251,9 +251,9 @@ public final class Filters {
}
@Override
- public boolean includeReorder(String name, NodeState reordered) {
+ public boolean includeReorder(String destName, String name, NodeState reordered) {
for (EventFilter filter : filters) {
- if (!filter.includeReorder(name, reordered)) {
+ if (!filter.includeReorder(destName, name, reordered)) {
return false;
}
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/GlobbingPathFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/GlobbingPathFilter.java?rev=1562102&r1=1562101&r2=1562102&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/GlobbingPathFilter.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/GlobbingPathFilter.java Tue Jan 28 16:06:31 2014
@@ -102,7 +102,7 @@ public class GlobbingPathFilter implemen
}
@Override
- public boolean includeReorder(String name, NodeState reordered) {
+ public boolean includeReorder(String destName, String name, NodeState reordered) {
return includeItem(name);
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UniversalFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UniversalFilter.java?rev=1562102&r1=1562101&r2=1562102&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UniversalFilter.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/UniversalFilter.java Tue Jan 28 16:06:31 2014
@@ -141,7 +141,7 @@ public class UniversalFilter implements
}
@Override
- public boolean includeReorder(String name, NodeState reordered) {
+ public boolean includeReorder(String destName, String name, NodeState reordered) {
return predicate.apply(selector.select(this, name, MISSING_NODE, reordered));
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/VisibleFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/VisibleFilter.java?rev=1562102&r1=1562101&r2=1562102&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/VisibleFilter.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/filter/VisibleFilter.java Tue Jan 28 16:06:31 2014
@@ -20,6 +20,7 @@
package org.apache.jackrabbit.oak.plugins.observation.filter;
import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.spi.state.NodeState;
/**
@@ -58,12 +59,17 @@ public class VisibleFilter implements Ev
@Override
public boolean includeMove(String sourcePath, String name, NodeState moved) {
+ for (String element : PathUtils.elements(sourcePath)) {
+ if (!isVisible(element)) {
+ return false;
+ }
+ }
return isVisible(name);
}
@Override
- public boolean includeReorder(String name, NodeState reordered) {
- return isVisible(name);
+ public boolean includeReorder(String destName, String name, NodeState reordered) {
+ return isVisible(destName) && isVisible(name);
}
@Override
Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/handler/ChangeHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/handler/ChangeHandler.java?rev=1562102&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/handler/ChangeHandler.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/handler/ChangeHandler.java Tue Jan 28 16:06:31 2014
@@ -0,0 +1,105 @@
+/*
+ * 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.plugins.observation.handler;
+
+import javax.annotation.CheckForNull;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+/**
+ * Handler of content changes. Used to decouple processing of changes
+ * from the content diff logic that detects them.
+ * <p>
+ * As the content diff recurses down the content tree, it will call the
+ * {@link #getChildHandler(String, NodeState, NodeState)} method to
+ * specialize the handler instance for each node under which changes are
+ * detected. The other handler methods always apply to the properties
+ * and direct children of the node for which that handler instance is
+ * specialized. The handler is expected to keep track of contextual
+ * information like the path or identifier of the current node based on
+ * the sequence of those specialization calls.
+ * <p>
+ * All names and paths passed to handler methods use unmapped Oak names.
+ */
+public interface ChangeHandler {
+
+ /**
+ * Returns a handler of changes within the given child node, or
+ * {@code null} if changes within that child are not to be processed.
+ *
+ * @param name name of the child node
+ * @param before before state of the child node, possibly non-existent
+ * @param after after state of the child node, possibly non-existent
+ * @return handler of changes within the child node, or {@code null}
+ */
+ @CheckForNull
+ ChangeHandler getChildHandler(
+ String name, NodeState before, NodeState after);
+
+ /**
+ * Notification for an added property
+ * @param after added property
+ */
+ void propertyAdded(PropertyState after);
+
+ /**
+ * Notification for a changed property
+ * @param before property before the change
+ * @param after property after the change
+ */
+ void propertyChanged(PropertyState before, PropertyState after);
+
+ /**
+ * Notification for a deleted property
+ * @param before deleted property
+ */
+ void propertyDeleted(PropertyState before);
+
+ /**
+ * Notification for an added node
+ * @param name name of the node
+ * @param after added node
+ */
+ void nodeAdded(String name, NodeState after);
+
+ /**
+ * Notification for a deleted node
+ * @param name name of the deleted node
+ * @param before deleted node
+ */
+ void nodeDeleted(String name, NodeState before);
+
+ /**
+ * Notification for a moved node
+ * @param sourcePath source of the moved node
+ * @param name name of the moved node
+ * @param moved moved node
+ */
+ void nodeMoved(String sourcePath, String name, NodeState moved);
+
+ /**
+ * Notification for a reordered node
+ * @param destName name of the {@code orderBefore()} destination node
+ * @param name name of the moved node
+ * @param moved moved node
+ */
+ void nodeReordered(String destName, String name, NodeState reordered);
+
+}
Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/handler/ChangeHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/handler/FilteredHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/handler/FilteredHandler.java?rev=1562102&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/handler/FilteredHandler.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/handler/FilteredHandler.java Tue Jan 28 16:06:31 2014
@@ -0,0 +1,105 @@
+/*
+ * 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.plugins.observation.handler;
+
+import javax.annotation.CheckForNull;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.plugins.observation.filter.EventFilter;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+/**
+ * Filtered change handler. This decorator class applies an {@link EventFilter}
+ * on all detected changes, and forwards the filtered changes to a given
+ * delegate change handler.
+ */
+public class FilteredHandler implements ChangeHandler {
+
+ private final EventFilter filter;
+
+ private final ChangeHandler handler;
+
+ public FilteredHandler(EventFilter filter, ChangeHandler handler) {
+ this.filter = filter;
+ this.handler = handler;
+ }
+
+ @Override @CheckForNull
+ public ChangeHandler getChildHandler(
+ String name, NodeState before, NodeState after) {
+ EventFilter f = filter.create(name, before, after);
+ if (f != null) {
+ ChangeHandler h = handler.getChildHandler(name, before, after);
+ if (h != null) {
+ return new FilteredHandler(f, h);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void propertyAdded(PropertyState after) {
+ if (filter.includeAdd(after)) {
+ handler.propertyAdded(after);
+ }
+ }
+
+ @Override
+ public void propertyChanged(PropertyState before, PropertyState after) {
+ if (filter.includeChange(before, after)) {
+ handler.propertyChanged(before, after);
+ }
+ }
+
+ @Override
+ public void propertyDeleted(PropertyState before) {
+ if (filter.includeDelete(before)) {
+ handler.propertyDeleted(before);
+ }
+ }
+
+ @Override
+ public void nodeAdded(String name, NodeState after) {
+ if (filter.includeAdd(name, after)) {
+ handler.nodeAdded(name, after);
+ }
+ }
+
+ @Override
+ public void nodeDeleted(String name, NodeState before) {
+ if (filter.includeDelete(name, before)) {
+ handler.nodeDeleted(name, before);
+ }
+ }
+
+ @Override
+ public void nodeMoved(String sourcePath, String name, NodeState moved) {
+ if (filter.includeMove(sourcePath, name, moved)) {
+ handler.nodeMoved(sourcePath, name, moved);
+ }
+ }
+
+ @Override
+ public void nodeReordered(String destName, String name, NodeState reordered) {
+ if (filter.includeReorder(destName, name, reordered)) {
+ handler.nodeReordered(destName, name, reordered);
+ }
+ }
+
+}
Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/handler/FilteredHandler.java
------------------------------------------------------------------------------
svn:eol-style = native