jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1561247 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: plugins/observation/EventImpl.java plugins/observation/JcrListener.java spi/commit/CommitInfo.java
Date Sat, 25 Jan 2014 02:29:57 GMT
Author: jukka
Date: Sat Jan 25 02:29:56 2014
New Revision: 1561247

URL: http://svn.apache.org/r1561247
Log:
OAK-1332: Large number of changes to the same node can fill observation queue

Postpone the construction of event paths and identifiers to when they are
actually requested. Currently this requires holding references to the
ImmutableTree instances and thus quite a bit of extra memory, but further
refactoring should make it possible to avoid the tree references.

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/JcrListener.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitInfo.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=1561247&r1=1561246&r2=1561247&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
Sat Jan 25 02:29:56 2014
@@ -18,9 +18,14 @@
  */
 package org.apache.jackrabbit.oak.plugins.observation;
 
+import static java.util.Collections.emptyMap;
+
 import java.util.Map;
 
 import org.apache.jackrabbit.api.observation.JackrabbitEvent;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.core.ImmutableTree;
+import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
 
 import com.google.common.base.Objects;
 
@@ -31,19 +36,32 @@ final class EventImpl implements Jackrab
 
     private final EventContext context;
     private final int type;
-    private final String path;
-    private final String identifier;
+    private final ImmutableTree tree;
+    private final String name;
     private final Map<?, ?> info;
 
