diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-12 18:28:56 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-12 18:28:56 +0000 |
commit | 2e48ecc0ea43d7b859c578080c72e4c739717487 (patch) | |
tree | 4327c0bb7ffc548117b738ef3698ed169ad1a1e7 /java/sca/modules/node-launcher/src/main | |
parent | 54132ed615e755edc1a8a87bf8d14ccbd2ac3a89 (diff) |
Added a little more logic to restart the domain manager or a node when the user presses 'r', quit when the user presses 'q'.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@694768 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/node-launcher/src/main')
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 |