summaryrefslogtreecommitdiffstats
path: root/java/sca/modules
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2008-09-05 02:07:43 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2008-09-05 02:07:43 +0000
commita8fa99e74baf16f8f5f83f0770d354523c9df6cd (patch)
treecc2c47b81b94e135aa51f44901695df5eb466b36 /java/sca/modules
parent6059c887cf7e4880a2de03959cf574a3d1f193cd (diff)
Minor fixes to the JSE and OSGi Equinox launchers. Added shutdown hooks, some try/catch, cleaned up the logs a bit.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@692319 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/DomainManagerLauncher.java87
-rw-r--r--java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeDaemonLauncher.java92
-rw-r--r--java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java99
-rw-r--r--java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java5
-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.java92
-rw-r--r--java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java113
-rw-r--r--java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java5
8 files changed, 428 insertions, 146 deletions
diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/DomainManagerLauncher.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/DomainManagerLauncher.java
index d2cda21de4..388f42bbb3 100644
--- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/DomainManagerLauncher.java
+++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/DomainManagerLauncher.java
@@ -20,6 +20,8 @@
package org.apache.tuscany.sca.node.equinox.launcher;
import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.domainManager;
+import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.startOSGi;
+import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.stopOSGi;
import java.io.IOException;
import java.util.logging.Level;
@@ -32,7 +34,7 @@ import java.util.logging.Logger;
*/
public class DomainManagerLauncher {
- private static final Logger logger = Logger.getLogger(DomainManagerLauncher.class.getName());
+ static final Logger logger = Logger.getLogger(DomainManagerLauncher.class.getName());
/**
* Constructs a new DomainManagerLauncher.
@@ -72,39 +74,100 @@ public class DomainManagerLauncher {
}
public static void main(String[] args) throws Exception {
- logger.info("Apache Tuscany SCA Domain Manager starting...");
+ logger.info("Apache Tuscany SCA Domain Manager is starting...");
- // Create a domain manager
+ // Create a launcher
DomainManagerLauncher launcher = newInstance();
- OSGiHost host = NodeLauncherUtil.startOSGi();
+
+ OSGiHost osgiHost = null;
+ Object domainManager = null;
+ ShutdownThread shutdown = null;
try {
- Object domainManager = launcher.createDomainManager();
+ // Start the OSGi host
+ osgiHost = startOSGi();
// 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 started.");
+ logger.info("SCA Domain Manager is now started.");
+
+ // Install a shutdown hook
+ ShutdownThread hook = new ShutdownThread(domainManager, osgiHost);
+ Runtime.getRuntime().addShutdownHook(hook);
logger.info("Press enter to shutdown.");
try {
System.in.read();
} catch (IOException e) {
+
+ // Wait forever
+ Object lock = new Object();
+ synchronized(lock) {
+ lock.wait();
+ }
}
- // Stop the domain manager
+ } finally {
+
+ // Remove the shutdown hook
+ if (shutdown != null) {
+ Runtime.getRuntime().removeShutdownHook(shutdown);
+ }
+
+ // Stop the domain manager and OSGi host
+ if (domainManager != null) {
+ stopDomainManager(domainManager);
+ }
+ if (osgiHost != null) {
+ stopOSGi(osgiHost);
+ }
+ }
+ }
+
+
+ /**
+ * Stop the given domain manager.
+ *
+ * @param domainManager
+ * @throws Exception
+ */
+ private static void stopDomainManager(Object domainManager) throws Exception {
+ try {
+ domainManager.getClass().getMethod("stop").invoke(domainManager);
+ logger.info("SCA Domain Manager is now stopped.");
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "SCA Domain Manager could not be stopped", e);
+ throw e;
+ }
+ }
+
+ private static class ShutdownThread extends Thread {
+ private Object domainManager;
+ private OSGiHost osgiHost;
+
+ public ShutdownThread(Object domainManager, OSGiHost osgiHost) {
+ super();
+ this.domainManager = domainManager;
+ this.osgiHost = osgiHost;
+ }
+
+ public void run() {
try {
- domainManager.getClass().getMethod("stop").invoke(domainManager);
+ stopDomainManager(domainManager);
} catch (Exception e) {
- logger.log(Level.SEVERE, "SCA Domain Manager could not be stopped", e);
- throw e;
+ // Ignore
+ }
+ try {
+ stopOSGi(osgiHost);
+ } catch (Exception e) {
+ // Ignore
}
- } finally {
- NodeLauncherUtil.stopOSGi(host);
}
}
}
diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeDaemonLauncher.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeDaemonLauncher.java
index fb2534485b..2eb4609da1 100644
--- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeDaemonLauncher.java
+++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeDaemonLauncher.java
@@ -20,6 +20,8 @@
package org.apache.tuscany.sca.node.equinox.launcher;
import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.nodeDaemon;
+import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.startOSGi;
+import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.stopOSGi;
import java.io.IOException;
import java.util.logging.Level;
@@ -32,7 +34,7 @@ import java.util.logging.Logger;
*/
public class NodeDaemonLauncher {
- private static final Logger logger = Logger.getLogger(NodeDaemonLauncher.class.getName());
+ static final Logger logger = Logger.getLogger(NodeDaemonLauncher.class.getName());
/**
* Constructs a new node daemon launcher.
@@ -61,40 +63,98 @@ public class NodeDaemonLauncher {
}
public static void main(String[] args) throws Exception {
- logger.info("Apache Tuscany SCA Node Daemon starting...");
+ logger.info("Apache Tuscany SCA Node Daemon is starting...");
- // Create a node daemon
+ // Create a node launcher
NodeDaemonLauncher launcher = newInstance();
- OSGiHost host = NodeLauncherUtil.startOSGi();
+ OSGiHost osgiHost = null;
+ Object node = null;
+ ShutdownThread shutdown = null;
try {
- Object daemon = launcher.createNodeDaemon();
- // Start the node daemon
+ // Start the OSGi host
+ osgiHost = startOSGi();
+
+ // Start the node
+ node = launcher.createNodeDaemon();
try {
- daemon.getClass().getMethod("start").invoke(daemon);
+ 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 started.");
-
+ logger.info("SCA Node Daemon is now started.");
+
+ // Install a shutdown hook
+ shutdown = new ShutdownThread(node, osgiHost);
+ Runtime.getRuntime().addShutdownHook(shutdown);
+
logger.info("Press enter to shutdown.");
try {
System.in.read();
} catch (IOException e) {
+
+ // Wait forever
+ Object lock = new Object();
+ synchronized(lock) {
+ lock.wait();
+ }
+ }
+ } finally {
+
+ // Remove the shutdown hook
+ if (shutdown != null) {
+ Runtime.getRuntime().removeShutdownHook(shutdown);
+ }
+
+ // Stop the node
+ if (node != null) {
+ stopNode(node);
}
+ if (osgiHost != null) {
+ stopOSGi(osgiHost);
+ }
+ }
+ }
+
+ /**
+ * Stop the given node.
+ *
+ * @param node
+ * @throws Exception
+ */
+ private static void stopNode(Object node) throws Exception {
+ try {
+ node.getClass().getMethod("stop").invoke(node);
+ logger.info("SCA Node Daemon is now stopped.");
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "SCA Node Daemon could not be stopped", e);
+ throw e;
+ }
+ }
+
+ private static class ShutdownThread extends Thread {
+ private Object node;
+ private OSGiHost osgiHost;
+
+ public ShutdownThread(Object node, OSGiHost osgiHost) {
+ super();
+ this.node = node;
+ this.osgiHost = osgiHost;
+ }
- // Stop the node daemon
+ public void run() {
try {
- daemon.getClass().getMethod("stop").invoke(daemon);
+ stopNode(node);
} catch (Exception e) {
- logger.log(Level.SEVERE, "SCA Node Daemon could not be stopped", e);
- throw e;
+ // Ignore
+ }
+ try {
+ stopOSGi(osgiHost);
+ } catch (Exception e) {
+ // Ignore
}
- } finally {
- NodeLauncherUtil.stopOSGi(host);
}
}
-
}
diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java
index c363de0e71..870a5d5e10 100644
--- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java
+++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncher.java
@@ -20,6 +20,8 @@
package org.apache.tuscany.sca.node.equinox.launcher;
import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.node;
+import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.startOSGi;
+import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.stopOSGi;
import java.io.IOException;
import java.util.logging.Level;
@@ -110,56 +112,113 @@ public class NodeLauncher {
}
public static void main(String[] args) throws Exception {
- logger.info("Apache Tuscany SCA OSGi Node is starting...");
+ logger.info("Apache Tuscany SCA Node is starting...");
- // Create a node
+ // Create a node launcher
NodeLauncher launcher = newInstance();
- OSGiHost host = NodeLauncherUtil.startOSGi();
+ OSGiHost osgiHost = null;
+ Object node = null;
+ ShutdownThread shutdown = null;
try {
- Object node;
- if (args.length == 1) {
+ // Start the OSGi host
+ osgiHost = startOSGi();
- // Create from a configuration URI
+ if (args.length ==1) {
+
+ // Create a node from a configuration URI
String configurationURI = args[0];
- logger.info("SCA OSGi Node configuration: " + configurationURI);
+ logger.info("SCA Node configuration: " + configurationURI);
node = launcher.createNodeFromURL(configurationURI);
} else {
-
- // Create from a composite URI and a contribution location
+
+ // 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 OSGi Node could not be started", e);
+ logger.log(Level.SEVERE, "SCA Node could not be started", e);
throw e;
}
- logger.info("SCA OSGi Node is now started.");
-
- logger.info("Press Enter to shutdown...");
+ logger.info("SCA Node is now started.");
+
+ // Install a shutdown hook
+ shutdown = new ShutdownThread(node, osgiHost);
+ Runtime.getRuntime().addShutdownHook(shutdown);
+
+ logger.info("Press enter to shutdown.");
try {
System.in.read();
} catch (IOException e) {
+
+ // Wait forever
+ Object lock = new Object();
+ synchronized(lock) {
+ lock.wait();
+ }
}
+ } finally {
+ // Remove the shutdown hook
+ if (shutdown != null) {
+ Runtime.getRuntime().removeShutdownHook(shutdown);
+ }
+
// Stop the node
+ if (node != null) {
+ stopNode(node);
+ }
+ if (osgiHost != null) {
+ stopOSGi(osgiHost);
+ }
+ }
+ }
+
+ /**
+ * Stop the given node.
+ *
+ * @param node
+ * @throws Exception
+ */
+ private static void stopNode(Object node) throws Exception {
+ try {
+ node.getClass().getMethod("stop").invoke(node);
+ logger.info("SCA Node is now stopped.");
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "SCA Node could not be stopped", e);
+ throw e;
+ }
+ }
+
+ private static class ShutdownThread extends Thread {
+ private Object node;
+ private OSGiHost osgiHost;
+
+ public ShutdownThread(Object node, OSGiHost osgiHost) {
+ super();
+ this.node = node;
+ this.osgiHost = osgiHost;
+ }
+
+ public void run() {
try {
- node.getClass().getMethod("stop").invoke(node);
+ stopNode(node);
} catch (Exception e) {
- logger.log(Level.SEVERE, "SCA OSGi Node could not be stopped", e);
- throw e;
+ // Ignore
+ }
+ try {
+ stopOSGi(osgiHost);
+ } catch (Exception e) {
+ // Ignore
}
- } finally {
- NodeLauncherUtil.stopOSGi(host);
}
}
-
}
diff --git a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
index 6b3981ed53..89d87b21d1 100644
--- a/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
+++ b/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
@@ -28,7 +28,6 @@ import java.util.logging.Level;
* @version $Rev$ $Date$
*/
final class NodeLauncherUtil {
- // private static final Logger logger = Logger.getLogger(NodeLauncherUtil.class.getName());
private static final String DOMAIN_MANAGER_LAUNCHER_BOOTSTRAP =
"org.apache.tuscany.sca.domain.manager.launcher.DomainManagerLauncherBootstrap";
@@ -138,7 +137,7 @@ final class NodeLauncherUtil {
return nodeDaemon;
} catch (Exception e) {
- NodeLauncher.logger.log(Level.SEVERE, "SCA Node Daemon could not be created", e);
+ NodeDaemonLauncher.logger.log(Level.SEVERE, "SCA Node Daemon could not be created", e);
throw new LauncherException(e);
} finally {
Thread.currentThread().setContextClassLoader(tccl);
@@ -166,7 +165,7 @@ final class NodeLauncherUtil {
return domainManager;
} catch (Exception e) {
- NodeLauncher.logger.log(Level.SEVERE, "SCA Domain Manager could not be created", e);
+ DomainManagerLauncher.logger.log(Level.SEVERE, "SCA Domain Manager could not be created", e);
throw new LauncherException(e);
} finally {
Thread.currentThread().setContextClassLoader(tccl);
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 f0c0a0a2f4..a9d7d84f5e 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
@@ -32,7 +32,7 @@ import java.util.logging.Logger;
*/
public class DomainManagerLauncher {
- private static final Logger logger = Logger.getLogger(DomainManagerLauncher.class.getName());
+ static final Logger logger = Logger.getLogger(DomainManagerLauncher.class.getName());
/**
* Constructs a new DomainManagerLauncher.
@@ -74,45 +74,60 @@ public class DomainManagerLauncher {
public static void main(String[] args) throws Exception {
logger.info("Apache Tuscany SCA Domain Manager is starting...");
- // Create a domain manager
+ // Create a launcher
DomainManagerLauncher launcher = newInstance();
- Object domainManager = launcher.createDomainManager();
- // Start the domain manager
+ Object domainManager = null;
+ ShutdownThread shutdown = null;
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.");
-
- ShutdownThread hook = new ShutdownThread(domainManager);
- Runtime.getRuntime().addShutdownHook(hook);
-
- logger.info("Press enter to shutdown.");
-
- try {
- System.in.read();
- } catch (IOException e) {
- // Wait forever
- Object lock = new Object();
- synchronized(lock) {
- lock.wait();
+ // 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) {
+
+ // Wait forever
+ Object lock = new Object();
+ synchronized(lock) {
+ lock.wait();
+ }
+ }
+ } finally {
+
+ // Remove the shutdown hook
+ if (shutdown != null) {
+ Runtime.getRuntime().removeShutdownHook(shutdown);
+ }
+
+ // Stop the domain manager
+ if (domainManager != null) {
+ stopDomainManager(domainManager);
}
}
-
- stop(domainManager);
- // Remove the hook
- Runtime.getRuntime().removeShutdownHook(hook);
}
- private static void stop(Object domainManager) throws Exception {
- // Stop the domain manager
- if (domainManager == null) {
- return;
- }
+ /**
+ * Stop the given domain manager.
+ *
+ * @param domainManager
+ * @throws Exception
+ */
+ private static void stopDomainManager(Object domainManager) throws Exception {
try {
domainManager.getClass().getMethod("stop").invoke(domainManager);
logger.info("SCA Domain Manager is now stopped.");
@@ -132,7 +147,7 @@ public class DomainManagerLauncher {
public void run() {
try {
- DomainManagerLauncher.stop(domainManager);
+ stopDomainManager(domainManager);
} catch (Exception e) {
// Ignore
}
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 2756bf2073..450cd85650 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
@@ -32,7 +32,7 @@ import java.util.logging.Logger;
*/
public class NodeDaemonLauncher {
- private static final Logger logger = Logger.getLogger(NodeDaemonLauncher.class.getName());
+ static final Logger logger = Logger.getLogger(NodeDaemonLauncher.class.getName());
/**
* Constructs a new node daemon launcher.
@@ -61,40 +61,84 @@ public class NodeDaemonLauncher {
}
public static void main(String[] args) throws Exception {
- logger.info("Apache Tuscany SCA Node Daemon starting...");
+ logger.info("Apache Tuscany SCA Node Daemon is starting...");
- // Create a node daemon
+ // Create a node launcher
NodeDaemonLauncher launcher = newInstance();
- Object daemon = launcher.createNodeDaemon();
-
- // Start the node daemon
- try {
- daemon.getClass().getMethod("start").invoke(daemon);
- } catch (Exception e) {
- logger.log(Level.SEVERE, "SCA Node Daemon could not be started", e);
- throw e;
- }
- logger.info("SCA Node Daemon started.");
-
- logger.info("Press enter to shutdown.");
+
+ Object node = null;
+ ShutdownThread shutdown = null;
try {
- System.in.read();
- } catch (IOException e) {
- // 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 enter to shutdown.");
+ try {
+ System.in.read();
+ } catch (IOException e) {
+
+ // Wait forever
+ Object lock = new Object();
+ synchronized(lock) {
+ lock.wait();
+ }
+ }
+ } finally {
- // Stop the node daemon
+ // Remove the shutdown hook
+ if (shutdown != null) {
+ Runtime.getRuntime().removeShutdownHook(shutdown);
+ }
+
+ // Stop the node
+ if (node != null) {
+ stopNode(node);
+ }
+ }
+ }
+
+ /**
+ * Stop the given node.
+ *
+ * @param node
+ * @throws Exception
+ */
+ private static void stopNode(Object node) throws Exception {
try {
- daemon.getClass().getMethod("stop").invoke(daemon);
+ node.getClass().getMethod("stop").invoke(node);
+ logger.info("SCA Node Daemon is now stopped.");
} catch (Exception e) {
logger.log(Level.SEVERE, "SCA Node Daemon could not be stopped", e);
throw e;
}
}
+ private static class ShutdownThread extends Thread {
+ private Object node;
+
+ public ShutdownThread(Object node) {
+ super();
+ this.node = node;
+ }
+
+ public void run() {
+ try {
+ stopNode(node);
+ } catch (Exception e) {
+ // Ignore
+ }
+ }
+ }
}
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 2171f5d597..c720d8f1e0 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
@@ -109,55 +109,98 @@ public class NodeLauncher {
}
public static void main(String[] args) throws Exception {
- logger.info("Apache Tuscany SCA Node starting...");
+ logger.info("Apache Tuscany SCA Node is starting...");
- // Create a node
+ // Create a node launcher
NodeLauncher launcher = newInstance();
- Object node;
- if (args.length ==1) {
+
+ Object node = null;
+ ShutdownThread shutdown = null;
+ try {
+ 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 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 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 started.");
-
- 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 enter to shutdown.");
+ try {
+ System.in.read();
+ } catch (IOException e) {
+
+ // Wait forever
+ Object lock = new Object();
+ synchronized(lock) {
+ lock.wait();
+ }
+ }
+ } finally {
+
+ // Remove the shutdown hook
+ if (shutdown != null) {
+ Runtime.getRuntime().removeShutdownHook(shutdown);
+ }
- // Wait forever
- Object lock = new Object();
- synchronized(lock) {
- lock.wait();
+ // Stop the node
+ if (node != null) {
+ stopNode(node);
}
}
+ }
- // Stop the node
+ /**
+ * Stop the given node.
+ *
+ * @param node
+ * @throws Exception
+ */
+ private static void stopNode(Object node) throws Exception {
try {
node.getClass().getMethod("stop").invoke(node);
+ logger.info("SCA Node is now stopped.");
} catch (Exception e) {
logger.log(Level.SEVERE, "SCA Node could not be stopped", e);
throw e;
}
}
+
+ private static class ShutdownThread extends Thread {
+ private Object node;
+
+ public ShutdownThread(Object node) {
+ super();
+ this.node = node;
+ }
+ public void run() {
+ try {
+ stopNode(node);
+ } catch (Exception e) {
+ // Ignore
+ }
+ }
+ }
}
diff --git a/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
index 6d8bcbe65c..7be1e14988 100644
--- a/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
+++ b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
@@ -45,7 +45,6 @@ import java.util.logging.Logger;
* @version $Rev$ $Date$
*/
final class NodeLauncherUtil {
-
private static final Logger logger = Logger.getLogger(NodeLauncherUtil.class.getName());
private static final String TUSCANY_HOME = "TUSCANY_HOME";
@@ -414,7 +413,7 @@ final class NodeLauncherUtil {
return nodeDaemon;
} catch (Exception e) {
- NodeLauncher.logger.log(Level.SEVERE, "SCA Node Daemon could not be created", e);
+ NodeDaemonLauncher.logger.log(Level.SEVERE, "SCA Node Daemon could not be created", e);
throw new LauncherException(e);
} finally {
Thread.currentThread().setContextClassLoader(tccl);
@@ -452,7 +451,7 @@ final class NodeLauncherUtil {
return domainManager;
} catch (Exception e) {
- NodeLauncher.logger.log(Level.SEVERE, "SCA Domain Manager could not be created", e);
+ DomainManagerLauncher.logger.log(Level.SEVERE, "SCA Domain Manager could not be created", e);
throw new LauncherException(e);
} finally {
Thread.currentThread().setContextClassLoader(tccl);