jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1355257 - in /jackrabbit/oak/trunk/oak-jcr: pom.xml src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeFilter.java src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java
Date Fri, 29 Jun 2012 08:03:33 GMT
Author: mduerig
Date: Fri Jun 29 08:03:31 2012
New Revision: 1355257

URL: http://svn.apache.org/viewvc?rev=1355257&view=rev
Log:
OAK-144: Implement observation
fix filter for (non) deep items

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

Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1355257&r1=1355256&r2=1355257&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Fri Jun 29 08:03:31 2012
@@ -94,9 +94,8 @@ 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.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#testNoLocalTrue
 org.apache.jackrabbit.test.api.observation.WorkspaceOperationTest#testCopy              
     <!-- OAK-156 -->
 org.apache.jackrabbit.test.api.observation.GetIdentifierTest#testNodeAdded
 org.apache.jackrabbit.test.api.observation.GetIdentifierTest#testNodeMoved

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=1355257&r1=1355256&r2=1355257&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
Fri Jun 29 08:03:31 2012
@@ -42,10 +42,11 @@ class ChangeFilter {
     }
 
     public boolean include(String path) {
-        if (!deep && !this.path.equals(path)) {
+        boolean equalPaths = this.path.equals(path);
+        if (!deep && !equalPaths) {
             return false;
         }
-        if (deep && !PathUtils.isAncestor(this.path, path)) {
+        if (deep && !(PathUtils.isAncestor(this.path, path) || equalPaths)) {
             return false;
         }
         return true;

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=1355257&r1=1355256&r2=1355257&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
Fri Jun 29 08:03:31 2012
@@ -130,7 +130,7 @@ class ChangeProcessor extends TimerTask 
 
         @Override
         public void childNodeAdded(String name, NodeState after) {
-            if (!stopped && filterRef.get().include(jcrPath())) {
+            if (!stopped && filterRef.get().includeChildren(jcrPath())) {
                 Iterator<Event> events = generateNodeEvents(Event.NODE_ADDED, path,
name, after);
                 this.events.add(events);
                 if (++childNodeCount > PURGE_LIMIT) {
@@ -141,7 +141,7 @@ class ChangeProcessor extends TimerTask 
 
         @Override
         public void childNodeDeleted(String name, NodeState before) {
-            if (!stopped && filterRef.get().include(jcrPath())) {
+            if (!stopped && filterRef.get().includeChildren(jcrPath())) {
                 Iterator<Event> events = generateNodeEvents(Event.NODE_REMOVED, path,
name, before);
                 this.events.add(events);
             }
@@ -158,63 +158,65 @@ class ChangeProcessor extends TimerTask 
                 }
             }
         }
-    }
-
-    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(int eventType, String parentPath, String
name, NodeState node) {
-        ChangeFilter filter = filterRef.get();
-        final String path = PathUtils.concat(parentPath, name);
-        String jcrPath = namePathMapper.getJcrPath(path);
+        private Event generatePropertyEvent(int eventType, String parentPath, PropertyState
property) {
+            String jcrPath = namePathMapper.getJcrPath(PathUtils.concat(parentPath, property.getName()));
 
-        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();
+            return new EventImpl(eventType, jcrPath, null, null, null, 0);
         }
 
-        final int propertyEventType = eventType == Event.NODE_ADDED
-            ? Event.PROPERTY_ADDED
-            : Event.PROPERTY_REMOVED;
+        private Iterator<Event> generateNodeEvents(int eventType, String parentPath,
String name, NodeState node) {
+            ChangeFilter filter = filterRef.get();
+            final String path = PathUtils.concat(parentPath, name);
+            String jcrParentPath = namePathMapper.getJcrPath(parentPath);
+            String jcrPath = namePathMapper.getJcrPath(path);
+
+            Iterator<Event> nodeEvent;
+            if (filter.include(eventType, jcrParentPath, associatedParentNode)) {
+                // 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, jcrPath, associatedParentNode)) {
+                propertyEvents = Iterators.map(node.getProperties().iterator(),
+                    new Function1<PropertyState, Event>() {
+                        @Override
+                        public Event apply(PropertyState property) {
+                            return generatePropertyEvent(propertyEventType, path, property);
+                        }
+                    });
+            }
+            else {
+                propertyEvents = Iterators.empty();
+            }
+
+            Iterator<Event> childNodeEvents = !stopped && filter.includeChildren(jcrPath)
+                    ? chain(generateChildEvents(eventType, path, node))
+                    : Iterators.<Event>empty();
+
+            return chain(nodeEvent, propertyEvents, childNodeEvents);
+        }
 
-        Iterator<Event> propertyEvents;
-        if (filter.include(propertyEventType)) {
-            propertyEvents = Iterators.map(node.getProperties().iterator(),
-                new Function1<PropertyState, Event>() {
+        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 Event apply(PropertyState property) {
-                        return generatePropertyEvent(propertyEventType, path, property);
+                    public Iterator<Event> apply(ChildNodeEntry entry) {
+                        return generateNodeEvents(eventType, parentPath, entry.getName(),
entry.getNodeState());
                     }
                 });
         }
-        else {
-            propertyEvents = Iterators.empty();
-        }
 
-        Iterator<Event> childNodeEvents = !stopped && 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 parentPath, NodeState node) {
-        return Iterators.map(node.getChildNodeEntries().iterator(),
-                new Function1<ChildNodeEntry, Iterator<Event>>() {
-            @Override
-            public Iterator<Event> apply(ChildNodeEntry entry) {
-                return generateNodeEvents(eventType, parentPath, entry.getName(), entry.getNodeState());
-            }
-        });
     }
 
 }



Mime
View raw message