jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1355002 - in /jackrabbit/oak/trunk/oak-jcr: ./ src/main/java/org/apache/jackrabbit/oak/jcr/observation/
Date Thu, 28 Jun 2012 13:20:59 GMT
Author: mduerig
Date: Thu Jun 28 13:20:58 2012
New Revision: 1355002

URL: http://svn.apache.org/viewvc?rev=1355002&view=rev
Log:
OAK-144: Implement observation
initial filter support

Modified:
    jackrabbit/oak/trunk/oak-jcr/pom.xml
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeFilter.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java

Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1355002&r1=1355001&r2=1355002&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Thu Jun 28 13:20:58 2012
@@ -86,14 +86,7 @@ org.apache.jackrabbit.test.api.query.XPa
 org.apache.jackrabbit.test.api.query.qom.ColumnTest#testExpandColumnsForNodeType
 org.apache.jackrabbit.test.api.query.qom.SelectorTest#testUnknownNodeType
 org.apache.jackrabbit.test.api.util
-org.apache.jackrabbit.test.api.observation.EventIteratorTest#testSkip
-org.apache.jackrabbit.test.api.observation.EventTest#testGetType
-org.apache.jackrabbit.test.api.observation.EventTest#testGetNodePath
 org.apache.jackrabbit.test.api.observation.EventTest#testGetUserId
-org.apache.jackrabbit.test.api.observation.NodeAddedTest#testSingleNodeAdded
-org.apache.jackrabbit.test.api.observation.NodeAddedTest#testMultipleNodeAdded1
-org.apache.jackrabbit.test.api.observation.NodeAddedTest#testMultipleNodeAdded2
-org.apache.jackrabbit.test.api.observation.NodeAddedTest#testTransientNodeAddedRemoved
 org.apache.jackrabbit.test.api.observation.NodeRemovedTest#testSingleNodeRemoved
 org.apache.jackrabbit.test.api.observation.NodeRemovedTest#testMultiNodesRemoved
 org.apache.jackrabbit.test.api.observation.NodeMovedTest#testMoveNode
@@ -103,24 +96,17 @@ org.apache.jackrabbit.test.api.observati
 org.apache.jackrabbit.test.api.observation.NodeReorderTest#testNodeReorderMove       <!--
reorder not supported -->
 org.apache.jackrabbit.test.api.observation.NodeReorderTest#testNodeReorderSameName   <!--
reorder not supported -->
 org.apache.jackrabbit.test.api.observation.NodeReorderTest#testNodeReorderSameNameWithRemove
 <!-- reorder not supported -->
-org.apache.jackrabbit.test.api.observation.PropertyChangedTest#testSinglePropertyChangedWithAdded
 org.apache.jackrabbit.test.api.observation.AddEventListenerTest#testPath
 org.apache.jackrabbit.test.api.observation.AddEventListenerTest#testNodeType
 org.apache.jackrabbit.test.api.observation.AddEventListenerTest#testIsDeepFalseNodeAdded
 org.apache.jackrabbit.test.api.observation.AddEventListenerTest#testIsDeepFalsePropertyAdded
-org.apache.jackrabbit.test.api.observation.AddEventListenerTest#testNoLocalTrue
 org.apache.jackrabbit.test.api.observation.WorkspaceOperationTest#testCopy
-org.apache.jackrabbit.test.api.observation.WorkspaceOperationTest#testRename
-org.apache.jackrabbit.test.api.observation.WorkspaceOperationTest#testMove
 org.apache.jackrabbit.test.api.observation.GetIdentifierTest#testNodeAdded
 org.apache.jackrabbit.test.api.observation.GetIdentifierTest#testNodeMoved
 org.apache.jackrabbit.test.api.observation.GetIdentifierTest#testNodeRemoved
 org.apache.jackrabbit.test.api.observation.GetIdentifierTest#testPropertyAdded
 org.apache.jackrabbit.test.api.observation.GetIdentifierTest#testPropertyChanged
 org.apache.jackrabbit.test.api.observation.GetIdentifierTest#testPropertyRemoved
-org.apache.jackrabbit.test.api.observation.GetInfoTest#testNodeAdded
-org.apache.jackrabbit.test.api.observation.GetInfoTest#testNodeRemoved
-org.apache.jackrabbit.test.api.observation.GetInfoTest#testPropertyAdded
 org.apache.jackrabbit.test.api.observation.GetUserDataTest#testSave
 org.apache.jackrabbit.test.api.observation.GetUserDataTest#testWorkspaceOperation
     </known.issues>

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeFilter.java?rev=1355002&r1=1355001&r2=1355002&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeFilter.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeFilter.java
Thu Jun 28 13:20:58 2012
@@ -16,24 +16,46 @@
  */
 package org.apache.jackrabbit.oak.jcr.observation;
 
