summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/node-launcher
diff options
context:
space:
mode:
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/DomainManagerLauncher.java81
-rw-r--r--java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeDaemonLauncher.java80
-rw-r--r--java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java6
3 files changed, 108 insertions, 59 deletions
diff --git a/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java
index a9d7d84f5e..eb06ad7411 100644
--- a/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java
+++ b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java
@@ -80,44 +80,67 @@ public class DomainManagerLauncher {
Object domainManager = null;
ShutdownThread shutdown = null;
try {
-
- // Start the domain manager
- domainManager = launcher.createDomainManager();
- 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 is now started.");
-
- // Install a shutdown hook
- shutdown = new ShutdownThread(domainManager);
- Runtime.getRuntime().addShutdownHook(shutdown);
-
- logger.info("Press enter to shutdown.");
-
- try {
- System.in.read();
- } catch (IOException e) {
+ while (true) {
+
+ // Start the domain manager
+ domainManager = launcher.createDomainManager();
+ 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 is now started.");
+
+ // Install a shutdown hook
+ shutdown = new ShutdownThread(domainManager);
+ Runtime.getRuntime().addShutdownHook(shutdown);
- // Wait forever
- Object lock = new Object();
- synchronized(lock) {
- lock.wait();
+ logger.info("Press 'q' to quit, 'r' to restart.");
+ int k = 0;
+ try {
+ while ((k != 'q') && (k != 'r')) {
+ k = System.in.read();
+ }
+ } catch (IOException e) {
+
+ // Wait forever
+ Object lock = new Object();
+ synchronized(lock) {
+ lock.wait();
+ }
+ }
+
+ // Stop the domain manager
+ if (domainManager != null) {
+ Object dm = domainManager;
+ domainManager = null;
+ stopDomainManager(dm);
+ }
+
+ // Quit
+ if (k == 'q' ) {
+ break;
}
}
+ } catch (Exception e) {
+ // Stop the domain manager
+ if (domainManager != null) {
+ try {
+ Object dm = domainManager;
+ domainManager = null;
+ stopDomainManager(dm);
+ } catch (Exception e2) {
+ }
+ }
+ throw e;
+
} finally {
// Remove the shutdown hook
if (shutdown != null) {
Runtime.getRuntime().removeShutdownHook(shutdown);
}
-
- // Stop the domain manager
- if (domainManager != null) {
- stopDomainManager(domainManager);
- }
}
}
diff --git a/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeDaemonLauncher.java b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeDaemonLauncher.java
index 450cd85650..7cfabfe265 100644
--- a/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeDaemonLauncher.java
+++ b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeDaemonLauncher.java
@@ -69,43 +69,67 @@ public class NodeDaemonLauncher {
Object node = null;
ShutdownThread shutdown = null;
try {
-
- // Start the node
- node = launcher.createNodeDaemon();
- try {
- node.getClass().getMethod("start").invoke(node);
- } catch (Exception e) {
- logger.log(Level.SEVERE, "SCA Node Daemon could not be started", e);
- throw e;
- }
- logger.info("SCA Node Daemon 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) {
+ while (true) {
- // Wait forever
- Object lock = new Object();
- synchronized(lock) {
- lock.wait();
+ // Start the node
+ node = launcher.createNodeDaemon();
+ try {
+ node.getClass().getMethod("start").invoke(node);
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "SCA Node Daemon could not be started", e);
+ throw e;
+ }
+ logger.info("SCA Node Daemon is now started.");
+
+ // Install a shutdown hook
+ shutdown = new ShutdownThread(node);
+ Runtime.getRuntime().addShutdownHook(shutdown);
+
+ logger.info("Press 'q' to quit, 'r' to restart.");
+ int k = 0;
+ try {
+ while ((k != 'q') && (k != 'r')) {
+ 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);
+ }
+
+ // 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);
- }
}
}
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 447ccaa6b4..be9bdb15c4 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
@@ -147,10 +147,12 @@ public class NodeLauncher {
shutdown = new ShutdownThread(node);
Runtime.getRuntime().addShutdownHook(shutdown);
- logger.info("Press 'q' to shutdown, any other key to restart.");
+ logger.info("Press 'q' to quit, 'r' to restart.");
int k = 0;
try {
- k = System.in.read();
+ while ((k != 'q') && (k != 'r')) {
+ k = System.in.read();
+ }
} catch (IOException e) {
// Wait forever