You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2008/09/12 20:27:00 UTC
svn commit: r694766 -
/tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java
Author: jsdelfino
Date: Fri Sep 12 11:26:59 2008
New Revision: 694766
URL: http://svn.apache.org/viewvc?rev=694766&view=rev
Log:
Restart a node when the user just presses enter.
Modified:
tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java
Modified: tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java?rev=694766&r1=694765&r2=694766&view=diff
==============================================================================
--- tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java (original)
+++ tuscany/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java Fri Sep 12 11:26:59 2008
@@ -117,57 +117,79 @@
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);
- }
}
}