From d890c2012c915504e4518810338d5ccebddada5e Mon Sep 17 00:00:00 2001 From: rfeng Date: Wed, 27 Aug 2008 23:44:27 +0000 Subject: Additional fix for TUSCANY-2566 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@689671 13f79535-47bb-0310-9956-ffa450edef68 --- java/sca/modules/node-launcher-osgi/pom.xml | 1 + .../node/osgi/launcher/DomainManagerLauncher.java | 57 +++++++------ .../sca/node/osgi/launcher/NodeLauncher.java | 99 ++++++++++++---------- 3 files changed, 87 insertions(+), 70 deletions(-) (limited to 'java/sca') diff --git a/java/sca/modules/node-launcher-osgi/pom.xml b/java/sca/modules/node-launcher-osgi/pom.xml index e9c22bf3bf..18e38323f6 100644 --- a/java/sca/modules/node-launcher-osgi/pom.xml +++ b/java/sca/modules/node-launcher-osgi/pom.xml @@ -111,6 +111,7 @@ copy-dependencies + test ${project.build.directory}/tuscany/modules true true diff --git a/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/DomainManagerLauncher.java b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/DomainManagerLauncher.java index 6c28ef8b28..f94c43bd52 100644 --- a/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/DomainManagerLauncher.java +++ b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/DomainManagerLauncher.java @@ -31,15 +31,15 @@ import java.util.logging.Logger; * @version $Rev$ $Date$ */ public class DomainManagerLauncher { - - private static final Logger logger = Logger.getLogger(DomainManagerLauncher.class.getName()); + + private static final Logger logger = Logger.getLogger(DomainManagerLauncher.class.getName()); /** * Constructs a new DomainManagerLauncher. */ private DomainManagerLauncher() { } - + /** * Returns a new launcher instance. * @@ -58,7 +58,7 @@ public class DomainManagerLauncher { public T createDomainManager() throws LauncherException { return (T)domainManager("."); } - + /** * Creates a new DomainManager. * @@ -70,34 +70,41 @@ public class DomainManagerLauncher { public T createDomainManager(String rootDirectory) throws LauncherException { return (T)domainManager(rootDirectory); } - + public static void main(String[] args) throws Exception { logger.info("Apache Tuscany SCA Domain Manager starting..."); // Create a domain manager DomainManagerLauncher launcher = newInstance(); - Object domainManager = launcher.createDomainManager(); - - // Start the domain manager - try { - domainManager.getClass().getMethod("start").invoke(domainManager); - } catch (Exception e) { - logger.log(Level.SEVERE, "SCA Domain Manager could not be started", e); - throw e; - } - logger.info("SCA Domain Manager started."); - - logger.info("Press enter to shutdown."); + OSGiHost host = NodeLauncherUtil.startOSGi(); try { - System.in.read(); - } catch (IOException e) {} - // Stop the domain manager - try { - domainManager.getClass().getMethod("stop").invoke(domainManager); - } catch (Exception e) { - logger.log(Level.SEVERE, "SCA Domain Manager could not be stopped", e); - throw e; + Object domainManager = launcher.createDomainManager(); + + // Start the domain manager + try { + domainManager.getClass().getMethod("start").invoke(domainManager); + } catch (Exception e) { + logger.log(Level.SEVERE, "SCA Domain Manager could not be started", e); + throw e; + } + logger.info("SCA Domain Manager started."); + + logger.info("Press enter to shutdown."); + try { + System.in.read(); + } catch (IOException e) { + } + + // Stop the domain manager + try { + domainManager.getClass().getMethod("stop").invoke(domainManager); + } catch (Exception e) { + logger.log(Level.SEVERE, "SCA Domain Manager could not be stopped", e); + throw e; + } + } finally { + NodeLauncherUtil.stopOSGi(host); } } } diff --git a/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncher.java b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncher.java index c4c4c04eb8..ea487c384b 100644 --- a/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncher.java +++ b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncher.java @@ -39,7 +39,7 @@ public class NodeLauncher { */ private NodeLauncher() { } - + /** * Returns a new launcher instance. * @@ -61,9 +61,9 @@ public class NodeLauncher { public T createNodeFromURL(String configurationURL) throws LauncherException { return (T)node(configurationURL, null, null, null, null); } - + /** - * Creates a new SCA Node. + * Creates a new SCA OSGi Node. * * @param compositeURI the URI of the composite to use * @param contributions the URI of the contributions that provides the composites and related @@ -73,12 +73,12 @@ public class NodeLauncher { * @return a new SCA node. * @throws LauncherException */ - public T createNode(String compositeURI, Contribution...contributions) throws LauncherException { + public T createNode(String compositeURI, Contribution... contributions) throws LauncherException { return (T)node(null, compositeURI, null, contributions, null); } - + /** - * Creates a new SCA Node. + * Creates a new SCA OSGi Node. * * @param compositeURI the URI of the composite to use * @param compositeContent the XML content of the composite to use @@ -86,10 +86,11 @@ public class NodeLauncher { * @return a new SCA node. * @throws LauncherException */ - public T createNode(String compositeURI, String compositeContent, Contribution...contributions) throws LauncherException { + public T createNode(String compositeURI, String compositeContent, Contribution... contributions) + throws LauncherException { return (T)node(null, compositeURI, compositeContent, contributions, null); } - + /** * Create a SCA node based on the discovery of the contribution on the classpath for the * given classloader. This method should be treated a convenient shortcut with the following @@ -107,49 +108,57 @@ public class NodeLauncher { public T createNodeFromClassLoader(String compositeURI, ClassLoader classLoader) throws LauncherException { return (T)node(null, compositeURI, null, null, classLoader); } - + public static void main(String[] args) throws Exception { - logger.info("Apache Tuscany SCA Node starting..."); + logger.info("Apache Tuscany SCA OSGi Node is starting..."); // Create a node NodeLauncher launcher = newInstance(); - Object node; - if (args.length ==1) { - - // Create from a configuration URI - String configurationURI = args[0]; - logger.info("SCA Node configuration: " + configurationURI); - node = launcher.createNodeFromURL(configurationURI); - } else { - - // Create from a composite URI and a contribution location - String compositeURI = args[0]; - String contributionLocation = args[1]; - logger.info("SCA composite: " + compositeURI); - logger.info("SCA contribution: " + contributionLocation); - node = launcher.createNode(compositeURI, new Contribution("default", contributionLocation)); - } - - // Start the node - try { - node.getClass().getMethod("start").invoke(node); - } catch (Exception e) { - logger.log(Level.SEVERE, "SCA Node could not be started", e); - throw e; - } - logger.info("SCA Node started."); - - logger.info("Press enter to shutdown."); - try { - System.in.read(); - } catch (IOException e) {} - // Stop the node + OSGiHost host = NodeLauncherUtil.startOSGi(); try { - node.getClass().getMethod("stop").invoke(node); - } catch (Exception e) { - logger.log(Level.SEVERE, "SCA Node could not be stopped", e); - throw e; + + Object node; + if (args.length == 1) { + + // Create from a configuration URI + String configurationURI = args[0]; + logger.info("SCA OSGi Node configuration: " + configurationURI); + node = launcher.createNodeFromURL(configurationURI); + } else { + + // Create from a composite URI and a contribution location + String compositeURI = args[0]; + String contributionLocation = args[1]; + logger.info("SCA composite: " + compositeURI); + logger.info("SCA contribution: " + contributionLocation); + node = launcher.createNode(compositeURI, new Contribution("default", contributionLocation)); + } + + // Start the node + try { + node.getClass().getMethod("start").invoke(node); + } catch (Exception e) { + logger.log(Level.SEVERE, "SCA OSGi Node could not be started", e); + throw e; + } + logger.info("SCA OSGi Node is now started."); + + logger.info("Press Enter to shutdown..."); + try { + System.in.read(); + } catch (IOException e) { + } + + // Stop the node + try { + node.getClass().getMethod("stop").invoke(node); + } catch (Exception e) { + logger.log(Level.SEVERE, "SCA OSGi Node could not be stopped", e); + throw e; + } + } finally { + NodeLauncherUtil.stopOSGi(host); } } -- cgit v1.2.3