Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 98579 invoked from network); 24 Jul 2009 15:33:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 24 Jul 2009 15:33:11 -0000 Received: (qmail 19600 invoked by uid 500); 24 Jul 2009 15:34:16 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 19537 invoked by uid 500); 24 Jul 2009 15:34:16 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 19528 invoked by uid 99); 24 Jul 2009 15:34:16 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Jul 2009 15:34:16 +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; Fri, 24 Jul 2009 15:34:12 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 6F88E238886C; Fri, 24 Jul 2009 15:33:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r797533 - /geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintExtender.java Date: Fri, 24 Jul 2009 15:33:51 -0000 To: scm@geronimo.apache.org From: gawor@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090724153351.6F88E238886C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: gawor Date: Fri Jul 24 15:33:49 2009 New Revision: 797533 URL: http://svn.apache.org/viewvc?rev=797533&view=rev Log: improved destroy algorithm Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintExtender.java Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintExtender.java URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintExtender.java?rev=797533&r1=797532&r2=797533&view=diff ============================================================================== --- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintExtender.java (original) +++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/container/BlueprintExtender.java Fri Jul 24 15:33:49 2009 @@ -20,6 +20,8 @@ import java.net.URL; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.Enumeration; import java.util.HashMap; import java.util.List; @@ -92,8 +94,9 @@ context.removeBundleListener(this); // Orderly shutdown of containers while (!containers.isEmpty()) { - Bundle bundle = getBundleToDestroy(); - destroyContext(bundle); + for (Bundle bundle : getBundlesToDestroy()) { + destroyContext(bundle); + } } this.eventDispatcher.destroy(); this.handlers.destroy(); @@ -101,8 +104,8 @@ LOGGER.debug("Blueprint extender stopped"); } - private Bundle getBundleToDestroy() { - Bundle bundleToDestroy = null; + private List getBundlesToDestroy() { + List bundlesToDestroy = new ArrayList(); for (Bundle bundle : containers.keySet()) { ServiceReference[] references = bundle.getRegisteredServices(); int usage = 0; @@ -116,29 +119,30 @@ } LOGGER.debug("Usage for bundle {} is {}", bundle, usage); if (usage == 0) { - if (bundleToDestroy == null) { - LOGGER.debug("Currently selecting bundle {} for destroy (first bundle with no usage)", bundle); - bundleToDestroy = bundle; - } else if (bundle.getLastModified() > bundleToDestroy.getLastModified()) { - LOGGER.debug("Currently selecting bundle {} for destroy (it has been installed more recently)", bundle); - bundleToDestroy = bundle; - } + LOGGER.debug("Currently selecting bundle {} for destroy", bundle); + bundlesToDestroy.add(bundle); } } - if (bundleToDestroy == null) { + if (!bundlesToDestroy.isEmpty()) { + Collections.sort(bundlesToDestroy, new Comparator() { + public int compare(Bundle b1, Bundle b2) { + return (int) (b2.getLastModified() - b1.getLastModified()); + } + }); + } else { ServiceReference ref = null; for (Bundle bundle : containers.keySet()) { ServiceReference[] references = bundle.getRegisteredServices(); for (ServiceReference reference : references) { - if (ref == null || reference.compareTo(ref) > 0) { + if (ref == null || reference.compareTo(ref) < 0) { LOGGER.debug("Currently selecting bundle {} for destroy (with reference {})", bundle, reference); ref = reference; } } } - bundleToDestroy = ref.getBundle(); + bundlesToDestroy.add(ref.getBundle()); } - return bundleToDestroy; + return bundlesToDestroy; } public void bundleChanged(BundleEvent event) {