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 C0A4CDCBC for ; Wed, 29 Aug 2012 08:52:49 +0000 (UTC) Received: (qmail 1031 invoked by uid 500); 29 Aug 2012 08:52:49 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 870 invoked by uid 500); 29 Aug 2012 08:52:44 -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 833 invoked by uid 99); 29 Aug 2012 08:52:43 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Aug 2012 08:52:43 +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; Wed, 29 Aug 2012 08:52:42 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E0BAE23889B8; Wed, 29 Aug 2012 08:51:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1378482 - /sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java Date: Wed, 29 Aug 2012 08:51:58 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120829085158.E0BAE23889B8@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: cziegeler Date: Wed Aug 29 08:51:58 2012 New Revision: 1378482 URL: http://svn.apache.org/viewvc?rev=1378482&view=rev Log: Clean up code a little bit 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=1378482&r1=1378481&r2=1378482&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 Wed Aug 29 08:51:58 2012 @@ -122,7 +122,11 @@ public class OsgiInstallerImpl private final AtomicLong backgroundTaskCounter = new AtomicLong(); - /** Constructor */ + /** + * Constructor + * + * Most of the initialization is defered to the background thread + */ public OsgiInstallerImpl(final BundleContext ctx) { this.ctx = ctx; // Initialize file util @@ -144,19 +148,26 @@ public class OsgiInstallerImpl } // Stop service trackers. - this.factoryTracker.close(); - this.transformerTracker.close(); + if ( this.factoryTracker != null ) { + this.factoryTracker.close(); + } + if ( this.transformerTracker != null ) { + this.transformerTracker.close(); + } + if ( this.updateHandlerTracker != null ) { + this.updateHandlerTracker.close(); + } this.listener.dispose(); if ( this.backgroundThread != null ) { - if(logger.isDebugEnabled()) { - try { - logger.debug("Waiting for main background thread {} to stop", backgroundThread.getName()); - } catch(NullPointerException ignore) { + if ( logger.isDebugEnabled() ) { + final Thread t = this.backgroundThread; + if ( t != null ) { + logger.debug("Waiting for main background thread {} to stop", t.getName()); } } - + while ( this.backgroundThread != null ) { // use a local variable to avoid NPEs final Thread t = this.backgroundThread; @@ -177,6 +188,9 @@ public class OsgiInstallerImpl this.logger.info("Apache Sling OSGi Installer Service stopped."); } + /** + * Start this component. + */ public void start() { this.startBackgroundThread(); } @@ -196,6 +210,9 @@ public class OsgiInstallerImpl this.logger.info("Apache Sling OSGi Installer Service started."); } + /** + * Start the background thread. + */ private void startBackgroundThread() { this.backgroundThread = new Thread(this); this.backgroundThread.setName(getClass().getSimpleName()); @@ -236,12 +253,12 @@ public class OsgiInstallerImpl // registered logger.debug("No more tasks to process, suspending listener and going idle"); this.listener.suspend(); - + try { logger.debug("wait() on resourcesLock"); this.resourcesLock.wait(); } catch (final InterruptedException ignore) {} - + if ( active ) { logger.debug("Done wait()ing on resourcesLock, restarting listener"); this.listener.start(); @@ -692,8 +709,8 @@ public class OsgiInstallerImpl @Override public void run() { - logger.debug("Starting background thread {} to execute {}", - Thread.currentThread().getName(), + logger.debug("Starting background thread {} to execute {}", + Thread.currentThread().getName(), aSyncTask); try { Thread.sleep(2000L); @@ -705,7 +722,7 @@ public class OsgiInstallerImpl aSyncTask.getResource().setAttribute(InstallTask.ASYNC_ATTR_NAME, oldValue); } aSyncTask.execute(ctx); - logger.debug("Background thread {} ends", Thread.currentThread().getName()); + logger.debug("Background thread {} ends", Thread.currentThread().getName()); } }; t.start();