incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1590644 - /sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
Date Mon, 28 Apr 2014 14:03:35 GMT
Author: cziegeler
Date: Mon Apr 28 14:03:35 2014
New Revision: 1590644

URL: http://svn.apache.org/r1590644
Log:
SLING-3522 : NPE on startup in ChangeStateTask.getSortKey

Modified:
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java?rev=1590644&r1=1590643&r2=1590644&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
Mon Apr 28 14:03:35 2014
@@ -232,6 +232,8 @@ implements OsgiInstaller, ResourceChange
                 this.logger.debug("Starting new installer cycle");
                 this.listener.start();
 
+                processUpdateInfos();
+
                 // merge potential new resources
                 this.mergeNewlyRegisteredResources();
 
@@ -821,6 +823,16 @@ implements OsgiInstaller, ResourceChange
         this.wakeUp();
     }
 
+    private static final class UpdateInfo {
+        public ResourceData data;
+        public Dictionary<String, Object> dict;
+        public String resourceType;
+        public String entityId;
+        public Map<String, Object> attributes;
+    }
+
+    private final List<UpdateInfo> updateInfos = new ArrayList<OsgiInstallerImpl.UpdateInfo>();
+
     /**
      * @see org.apache.sling.installer.api.ResourceChangeListener#resourceAddedOrUpdated(java.lang.String,
java.lang.String, java.io.InputStream, java.util.Dictionary, Map)
      */
@@ -829,9 +841,54 @@ implements OsgiInstaller, ResourceChange
             final InputStream is,
             final Dictionary<String, Object> dict,
             final Map<String, Object> attributes) {
+        try {
+            final UpdateInfo ui = new UpdateInfo();
+            ui.data = ResourceData.create(is, dict);
+            ui.resourceType = resourceType;
+            ui.dict = dict;
+            ui.entityId = entityId;
+            ui.attributes = attributes;
+
+            synchronized ( this.resourcesLock ) {
+                updateInfos.add(ui);
+                this.wakeUp();
+            }
+        } catch (final IOException ioe) {
+            logger.error("Unable to handle resource add or update of " + resourceType + ':'
+ entityId, ioe);
+        } finally {
+            // always close the input stream!
+            if ( is != null ) {
+                try {
+                    is.close();
+                } catch (final IOException ignore) {
+                    // ignore
+                }
+            }
+        }
+    }
+
+
+    private void processUpdateInfos() {
+        final List<UpdateInfo> infos = new ArrayList<OsgiInstallerImpl.UpdateInfo>();
+        synchronized ( this.resourcesLock ) {
+            infos.addAll(this.updateInfos);
+            this.updateInfos.clear();
+        }
+        for(final UpdateInfo info : infos) {
+            if ( info.data != null ) {
+                this.internalResourceAddedOrUpdated(info.resourceType, info.entityId, info.data,
info.dict, info.attributes);
+            } else {
+                this.internalResourceRemoved(info.resourceType, info.entityId);
+            }
+        }
+    }
+    private void internalResourceAddedOrUpdated(final String resourceType,
+            final String entityId,
+            final ResourceData data,
+            final Dictionary<String, Object> dict,
+            final Map<String, Object> attributes) {
         final String key = resourceType + ':' + entityId;
         try {
-            final ResourceData data = ResourceData.create(is, dict);
             synchronized ( this.resourcesLock ) {
                 final EntityResourceList erl = this.persistentList.getEntityResourceList(key);
                 logger.debug("Added or updated {} : {}", key, erl);
@@ -969,15 +1026,6 @@ implements OsgiInstaller, ResourceChange
             }
         } catch (final IOException ioe) {
             logger.error("Unable to handle resource add or update of " + key, ioe);
-        } finally {
-            // always close the input stream!
-            if ( is != null ) {
-                try {
-                    is.close();
-                } catch (final IOException ignore) {
-                    // ignore
-                }
-            }
         }
     }
 
@@ -985,6 +1033,18 @@ implements OsgiInstaller, ResourceChange
      * @see org.apache.sling.installer.api.ResourceChangeListener#resourceRemoved(java.lang.String,
java.lang.String)
      */
     public void resourceRemoved(final String resourceType, String resourceId) {
+        final UpdateInfo ui = new UpdateInfo();
+        ui.resourceType = resourceType;
+        ui.entityId = resourceId;
+
+        synchronized ( this.resourcesLock ) {
+            updateInfos.add(ui);
+            this.wakeUp();
+        }
+    }
+
+    private void internalResourceRemoved(final String resourceType, String resourceId) {
+
         String key = resourceType + ':' + resourceId;
         synchronized ( this.resourcesLock ) {
             final EntityResourceList erl = this.persistentList.getEntityResourceList(key);



Mime
View raw message