Return-Path: Delivered-To: apmail-sling-commits-archive@www.apache.org Received: (qmail 70177 invoked from network); 31 Aug 2009 13:29:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 31 Aug 2009 13:29:13 -0000 Received: (qmail 7865 invoked by uid 500); 31 Aug 2009 13:29:13 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 7806 invoked by uid 500); 31 Aug 2009 13:29:13 -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 7797 invoked by uid 99); 31 Aug 2009 13:29:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 31 Aug 2009 13:29:13 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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, 31 Aug 2009 13:29:11 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id AB2472388903; Mon, 31 Aug 2009 13:28:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r809579 - /sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java Date: Mon, 31 Aug 2009 13:28:51 -0000 To: commits@sling.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090831132851.AB2472388903@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bdelacretaz Date: Mon Aug 31 13:28:51 2009 New Revision: 809579 URL: http://svn.apache.org/viewvc?rev=809579&view=rev Log: SLING-1078 - schedule task retries only on meaningful bundle events Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java?rev=809579&r1=809578&r2=809579&view=diff ============================================================================== --- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java (original) +++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java Mon Aug 31 13:28:51 2009 @@ -35,8 +35,6 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleListener; -import org.osgi.framework.FrameworkEvent; -import org.osgi.framework.FrameworkListener; import org.osgi.service.log.LogService; /** Worker thread where all OSGi tasks are executed. @@ -47,7 +45,7 @@ * that are updated or removed during a cycle, and merged with * the main list at the end of the cycle. */ -class OsgiInstallerThread extends Thread implements FrameworkListener, BundleListener { +class OsgiInstallerThread extends Thread implements BundleListener { private final OsgiInstallerContext ctx; private final List newResources = new LinkedList(); @@ -72,7 +70,6 @@ void deactivate() { ctx.getBundleContext().removeBundleListener(this); - ctx.getBundleContext().removeFrameworkListener(this); active = false; synchronized (newResources) { newResources.notify(); @@ -81,7 +78,6 @@ @Override public void run() { - ctx.getBundleContext().addFrameworkListener(this); ctx.getBundleContext().addBundleListener(this); while(active) { @@ -381,17 +377,27 @@ ctx.incrementCounter(OsgiInstaller.INSTALLER_CYCLES_COUNTER); } - /** Need to wake up on framework and bundle events, as we might have tasks waiting to retry */ - public void frameworkEvent(FrameworkEvent arg0) { - synchronized (newResources) { - newResources.notify(); - } - } - - /** Need to wake up on framework and bundle events, as we might have tasks waiting to retry */ - public void bundleChanged(BundleEvent arg0) { - synchronized (newResources) { - newResources.notify(); - } + /** If we have any tasks waiting to be retried, schedule their execution */ + private void scheduleRetries() { + final int toRetry = tasksForNextCycle.size(); + if(toRetry > 0) { + if(ctx.getLogService() != null) { + ctx.getLogService().log(LogService.LOG_DEBUG, toRetry + " tasks scheduled for retrying"); + } + synchronized (newResources) { + newResources.notify(); + } + } + } + + public void bundleChanged(BundleEvent e) { + final int t = e.getType(); + if(t == BundleEvent.INSTALLED || t == BundleEvent.RESOLVED || t == BundleEvent.STARTED || t == BundleEvent.UPDATED) { + if(ctx.getLogService() != null) { + ctx.getLogService().log(LogService.LOG_DEBUG, + "Received BundleEvent that might allow installed bundles to start, scheduling retries if any"); + } + scheduleRetries(); + } } } \ No newline at end of file