incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r1372539 - /sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingHandlerManager.java
Date Mon, 13 Aug 2012 18:32:45 GMT
Author: justin
Date: Mon Aug 13 18:32:45 2012
New Revision: 1372539

URL: http://svn.apache.org/viewvc?rev=1372539&view=rev
Log:
SLING-2559 - avoiding the setValue() call by queueing updates to the handler map and then
using putAll()

Modified:
    sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingHandlerManager.java

Modified: sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingHandlerManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingHandlerManager.java?rev=1372539&r1=1372538&r2=1372539&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingHandlerManager.java
(original)
+++ sling/trunk/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingHandlerManager.java
Mon Aug 13 18:32:45 2012
@@ -19,6 +19,8 @@
 package org.apache.sling.jcr.webdav.impl.handler;
 
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import java.util.TreeMap;
@@ -58,19 +60,31 @@ public class SlingHandlerManager<Managed
 
             final ArrayList<ManagedType> ioHandlers = new ArrayList<ManagedType>(
                 entries.size());
+            final Map<ServiceReference, ManagedType> updates = new HashMap<ServiceReference,
ManagedType>();
             for (Entry<ServiceReference, ManagedType> entry : entries) {
                 final ManagedType ioHandler;
                 if (entry.getValue() == null) {
+                    final ServiceReference key = entry.getKey();
                     // unckecked cast
                     ioHandler = (ManagedType) this.componentContext.locateService(
-                        referenceName, entry.getKey());
-                    entry.setValue(ioHandler);
+                        referenceName, key);
+                    // since we're inside the entries iterator, we can't update the map
+                    // defer updating the map until this loop is finished
+                    if (ioHandler != null) {
+                        updates.put(key, ioHandler);
+                    }
                 } else {
                     ioHandler = entry.getValue();
                 }
                 ioHandlers.add(ioHandler);
             }
 
+            if (!updates.isEmpty()) {
+                synchronized (this.handlerServices) {
+                    this.handlerServices.putAll(updates);
+                }
+            }
+
             // unckecked cast
             this.handlers = ioHandlers.toArray(type);
         }



Mime
View raw message