-import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 class ChangeFilter {
-    public ChangeFilter(int eventTypes, String absPath, boolean deep, String[] uuid, String[]
nodeTypeName,
+    private final int eventTypes;
+    private final String path;
+    private final boolean deep;
+    private final String[] uuid;          // TODO implement filtering by uuid
+    private final String[] nodeTypeName;  // TODO implement filtering by nodeTypeName
+    private boolean noLocal;              // TODO implement filtering by noLocal
+
+    public ChangeFilter(int eventTypes, String path, boolean deep, String[] uuid, String[]
nodeTypeName,
             boolean noLocal) {
-        // todo implement ChangeFilter
+        this.eventTypes = eventTypes;
+        this.path = path;
+        this.deep = deep;
+        this.uuid = uuid;
+        this.nodeTypeName = nodeTypeName;
+        this.noLocal = noLocal;
+    }
+
+    public boolean include(int eventType) {
+        return (this.eventTypes & eventType) != 0;
     }
 
-    public boolean include(int eventType, String path, PropertyState propertyState) {
-        return true; // todo implement include
+    public boolean include(String path) {
+        if (!deep && !this.path.equals(path)) {
+            return false;
+        }
+        if (deep && !PathUtils.isAncestor(this.path, path)) {
+            return false;
+        }
+        return true;
     }
 
-    public boolean include(int eventType, String path, NodeState nodeState) {
-        return true; // todo implement include
+    public boolean include(int eventType, String path, NodeState associatedParentNode) {
+        return include(eventType) && include(path);
     }
 
     public boolean includeChildren(String path) {
-        return true; // todo implement includeChildren
+        return deep && PathUtils.isAncestor(this.path, path);
     }
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java?rev=1355002&r1=1355001&r2=1355002&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java
Thu Jun 28 13:20:58 2012
@@ -77,29 +77,36 @@ class ChangeProcessor extends TimerTask 
         public static final int PURGE_LIMIT = 8192;
 
         private final String path;
+        private final NodeState associatedParentNode;
 
         private int childNodeCount;
         private List<Iterator<Event>> events;
 
-        EventGeneratingNodeStateDiff(String path, List<Iterator<Event>> events)
{
+        EventGeneratingNodeStateDiff(String path, List<Iterator<Event>> events,
NodeState associatedParentNode) {
             this.path = path;
+            this.associatedParentNode = associatedParentNode;
             this.events = events;
         }
 
         public EventGeneratingNodeStateDiff() {
-            this("/", new ArrayList<Iterator<Event>>(PURGE_LIMIT));
+            this("/", new ArrayList<Iterator<Event>>(PURGE_LIMIT), null);
         }
 
         public void sendEvents() {
-            if (!events.isEmpty()) {
-                listener.onEvent(new EventIteratorAdapter(Iterators.flatten(events.iterator())));
+            Iterator<Event> eventIt = Iterators.flatten(events.iterator());
+            if (eventIt.hasNext()) {
+                listener.onEvent(new EventIteratorAdapter(eventIt));
                 events = new ArrayList<Iterator<Event>>(PURGE_LIMIT);
             }
         }
 
+        private String jcrPath() {
+            return namePathMapper.getJcrPath(path);
+        }
+
         @Override
         public void propertyAdded(PropertyState after) {
-            if (!stopped && filterRef.get().include(Event.PROPERTY_ADDED, path, after))
{
+            if (!stopped && filterRef.get().include(Event.PROPERTY_ADDED, jcrPath(),
associatedParentNode)) {
                 Event event = generatePropertyEvent(Event.PROPERTY_ADDED, path, after);
                 events.add(Iterators.singleton(event));
             }
@@ -107,7 +114,7 @@ class ChangeProcessor extends TimerTask 
 
         @Override
         public void propertyChanged(PropertyState before, PropertyState after) {
-            if (!stopped && filterRef.get().include(Event.PROPERTY_CHANGED, path,
before)) {
+            if (!stopped && filterRef.get().include(Event.PROPERTY_CHANGED, jcrPath(),
associatedParentNode)) {
                 Event event = generatePropertyEvent(Event.PROPERTY_CHANGED, path, after);
                 events.add(Iterators.singleton(event));
             }
@@ -115,7 +122,7 @@ class ChangeProcessor extends TimerTask 
 
         @Override
         public void propertyDeleted(PropertyState before) {
-            if (!stopped && filterRef.get().include(Event.PROPERTY_REMOVED, path,
before)) {
+            if (!stopped && filterRef.get().include(Event.PROPERTY_REMOVED, jcrPath(),
associatedParentNode)) {
                 Event event = generatePropertyEvent(Event.PROPERTY_REMOVED, path, before);
                 events.add(Iterators.singleton(event));
             }
@@ -123,7 +130,7 @@ class ChangeProcessor extends TimerTask 
 
         @Override
         public void childNodeAdded(String name, NodeState after) {
-            if (!stopped && filterRef.get().include(Event.NODE_ADDED, path, after))
{
+            if (!stopped && filterRef.get().include(jcrPath())) {
                 Iterator<Event> events = generateNodeEvents(Event.NODE_ADDED, path,
name, after);
                 this.events.add(events);
                 if (++childNodeCount > PURGE_LIMIT) {
@@ -134,7 +141,7 @@ class ChangeProcessor extends TimerTask 
 
         @Override
         public void childNodeDeleted(String name, NodeState before) {
-            if (!stopped && filterRef.get().include(Event.NODE_REMOVED, path, before))
{
+            if (!stopped && filterRef.get().include(jcrPath())) {
                 Iterator<Event> events = generateNodeEvents(Event.NODE_REMOVED, path,
name, before);
                 this.events.add(events);
             }
@@ -142,8 +149,9 @@ class ChangeProcessor extends TimerTask 
 
         @Override
         public void childNodeChanged(String name, NodeState before, NodeState after) {
-            if (!stopped && filterRef.get().includeChildren(path)) {
-                EventGeneratingNodeStateDiff diff = new EventGeneratingNodeStateDiff(PathUtils.concat(path,
name), events);
+            if (!stopped && filterRef.get().includeChildren(jcrPath())) {
+                EventGeneratingNodeStateDiff diff = new EventGeneratingNodeStateDiff(
+                        PathUtils.concat(path, name), events, after);
                 changeExtractor.getChanges(before, after, diff);
                 if (events.size() > PURGE_LIMIT) {
                     diff.sendEvents();
@@ -152,39 +160,59 @@ class ChangeProcessor extends TimerTask 
         }
     }
 
-    private Event generatePropertyEvent(int eventType, String path, PropertyState property)
{
-        String jcrPath = namePathMapper.getJcrPath(PathUtils.concat(path, property.getName()));
+    private Event generatePropertyEvent(int eventType, String parentPath, PropertyState property)
{
+        String jcrPath = namePathMapper.getJcrPath(PathUtils.concat(parentPath, property.getName()));
 
         // TODO support userId, identifier, info, date
         return new EventImpl(eventType, jcrPath, null, null, null, 0);
     }
 
-    private Iterator<Event> generateNodeEvents(final int eventType, String path, String
name, NodeState node) {
-        final String jcrPath = namePathMapper.getJcrPath(PathUtils.concat(path, name));
-
-        Iterator<Event> propertyEvents = Iterators.map(node.getProperties().iterator(),
+    private Iterator<Event> generateNodeEvents(int eventType, String parentPath, String
name, NodeState node) {
+        ChangeFilter filter = filterRef.get();
+        final String path = PathUtils.concat(parentPath, name);
+        String jcrPath = namePathMapper.getJcrPath(path);
+
+        Iterator<Event> nodeEvent;
+        if (filter.include(eventType)) {
+            // TODO support userId, identifier, info, date
+            Event event = new EventImpl(eventType, jcrPath, null, null, null, 0);
+            nodeEvent = singleton(event);
+        }
+        else {
+            nodeEvent = Iterators.empty();
+        }
+
+        final int propertyEventType = eventType == Event.NODE_ADDED
+            ? Event.PROPERTY_ADDED
+            : Event.PROPERTY_REMOVED;
+
+        Iterator<Event> propertyEvents;
+        if (filter.include(propertyEventType)) {
+            propertyEvents = Iterators.map(node.getProperties().iterator(),
                 new Function1<PropertyState, Event>() {
-                    int propertyEventType = eventType == Event.NODE_ADDED ? Event.PROPERTY_ADDED
: Event.PROPERTY_REMOVED;
-
                     @Override
                     public Event apply(PropertyState property) {
-                        return generatePropertyEvent(propertyEventType, jcrPath, property);
+                        return generatePropertyEvent(propertyEventType, path, property);
                     }
                 });
+        }
+        else {
+            propertyEvents = Iterators.empty();
+        }
 
-        // TODO support userId, identifier, info, date
-        final Event nodeEvent = new EventImpl(eventType, jcrPath, null, null, null, 0);
-        Iterator<Event> events = Iterators.chain(singleton(nodeEvent), propertyEvents);
-        return chain(events, chain(generateChildEvents(eventType, path, name, node)));
+        Iterator<Event> childNodeEvents = filter.includeChildren(jcrPath)
+            ? chain(generateChildEvents(eventType, path, node))
+            : Iterators.<Event>empty();
+
+        return chain(nodeEvent, propertyEvents, childNodeEvents);
     }
 
-    private Iterator<Iterator<Event>> generateChildEvents(final int eventType,
final String path, final String name,
-            NodeState node) {
+    private Iterator<Iterator<Event>> generateChildEvents(final int eventType,
final String parentPath, NodeState node) {
         return Iterators.map(node.getChildNodeEntries().iterator(),
                 new Function1<ChildNodeEntry, Iterator<Event>>() {
             @Override
             public Iterator<Event> apply(ChildNodeEntry entry) {
-                return generateNodeEvents(eventType, path, name, entry.getNodeState());
+                return generateNodeEvents(eventType, parentPath, entry.getName(), entry.getNodeState());
             }
         });
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java?rev=1355002&r1=1355001&r2=1355002&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java
Thu Jun 28 13:20:58 2012
@@ -55,7 +55,6 @@ public class ObservationManagerImpl impl
             boolean isDeep, String[] uuid, String[] nodeTypeName, boolean noLocal)
             throws RepositoryException {
 
-        // TODO: support noLocal flag!?
         ChangeProcessor processor = processors.get(listener);
         if (processor == null) {
             ChangeExtractor extractor = sessionDelegate.getChangeExtractor();



Mime
View raw message