diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-12 18:26:59 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-12 18:26:59 +0000 |
commit | 903f0145bf847393db17aed4cfca30563b87fa73 (patch) | |
tree | 5b3b7fc29f8fbe4f2b44b7165298f9a865f66f21 /java/sca/modules/node-launcher | |
parent | 4ddadcfa4e7fee4c837e3bc271523b61c7b7142a (diff) |
Restart a node when the user just presses enter.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@694766 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/node-launcher')
-rw-r--r-- | java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java | 102 |
1 files changed, 62 insertions, 40 deletions
diff --git a/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java index c720d8f1e0..447ccaa6b4 100644 --- a/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java +++ b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java @@ -117,57 +117,79 @@ public class NodeLauncher { Object node = null; ShutdownThread shutdown = null; try { - if (args.length ==1) { + while (true) { + if (args.length ==1) { + + // Create a node from a configuration URI + String configurationURI = args[0]; + logger.info("SCA Node configuration: " + configurationURI); + node = launcher.createNodeFromURL(configurationURI); + } else { + + // Create a node 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)); + } - // Create a node from a configuration URI - String configurationURI = args[0]; - logger.info("SCA Node configuration: " + configurationURI); - node = launcher.createNodeFromURL(configurationURI); - } else { + // 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 is now started."); - // Create a node 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 is now started."); - - // Install a shutdown hook - shutdown = new ShutdownThread(node); - Runtime.getRuntime().addShutdownHook(shutdown); - - logger.info("Press enter to shutdown."); - try { - System.in.read(); - } catch (IOException e) { + // Install a shutdown hook + shutdown = new ShutdownThread(node); + Runtime.getRuntime().addShutdownHook(shutdown); + + logger.info("Press 'q' to shutdown, any other key to restart."); + int k = 0; + try { + k = System.in.read(); + } catch (IOException e) { + + // Wait forever + Object lock = new Object(); + synchronized(lock) { + lock.wait(); + } + } + + // Stop the node + if (node != null) { + Object n = node; + node = null; + stopNode(n); + } - // Wait forever - Object lock = new Object(); - synchronized(lock) { - lock.wait(); + // Quit + if (k == 'q' ) { + break; } } + } catch (Exception e) { + // Stop the node + if (node != null) { + try { + Object n = node; + node = null; + stopNode(n); + } catch (Exception e2) { + } + } + throw e; + } finally { // Remove the shutdown hook if (shutdown != null) { Runtime.getRuntime().removeShutdownHook(shutdown); } - - // Stop the node - if (node != null) { - stopNode(node); - } } } |