Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6A44CF20C for ; Mon, 28 Apr 2014 14:04:02 +0000 (UTC) Received: (qmail 28794 invoked by uid 500); 28 Apr 2014 14:04:01 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 28719 invoked by uid 500); 28 Apr 2014 14:04:00 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 28711 invoked by uid 99); 28 Apr 2014 14:04:00 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Apr 2014 14:04:00 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Apr 2014 14:03:59 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 0B16E23889E1; Mon, 28 Apr 2014 14:03:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140428140336.0B16E23889E1@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 dict; + public String resourceType; + public String entityId; + public Map attributes; + } + + private final List updateInfos = new ArrayList(); + /** * @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 dict, final Map 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 infos = new ArrayList(); + 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 dict, + final Map 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);