You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:51:31 UTC

[sling-org-apache-sling-jcr-webdav] 26/29: SLING-2559 - avoiding the setValue() call by queueing updates to the handler map and then using putAll()

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.webdav-2.1.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-webdav.git

commit f90cc4b3c8fce7210613f0a6b89425726f9a39eb
Author: Justin Edelson <ju...@apache.org>
AuthorDate: Mon Aug 13 18:32:45 2012 +0000

    SLING-2559 - avoiding the setValue() call by queueing updates to the handler map and then using putAll()
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/webdav@1372539 13f79535-47bb-0310-9956-ffa450edef68
---
 .../jcr/webdav/impl/handler/SlingHandlerManager.java   | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingHandlerManager.java b/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingHandlerManager.java
index 356eb81..6660095 100644
--- a/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingHandlerManager.java
+++ b/src/main/java/org/apache/sling/jcr/webdav/impl/handler/SlingHandlerManager.java
@@ -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<ManagedType> {
 
             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);
         }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.