Author: cziegeler
Date: Sun Oct 16 10:18:44 2016
New Revision: 1765134

URL: http://svn.apache.org/viewvc?rev=1765134&view=rev
Log:
SLING-6070 : Reduce temporary storage required in JcrResourceListener, call 
reportChanges earlier

Modified:
    
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceChange.java
    
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java

Modified: 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceChange.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceChange.java?rev=1765134&r1=1765133&r2=1765134&view=diff
==============================================================================
--- 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceChange.java
 (original)
+++ 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceChange.java
 Sun Oct 16 10:18:44 2016
@@ -20,76 +20,23 @@ package org.apache.sling.jcr.resource.in
 
 import org.apache.sling.api.resource.observation.ResourceChange;
 
+/**
+ * Extension of {@code ResourceChange} to support user id (if available)
+ */
 public class JcrResourceChange extends ResourceChange {
 
     private final String userId;
 
-    private JcrResourceChange(Builder builder) {
-        super(builder.changeType, builder.path, builder.isExternal);
-        this.userId = builder.userId;
+    public JcrResourceChange(final ResourceChange.ChangeType changeType,
+            final String path,
+            final boolean isExternal,
+            final String userId) {
+        super(changeType, path, isExternal);
+        this.userId = userId;
     }
 
     @Override
     public String getUserId() {
         return userId;
     }
-
-    @Override
-    public String toString() {
-        StringBuilder b = new StringBuilder();
-        b.append("ResourceChange[type=")
-          .append(this.getType())
-          .append(", path=")
-          .append(this.getPath())
-          .append("]");
-        return b.toString();
-    }
-
-    public static class Builder {
-
-        private String path;
-
-        private ChangeType changeType;
-
-        private boolean isExternal;
-
-        private String userId;
-
-        public String getPath() {
-            return path;
-        }
-
-        public void setPath(String path) {
-            this.path = path;
-        }
-
-        public ChangeType getChangeType() {
-            return changeType;
-        }
-
-        public void setChangeType(ChangeType changeType) {
-            this.changeType = changeType;
-        }
-
-        public boolean isExternal() {
-            return isExternal;
-        }
-
-        public void setExternal(boolean isExternal) {
-            this.isExternal = isExternal;
-        }
-
-        public String getUserId() {
-            return userId;
-        }
-
-        public void setUserId(String userId) {
-            this.userId = userId;
-        }
-
-        public ResourceChange build() {
-            return new JcrResourceChange(this);
-        }
-    }
-
 }
\ No newline at end of file

Modified: 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java?rev=1765134&r1=1765133&r2=1765134&view=diff
==============================================================================
--- 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java
 (original)
+++ 
sling/trunk/bundles/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceListener.java
 Sun Oct 16 10:18:44 2016
@@ -32,7 +32,6 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -50,7 +49,6 @@ import org.apache.sling.api.resource.obs
 import org.apache.sling.api.resource.observation.ResourceChange.ChangeType;
 import org.apache.sling.api.resource.path.Path;
 import org.apache.sling.jcr.api.SlingRepository;
-import org.apache.sling.jcr.resource.internal.JcrResourceChange.Builder;
 import org.apache.sling.jcr.resource.internal.helper.jcr.PathMapper;
 import org.apache.sling.spi.resource.provider.ObserverConfiguration;
 import org.apache.sling.spi.resource.provider.ProviderContext;
@@ -134,9 +132,9 @@ public class JcrResourceListener impleme
      */
     @Override
     public void onEvent(final EventIterator events) {
-        final Map<String, Builder> addedEvents = new HashMap<String, 
Builder>();
-        final Map<String, Builder> changedEvents = new HashMap<String, 
Builder>();
-        final Map<String, Builder> removedEvents = new HashMap<String, 
Builder>();
+        final Map<String, ResourceChange> addedEvents = new HashMap<String, 
ResourceChange>();
+        final Map<String, ResourceChange> changedEvents = new HashMap<String, 
ResourceChange>();
+        final Map<String, ResourceChange> removedEvents = new HashMap<String, 
ResourceChange>();
 
         AtomicBoolean refreshedSession = new AtomicBoolean(false);
         while ( events.hasNext() ) {
@@ -183,35 +181,26 @@ public class JcrResourceListener impleme
         }
 
         final List<ResourceChange> changes = new ArrayList<ResourceChange>();
-        buildResourceChanges(changes, addedEvents);
-        buildResourceChanges(changes, removedEvents);
-        buildResourceChanges(changes, changedEvents);
+        changes.addAll(addedEvents.values());
+        changes.addAll(removedEvents.values());
+        changes.addAll(changedEvents.values());
         ctx.getObservationReporter().reportChanges(changes, false);
 
     }
 
-    private void buildResourceChanges(List<ResourceChange> result, Map<String, 
Builder> builders) {
-        for (Entry<String, Builder> e : builders.entrySet()) {
-            result.add(e.getValue().build());
-        }
-    }
-
-    private Builder createResourceChange(final Event event,
+    private ResourceChange createResourceChange(final Event event,
             final String path,
             final ChangeType changeType) {
-        Builder builder = new Builder();
-        String pathWithPrefix = addMountPrefix(mountPrefix, path);
-        builder.setPath(pathMapper.mapJCRPathToResourcePath(pathWithPrefix));
-        builder.setChangeType(changeType);
-        boolean isExternal = this.isExternal(event);
-        builder.setExternal(isExternal);
+        final String pathWithPrefix = addMountPrefix(mountPrefix, path);
+        final String fullPath = 
pathMapper.mapJCRPathToResourcePath(pathWithPrefix);
+        final boolean isExternal = this.isExternal(event);
+        final String userId;
         if (!isExternal) {
-            final String userID = event.getUserID();
-            if (userID != null) {
-                builder.setUserId(userID);
-            }
+            userId = event.getUserID();
+        } else {
+            userId = null;
         }
-        return builder;
+        return new JcrResourceChange(changeType, fullPath, isExternal, userId);
     }
 
     private boolean isExternal(final Event event) {


Reply via email to