-    EventImpl(EventContext context,
-            int type, String path, String identifier, Map<?, ?> info) {
+    private EventImpl(
+            EventContext context, int type,
+            ImmutableTree tree, String name, Map<?, ?> info) {
         this.context = context;
         this.type = type;
-        this.path = path;
-        this.identifier = identifier;
+        this.tree = tree;
+        this.name = name;
         this.info = info;
     }
 
+    EventImpl(EventContext context, int type, ImmutableTree tree, String name) {
+        this(context, type, tree, name, emptyMap());
+    }
+
+    EventImpl(EventContext context, int type, ImmutableTree tree, Map<?, ?> info) {
+        this(context, type, tree, null, info);
+    }
+
+    EventImpl(EventContext context, int type, ImmutableTree tree) {
+        this(context, type, tree, null, emptyMap());
+    }
+
     @Override
     public int getType() {
         return type;
@@ -51,6 +69,10 @@ final class EventImpl implements Jackrab
 
     @Override
     public String getPath() {
+        String path = tree.getPath();
+        if (name != null) {
+            path = PathUtils.concat(path, name);
+        }
         return context.getJcrPath(path);
     }
 
@@ -61,7 +83,7 @@ final class EventImpl implements Jackrab
 
     @Override
     public String getIdentifier() {
-        return identifier;
+        return IdentifierManager.getIdentifier(tree);
     }
 
     @Override
@@ -92,11 +114,11 @@ final class EventImpl implements Jackrab
             return true;
         } else if (object instanceof EventImpl) {
             EventImpl that = (EventImpl) object;
-            return Objects.equal(this.context, that.context)
-                    && this.type == that.type
-                    && Objects.equal(this.path, that.path)
-                    && Objects.equal(this.identifier, that.identifier)
-                    && Objects.equal(this.info, that.info);
+            return this.type == that.type
+                    && context.equals(that.context)
+                    && Objects.equal(this.info, that.info)
+                    && getPath().equals(that.getPath())
+                    && getIdentifier().equals(that.getIdentifier());
         } else {
             return false;
         }
@@ -104,15 +126,15 @@ final class EventImpl implements Jackrab
 
     @Override
     public int hashCode() {
-        return Objects.hashCode(context, type, path, identifier, info);
+        return Objects.hashCode(context, type, info, getPath(), getIdentifier());
     }
 
     @Override
     public String toString() {
-        return Objects.toStringHelper(this)
+        return Objects.toStringHelper(this).omitNullValues()
                 .add("type", type)
-                .add("path", path)
-                .add("identifier", identifier)
+                .add("tree", tree)
+                .add("name", name)
                 .add("info", info)
                 .add("context", context)
                 .toString();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/JcrListener.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/JcrListener.java?rev=1561247&r1=1561246&r2=1561247&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/JcrListener.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/JcrListener.java
Sat Jan 25 02:29:56 2014
@@ -19,14 +19,13 @@
 package org.apache.jackrabbit.oak.plugins.observation;
 
 import static com.google.common.collect.Lists.newArrayList;
-import static java.util.Collections.emptyMap;
 import static javax.jcr.observation.Event.NODE_ADDED;
 import static javax.jcr.observation.Event.NODE_MOVED;
 import static javax.jcr.observation.Event.NODE_REMOVED;
 import static javax.jcr.observation.Event.PROPERTY_ADDED;
+import static javax.jcr.observation.Event.PROPERTY_CHANGED;
 import static javax.jcr.observation.Event.PROPERTY_REMOVED;
 import static org.apache.jackrabbit.oak.core.AbstractTree.OAK_CHILD_ORDER;
-import static org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager.getIdentifier;
 
 import java.util.Iterator;
 import java.util.List;
@@ -37,7 +36,6 @@ import javax.jcr.observation.Event;
 import com.google.common.collect.ImmutableMap;
 
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.core.ImmutableTree;
 import org.apache.jackrabbit.oak.plugins.observation.EventIterable.IterableListener;
@@ -65,22 +63,26 @@ class JcrListener implements IterableLis
 
     @Override
     public void propertyAdded(PropertyState after) {
-        events.add(createEvent(PROPERTY_ADDED, afterTree, after));
+        events.add(new EventImpl(
+                context, PROPERTY_ADDED, afterTree, after.getName()));
     }
 
     @Override
     public void propertyChanged(PropertyState before, PropertyState after) {
-        events.add(createEvent(Event.PROPERTY_CHANGED, afterTree, after));
+        events.add(new EventImpl(
+                context, PROPERTY_CHANGED, afterTree, after.getName()));
     }
 
     @Override
     public void propertyDeleted(PropertyState before) {
-        events.add(createEvent(PROPERTY_REMOVED, beforeTree, before));
+        events.add(new EventImpl(
+                context, PROPERTY_REMOVED, beforeTree, before.getName()));
     }
 
     @Override
     public void childNodeAdded(String name, NodeState after) {
-        events.add(createEvent(NODE_ADDED, afterTree.getChild(name)));
+        events.add(new EventImpl(
+                context, NODE_ADDED, new ImmutableTree(afterTree, name, after)));
     }
 
     @Override
@@ -90,23 +92,26 @@ class JcrListener implements IterableLis
 
     @Override
     public void childNodeDeleted(String name, NodeState before) {
-        events.add(createEvent(NODE_REMOVED, beforeTree.getChild(name)));
+        events.add(new EventImpl(
+                context, NODE_REMOVED, new ImmutableTree(beforeTree, name, before)));
     }
 
     @Override
     public void nodeMoved(String sourcePath, String name, NodeState moved) {
         String destPath = PathUtils.concat(afterTree.getPath(), name);
-        events.add(createEvent(NODE_MOVED, afterTree.getChild(name),
-                ImmutableMap.of(
-                        "srcAbsPath", context.getJcrPath(sourcePath),
-                        "destAbsPath", context.getJcrPath(destPath))));
+        ImmutableMap<String, String> info = ImmutableMap.of(
+                "srcAbsPath", context.getJcrPath(sourcePath),
+                "destAbsPath", context.getJcrPath(destPath));
+        ImmutableTree tree = new ImmutableTree(afterTree, name, moved);
+        events.add(new EventImpl(context, NODE_MOVED, tree, info));
     }
 
     @Override
     public JcrListener create(String name, NodeState before, NodeState after) {
         return new JcrListener(
                 context,
-                new ImmutableTree(beforeTree, name, before), afterTree.getChild(name));
+                new ImmutableTree(beforeTree, name, before),
+                new ImmutableTree(afterTree, name, after));
     }
 
     @Override
@@ -123,6 +128,7 @@ class JcrListener implements IterableLis
         afterNames.retainAll(beforeNames);
         beforeNames.retainAll(afterNames);
 
+        ImmutableTree parent = new ImmutableTree(afterTree, name, after);
         // Selection sort beforeNames into afterNames recording the swaps as we go
         for (int a = 0; a < afterNames.size(); a++) {
             String afterName = afterNames.get(a);
@@ -131,26 +137,14 @@ class JcrListener implements IterableLis
                 if (a != b && beforeName.equals(afterName)) {
                     beforeNames.set(b, beforeNames.get(a));
                     beforeNames.set(a, beforeName);
-                    events.add(createEvent(NODE_MOVED, afterTree.getChild(name).getChild(afterName),
-                            ImmutableMap.of(
-                                    "srcChildRelPath", context.getJcrName(beforeNames.get(a)),
-                                    "destChildRelPath", context.getJcrName(beforeNames.get(a
+ 1)))));
+                    Map<String, String> info = ImmutableMap.of(
+                            "srcChildRelPath", context.getJcrName(beforeNames.get(a)),
+                            "destChildRelPath", context.getJcrName(beforeNames.get(a + 1)));
+                    ImmutableTree tree = parent.getChild(afterName);
+                    events.add(new EventImpl(context, NODE_MOVED, tree, info));
                 }
             }
         }
     }
 
-    private Event createEvent(int eventType, Tree tree) {
-        return new EventImpl(context, eventType, tree.getPath(), getIdentifier(tree), emptyMap());
-    }
-
-    private Event createEvent(int eventType, Tree tree, Map<?, ?> info) {
-        return new EventImpl(context, eventType, tree.getPath(), getIdentifier(tree), info);
-    }
-
-    private Event createEvent(int eventType, Tree parent, PropertyState property) {
-        String path = PathUtils.concat(parent.getPath(), property.getName());
-        return new EventImpl(context, eventType, path, getIdentifier(parent), emptyMap());
-    }
-
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitInfo.java?rev=1561247&r1=1561246&r2=1561247&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitInfo.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitInfo.java
Sat Jan 25 02:29:56 2014
@@ -110,7 +110,7 @@ public final class CommitInfo {
 
     @Override
     public String toString() {
-        return toStringHelper(this)
+        return toStringHelper(this).omitNullValues()
                 .add("sessionId", sessionId)
                 .add("userId", userId)
                 .add("userData", message)



Mime
View raw message