From 903f0145bf847393db17aed4cfca30563b87fa73 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Fri, 12 Sep 2008 18:26:59 +0000 Subject: 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 --- .../tuscany/sca/node/launcher/NodeLauncher.java | 102 +++++++++++++-------- 1 file changed, 62 insertions(+), 40 deletions(-) (limited to 'java/sca/modules/node-launcher/src/main') 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); - } } } -- cgit v1.2.3