incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1243476 - /sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java
Date Mon, 13 Feb 2012 11:28:49 GMT
Author: fmeschbe
Date: Mon Feb 13 11:28:49 2012
New Revision: 1243476

URL: http://svn.apache.org/viewvc?rev=1243476&view=rev
Log:
SLING-2420 Prevent deadlocks with the framework while registering and unregistering services

Modified:
    sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java

Modified: sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java?rev=1243476&r1=1243475&r2=1243476&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java
(original)
+++ sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java
Mon Feb 13 11:28:49 2012
@@ -70,7 +70,7 @@ public class JcrResourceBundleProvider i
         EventListener {
 
     private static final boolean DEFAULT_PRELOAD_BUNDLES = false;
-    
+
     @Property(value = "")
     private static final String PROP_USER = "user";
 
@@ -123,9 +123,9 @@ public class JcrResourceBundleProvider i
      * {@link #getRootResourceBundle()}.
      */
     private ResourceBundle rootResourceBundle;
-    
+
     private BundleContext bundleContext;
-    
+
     private List<ServiceRegistration> bundleServiceRegistrations;
 
     private boolean preloadBundles;
@@ -219,7 +219,7 @@ public class JcrResourceBundleProvider i
             t.start();
         }
     }
-    
+
     protected void deactivate() {
         clearCache();
     }
@@ -280,13 +280,14 @@ public class JcrResourceBundleProvider i
                     new Object[] { baseName, locale
                             });
             } else {
+                Dictionary<Object, Object> serviceProps = new Hashtable<Object,
Object>();
+                if (key.baseName != null) {
+                    serviceProps.put("baseName", key.baseName);
+                }
+                serviceProps.put("locale", key.locale.toString());
+                ServiceRegistration serviceReg = bundleContext.registerService(ResourceBundle.class.getName(),
+                    resourceBundle, serviceProps);
                 synchronized (this) {
-                    Dictionary<Object, Object> serviceProps = new Hashtable<Object,
Object>();
-                    if (key.baseName != null) {
-                        serviceProps.put("baseName", key.baseName);
-                    }
-                    serviceProps.put("locale", key.locale.toString());
-                    ServiceRegistration serviceReg = bundleContext.registerService(ResourceBundle.class.getName(),
resourceBundle, serviceProps);
                     bundleServiceRegistrations.add(serviceReg);
                 }
             }
@@ -428,17 +429,21 @@ public class JcrResourceBundleProvider i
 
         return resourceResolver;
     }
-    
+
     private void clearCache() {
         resourceBundleCache.clear();
+
+        ServiceRegistration[] serviceRegs;
         synchronized (this) {
-            for (ServiceRegistration serviceReg : bundleServiceRegistrations) {
-                serviceReg.unregister();
-            }
+            serviceRegs = bundleServiceRegistrations.toArray(new ServiceRegistration[bundleServiceRegistrations.size()]);
             bundleServiceRegistrations.clear();
         }
+
+        for (ServiceRegistration serviceReg : serviceRegs) {
+            serviceReg.unregister();
+        }
     }
-    
+
     private void preloadBundles() {
         if (preloadBundles) {
             @SuppressWarnings("deprecation")
@@ -457,7 +462,7 @@ public class JcrResourceBundleProvider i
                     if (usedKeys.add(key)) {
                         getResourceBundle(baseName, locale);
                     }
-                }   
+                }
             }
         }
     }



Mime
View raw message