jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1499383 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/
Date Wed, 03 Jul 2013 13:11:46 GMT
Author: mduerig
Date: Wed Jul  3 13:11:45 2013
New Revision: 1499383

URL: http://svn.apache.org/r1499383
Log:
OAK-144 Implement Observation
Use Oak names and paths in EventFilter

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventImpl.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/EventFilter.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ObservationManagerImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventImpl.java?rev=1499383&r1=1499382&r2=1499383&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventImpl.java
Wed Jul  3 13:11:45 2013
@@ -32,7 +32,7 @@ import org.apache.jackrabbit.api.observa
 public class EventImpl implements JackrabbitEvent {
 
     private final int type;
-    private final String path;
+    private final String jcrPath;
     private final String userID;
     private final String identifier;
     private final Map<?, ?> info;
@@ -41,10 +41,10 @@ public class EventImpl implements Jackra
     private final boolean external;
 
     public EventImpl(
-            int type, String path, String userID, String identifier,
+            int type, String jcrPath, String userID, String identifier,
             Map<?, ?> info, long date, String userData, boolean external) {
         this.type = type;
-        this.path = path;
+        this.jcrPath = jcrPath;
         this.userID = userID;
         this.identifier = identifier;
         this.info = info == null ? Collections.emptyMap() : info;
@@ -60,7 +60,7 @@ public class EventImpl implements Jackra
 
     @Override
     public String getPath() throws RepositoryException {
-        return path;
+        return jcrPath;
     }
 
     @Override
@@ -106,7 +106,7 @@ public class EventImpl implements Jackra
         return date == that.date && type == that.type &&
                 (identifier == null ? that.identifier == null : identifier.equals(that.identifier))
&&
                 (info == null ? that.info == null : info.equals(that.info)) &&
-                (path == null ? that.path == null : path.equals(that.path)) &&
+                (jcrPath == null ? that.jcrPath == null : jcrPath.equals(that.jcrPath)) &&
                 (userID == null ? that.userID == null : userID.equals(that.userID)) &&
                 (userData == null ? that.userData == null : userData.equals(that.userData))
&&
                 external == that.external;
@@ -116,7 +116,7 @@ public class EventImpl implements Jackra
     @Override
     public final int hashCode() {
         int result = type;
-        result = 31 * result + (path == null ? 0 : path.hashCode());
+        result = 31 * result + (jcrPath == null ? 0 : jcrPath.hashCode());
         result = 31 * result + (userID == null ? 0 : userID.hashCode());
         result = 31 * result + (identifier == null ? 0 : identifier.hashCode());
         result = 31 * result + (info == null ? 0 : info.hashCode());
@@ -129,7 +129,7 @@ public class EventImpl implements Jackra
     public String toString() {
         return "EventImpl{" +
                 "type=" + type +
-                ", path='" + path + '\'' +
+                ", jcrPath='" + jcrPath + '\'' +
                 ", userID='" + userID + '\'' +
                 ", identifier='" + identifier + '\'' +
                 ", info=" + info +

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=1499383&r1=1499382&r2=1499383&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
Wed Jul  3 13:11:45 2013
@@ -252,13 +252,9 @@ class ChangeProcessor implements Runnabl
             }
         }
 
-        private String jcrPath() {
-            return namePathMapper.getJcrPath(path);
-        }
-
         @Override
         public boolean propertyAdded(PropertyState after) {
-            if (filterRef.get().include(Event.PROPERTY_ADDED, jcrPath(), afterParentNode))
{
+            if (filterRef.get().include(Event.PROPERTY_ADDED, path, afterParentNode)) {
                 Event event = generatePropertyEvent(Event.PROPERTY_ADDED, path, after, getAfterId());
                 events.add(Iterators.singletonIterator(event));
             }
@@ -267,7 +263,7 @@ class ChangeProcessor implements Runnabl
 
         @Override
         public boolean propertyChanged(PropertyState before, PropertyState after) {
-            if (filterRef.get().include(Event.PROPERTY_CHANGED, jcrPath(), afterParentNode))
{
+            if (filterRef.get().include(Event.PROPERTY_CHANGED, path, afterParentNode)) {
                 Event event = generatePropertyEvent(Event.PROPERTY_CHANGED, path, after,
getAfterId());
                 events.add(Iterators.singletonIterator(event));
             }
@@ -276,7 +272,7 @@ class ChangeProcessor implements Runnabl
 
         @Override
         public boolean propertyDeleted(PropertyState before) {
-            if (filterRef.get().include(Event.PROPERTY_REMOVED, jcrPath(), afterParentNode))
{
+            if (filterRef.get().include(Event.PROPERTY_REMOVED, path, afterParentNode)) {
                 Event event = generatePropertyEvent(Event.PROPERTY_REMOVED, path, before,
getBeforeId());
                 events.add(Iterators.singletonIterator(event));
             }
@@ -285,7 +281,7 @@ class ChangeProcessor implements Runnabl
 
         @Override
         public boolean childNodeAdded(String name, NodeState after) {
-            if (filterRef.get().includeChildren(jcrPath())) {
+            if (filterRef.get().includeChildren(path)) {
                 Iterator<Event> events = generateNodeEvents(Event.NODE_ADDED, path,
name,
                         after, afterParentNode, getAfterId(after, name));
                 this.events.add(events);
@@ -298,7 +294,7 @@ class ChangeProcessor implements Runnabl
 
         @Override
         public boolean childNodeDeleted(String name, NodeState before) {
-            if (filterRef.get().includeChildren(jcrPath())) {
+            if (filterRef.get().includeChildren(path)) {
                 Iterator<Event> events = generateNodeEvents(Event.NODE_REMOVED, path,
name,
                         before, beforeParentNode, getBeforeId(before, name));
                 this.events.add(events);
@@ -314,7 +310,7 @@ class ChangeProcessor implements Runnabl
         @Nonnull
         @Override
         public RecursingNodeStateDiff createChildDiff(String name, NodeState before, NodeState
after) {
-            if (filterRef.get().includeChildren(jcrPath())) {
+            if (filterRef.get().includeChildren(path)) {
                 EventGeneratingNodeStateDiff diff = new EventGeneratingNodeStateDiff(
                         changes, PathUtils.concat(path, name), events, before, after, this,
name);
                 return VisibleDiff.wrap(diff);
@@ -323,10 +319,10 @@ class ChangeProcessor implements Runnabl
             }
         }
 
-        private EventImpl createEvent(int eventType, String jcrPath, String id) {
+        private EventImpl createEvent(int eventType, String path, String id) {
             // TODO support info
             return new EventImpl(
-                    eventType, jcrPath, changes.getUserId(),
+                    eventType, namePathMapper.getJcrPath(path), changes.getUserId(),
                     id, null, changes.getDate(), userDataRef.get(),
                     changes.isExternal());
         }
@@ -379,20 +375,17 @@ class ChangeProcessor implements Runnabl
         }
 
         private Event generatePropertyEvent(int eventType, String parentPath, PropertyState
property, String id) {
-            String jcrPath = namePathMapper.getJcrPath(PathUtils.concat(parentPath, property.getName()));
-            return createEvent(eventType, jcrPath, id);
+            String path = PathUtils.concat(parentPath, property.getName());
+            return createEvent(eventType, path, id);
         }
 
         private Iterator<Event> generateNodeEvents(int eventType, String parentPath,
String childName,
                 NodeState node, NodeState parentNode, final String id) {
             EventFilter filter = filterRef.get();
             final String path = PathUtils.concat(parentPath, childName);
-            String jcrParentPath = namePathMapper.getJcrPath(parentPath);
-            String jcrPath = namePathMapper.getJcrPath(path);
-
             Iterator<Event> nodeEvent;
-            if (filter.include(eventType, jcrParentPath, parentNode)) {
-                Event event = createEvent(eventType, jcrPath, id);
+            if (filter.include(eventType, parentPath, parentNode)) {
+                Event event = createEvent(eventType, path, id);
                 nodeEvent = Iterators.singletonIterator(event);
             } else {
                 nodeEvent = Iterators.emptyIterator();
@@ -403,7 +396,7 @@ class ChangeProcessor implements Runnabl
                     : Event.PROPERTY_REMOVED;
 
             Iterator<Event> propertyEvents;
-            if (filter.include(propertyEventType, jcrPath, parentNode)) {
+            if (filter.include(propertyEventType, path, parentNode)) {
                 propertyEvents = Iterators.transform(
                         Iterators.filter(
                                 node.getProperties().iterator(),
@@ -423,7 +416,7 @@ class ChangeProcessor implements Runnabl
                 propertyEvents = Iterators.emptyIterator();
             }
 
-            Iterator<Event> childNodeEvents = filter.includeChildren(jcrPath)
+            Iterator<Event> childNodeEvents = filter.includeChildren(path)
                     ? Iterators.concat(generateChildEvents(eventType, path, node, id))
                     : Iterators.<Event>emptyIterator();
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/EventFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/EventFilter.java?rev=1499383&r1=1499382&r2=1499383&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/EventFilter.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/EventFilter.java
Wed Jul  3 13:11:45 2013
@@ -20,7 +20,6 @@ package org.apache.jackrabbit.oak.jcr.ob
 
 import static com.google.common.base.Objects.toStringHelper;
 
-import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.NoSuchNodeTypeException;
@@ -31,7 +30,6 @@ import org.apache.jackrabbit.oak.api.Tre
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.core.ReadOnlyTree;
-import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
@@ -40,7 +38,6 @@ import org.apache.jackrabbit.oak.spi.sta
  */
 class EventFilter {
     private final ReadOnlyNodeTypeManager ntMgr;
-    private final NamePathMapper namePathMapper;
     private final int eventTypes;
     private final String path;
     private final boolean deep;
@@ -50,8 +47,8 @@ class EventFilter {
 
     /**
      * Create a new instance of a filter for a certain criterion
+     *
      * @param ntMgr
-     * @param namePathMapper
      * @param eventTypes  event types to include encoded as a bit mask
      * @param path        path to include
      * @param deep        {@code true} if descendants of {@code path} should be included.
{@code false} otherwise.
@@ -63,18 +60,14 @@ class EventFilter {
      * @see javax.jcr.observation.ObservationManager#addEventListener(javax.jcr.observation.EventListener,
      * int, String, boolean, String[], String[], boolean)
      */
-    public EventFilter(ReadOnlyNodeTypeManager ntMgr,
-            NamePathMapper namePathMapper, int eventTypes,
-            String path, boolean deep, String[] uuids,
-            String[] nodeTypeName, boolean noLocal)
-            throws NoSuchNodeTypeException, RepositoryException {
+    public EventFilter(ReadOnlyNodeTypeManager ntMgr, int eventTypes, String path, boolean
deep, String[] uuids,
+            String[] nodeTypeName, boolean noLocal) {
         this.ntMgr = ntMgr;
-        this.namePathMapper = namePathMapper;
         this.eventTypes = eventTypes;
         this.path = path;
         this.deep = deep;
         this.uuids = uuids;
-        this.nodeTypeOakName = validateNodeTypeNames(nodeTypeName);
+        this.nodeTypeOakName = nodeTypeName;
         this.noLocal = noLocal;
     }
 
@@ -98,12 +91,9 @@ class EventFilter {
      * @return  {@code true} if the children of {@code path} could be matched by this filter
      */
     public boolean includeChildren(String path) {
-        String thisOakPath = namePathMapper.getOakPath(this.path);
-        String thatOakPath = namePathMapper.getOakPath(path);
-
-        return PathUtils.isAncestor(thatOakPath, thisOakPath) ||
-                path.equals(thisOakPath) ||
-                deep && PathUtils.isAncestor(thisOakPath, thatOakPath);
+        return PathUtils.isAncestor(path, this.path) ||
+                path.equals((this.path)) ||
+                deep && PathUtils.isAncestor(this.path, path);
     }
 
     /**
@@ -139,15 +129,12 @@ class EventFilter {
     }
 
     private boolean include(String path) {
-        String thisOakPath = namePathMapper.getOakPath(this.path);
-        String thatOakPath = namePathMapper.getOakPath(path);
-
-        boolean equalPaths = thisOakPath.equals(thatOakPath);
+        boolean equalPaths = this.path.equals(path);
         if (!deep && !equalPaths) {
             return false;
         }
 
-        if (deep && !(PathUtils.isAncestor(thisOakPath, thatOakPath) || equalPaths))
{
+        if (deep && !(PathUtils.isAncestor(this.path, path) || equalPaths)) {
             return false;
         }
         return true;
@@ -197,27 +184,4 @@ class EventFilter {
         return false;
     }
 
-    /**
-     * Validates the given node type names.
-     *
-     * @param nodeTypeNames the node type names.
-     * @return the node type names as oak names.
-     * @throws javax.jcr.nodetype.NoSuchNodeTypeException if one of the node type names refers
to
-     *                                 an non-existing node type.
-     * @throws javax.jcr.RepositoryException     if an error occurs while reading from the
-     *                                 node type manager.
-     */
-    @CheckForNull
-    private String[] validateNodeTypeNames(@Nullable String[] nodeTypeNames)
-            throws NoSuchNodeTypeException, RepositoryException {
-        if (nodeTypeNames == null) {
-            return null;
-        }
-        String[] oakNames = new String[nodeTypeNames.length];
-        for (int i = 0; i < nodeTypeNames.length; i++) {
-            ntMgr.getNodeType(nodeTypeNames[i]);
-            oakNames[i] = namePathMapper.getOakName(nodeTypeNames[i]);
-        }
-        return oakNames;
-    }
 }

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=1499383&r1=1499382&r2=1499383&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
Wed Jul  3 13:11:45 2013
@@ -24,8 +24,11 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.observation.EventJournal;
 import javax.jcr.observation.EventListener;
 import javax.jcr.observation.EventListenerIterator;
@@ -99,8 +102,8 @@ public class ObservationManagerImpl impl
     @Override
     public synchronized void addEventListener(EventListener listener, int eventTypes, String
absPath,
             boolean isDeep, String[] uuid, String[] nodeTypeName, boolean noLocal) throws
RepositoryException {
-        EventFilter filter = new EventFilter(ntMgr, namePathMapper, eventTypes,
-                absPath, isDeep, uuid, nodeTypeName, noLocal);
+        EventFilter filter = new EventFilter(ntMgr, eventTypes, oakPath(absPath), isDeep,
+                uuid, validateNodeTypeNames(nodeTypeName), noLocal);
         ChangeProcessor processor = processors.get(listener);
         if (processor == null) {
             log.info(OBSERVATION, "Registering event listener {} with filter {}", listener,
filter);
@@ -160,4 +163,34 @@ public class ObservationManagerImpl impl
         throw new UnsupportedRepositoryOperationException();
     }
 
+    //------------------------------------------------------------< private >---
+
+    private String oakPath(String jcrPath) {
+        return namePathMapper.getOakPath(jcrPath);
+    }
+
+    /**
+     * Validates the given node type names.
+     *
+     * @param nodeTypeNames the node type names.
+     * @return the node type names as oak names.
+     * @throws javax.jcr.nodetype.NoSuchNodeTypeException if one of the node type names refers
to
+     *                                 an non-existing node type.
+     * @throws javax.jcr.RepositoryException     if an error occurs while reading from the
+     *                                 node type manager.
+     */
+    @CheckForNull
+    private String[] validateNodeTypeNames(@Nullable String[] nodeTypeNames)
+            throws NoSuchNodeTypeException, RepositoryException {
+        if (nodeTypeNames == null) {
+            return null;
+        }
+        String[] oakNames = new String[nodeTypeNames.length];
+        for (int i = 0; i < nodeTypeNames.length; i++) {
+            ntMgr.getNodeType(nodeTypeNames[i]);
+            oakNames[i] = namePathMapper.getOakName(nodeTypeNames[i]);
+        }
+        return oakNames;
+    }
+
 }



Mime
View raw message