Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 97177 invoked from network); 7 Dec 2009 17:05:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 7 Dec 2009 17:05:42 -0000 Received: (qmail 70400 invoked by uid 500); 7 Dec 2009 17:05:42 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 70353 invoked by uid 500); 7 Dec 2009 17:05:42 -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 70344 invoked by uid 99); 7 Dec 2009 17:05:41 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Dec 2009 17:05:41 +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, 07 Dec 2009 17:05:32 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8F23A238898B; Mon, 7 Dec 2009 17:05:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r888005 - /geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java Date: Mon, 07 Dec 2009 17:05:10 -0000 To: scm@geronimo.apache.org From: gawor@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091207170510.8F23A238898B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: gawor Date: Mon Dec 7 17:05:10 2009 New Revision: 888005 URL: http://svn.apache.org/viewvc?rev=888005&view=rev Log: separate installing and starting of the dependent bundles in two separate steps Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java?rev=888005&r1=888004&r2=888005&view=diff ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java (original) +++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java Mon Dec 7 17:05:10 2009 @@ -17,7 +17,6 @@ * under the License. */ - package org.apache.geronimo.system.configuration; import java.io.IOException; @@ -25,7 +24,10 @@ import java.net.URL; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; +import java.util.Map; +import java.util.WeakHashMap; import org.apache.geronimo.gbean.annotation.GBean; import org.apache.geronimo.gbean.annotation.ParamReference; @@ -57,6 +59,9 @@ private final BundleContext bundleContext; private final Collection repositories; + + private final Map pluginMap = + Collections.synchronizedMap(new WeakHashMap()); public DependencyManager(@ParamSpecial(type = SpecialAttributeType.bundleContext) BundleContext bundleContext, @ParamReference(name = "Repositories", namingType = "Repository") Collection repositories) { @@ -69,57 +74,104 @@ int eventType = bundleEvent.getType(); if (eventType == BundleEvent.INSTALLED) { installed(bundleEvent.getBundle()); + } else if (eventType == BundleEvent.STARTING) { + starting(bundleEvent.getBundle()); } } - private void installed(Bundle bundle) { + private PluginArtifactType getPluginMetadata(Bundle bundle) { + PluginArtifactType pluginArtifactType = null; URL info = bundle.getEntry("META-INF/geronimo-plugin.xml"); if (info != null) { log.info("found geronimo-plugin.xml for bundle " + bundle); + InputStream in = null; try { - InputStream in = info.openStream(); - try { - PluginType pluginType = PluginXmlUtil.loadPluginMetadata(in); - PluginArtifactType pluginArtifactType = pluginType.getPluginArtifact().get(0); - List dependencies = pluginArtifactType.getDependency(); - List bundles = new ArrayList(); - for (DependencyType dependencyType : dependencies) { - log.info("installing artifact: " + dependencyType); - Artifact artifact = dependencyType.toArtifact(); - String location = locateBundle(artifact); - for (Bundle test: bundleContext.getBundles()) { - if (location.equals(test.getLocation())) { - continue; - } - } - try { - bundles.add(bundleContext.installBundle(location)); - } catch (BundleException e) { - log.warn("Could not install bundle for artifact: " + artifact, e); + in = info.openStream(); + PluginType pluginType = PluginXmlUtil.loadPluginMetadata(in); + pluginArtifactType = pluginType.getPluginArtifact().get(0); + } catch (Throwable e) { + log.warn("Could not read geronimo metadata for bundle: " + bundle, e); + } finally { + if (in != null) { + try { in.close(); } catch (IOException e) {} + } + } + } else { + log.info("did not find geronimo-plugin.xml for bundle " + bundle); + } + return pluginArtifactType; + } + + private PluginArtifactType getCachedPluginMetadata(Bundle bundle) { + PluginArtifactType pluginArtifactType = pluginMap.get(bundle); + if (pluginArtifactType == null) { + pluginArtifactType = getPluginMetadata(bundle); + if (pluginArtifactType != null) { + pluginMap.put(bundle, pluginArtifactType); + } + } + return pluginArtifactType; + } + + private void installed(Bundle bundle) { + PluginArtifactType pluginArtifactType = getCachedPluginMetadata(bundle); + if (pluginArtifactType != null) { + List dependencies = pluginArtifactType.getDependency(); + try { + for (DependencyType dependencyType : dependencies) { + log.info("Installing artifact: " + dependencyType); + Artifact artifact = dependencyType.toArtifact(); + String location = locateBundle(artifact); + for (Bundle test: bundleContext.getBundles()) { + if (location.equals(test.getLocation())) { + continue; } } - for (Bundle b : bundles) { - if (BundleUtils.canStart(b)) { - try { - b.start(Bundle.START_TRANSIENT); - } catch (BundleException e) { - log.warn("Could not start bundle: " + b, e); - } - } + try { + bundleContext.installBundle(location); + } catch (BundleException e) { + log.warn("Could not install bundle for artifact: " + artifact, e); } - } catch (Throwable e) { - log.warn("Could not read geronimo metadata for bundle: " + bundle, e); - } finally { - in.close(); } - } catch (IOException e) { - //?? + } catch (Exception e) { + log.error("Could not install bundle dependecy", e); } - } else { - log.info("did not find geronimo-plugin.xml for bundle " + bundle); } } + private void starting(Bundle bundle) { + PluginArtifactType pluginArtifactType = getCachedPluginMetadata(bundle); + if (pluginArtifactType != null) { + List bundles = new ArrayList(); + List dependencies = pluginArtifactType.getDependency(); + try { + for (DependencyType dependencyType : dependencies) { + log.info("Starting artifact: " + dependencyType); + Artifact artifact = dependencyType.toArtifact(); + String location = locateBundle(artifact); + + for (Bundle test: bundleContext.getBundles()) { + if (location.equals(test.getLocation())) { + bundles.add(test); + } + } + } + + for (Bundle b : bundles) { + if (BundleUtils.canStart(b)) { + try { + b.start(Bundle.START_TRANSIENT); + } catch (BundleException e) { + log.warn("Could not start bundle: " + b, e); + } + } + } + } catch (Exception e) { + log.error("Could not install bundle dependecy", e); + } + } + } + private String locateBundle(Artifact configurationId) throws NoSuchConfigException, IOException, InvalidConfigException { if (System.getProperty("geronimo.build.car") == null) { return "mvn:" + configurationId.getGroupId() + "/" + configurationId.getArtifactId() + "/" + configurationId.getVersion() + ("jar".equals(configurationId.getType())? "": "/" + configurationId.getType());