summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2011-05-25 12:49:47 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2011-05-25 12:49:47 +0000
commite0f5b3ebd3785a7b73372d422fb28f1cedd25638 (patch)
treef29caf585922854ad9a19dfec942f9ffedf47423 /sca-java-2.x
parent2d151a899b913cba1e168c833a6e805ef8b81008 (diff)
Set up listener to allow consistent shutdown
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1127503 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/main/java/org/apache/tuscany/sca/impl/Tuscany.java77
1 files changed, 33 insertions, 44 deletions
diff --git a/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/main/java/org/apache/tuscany/sca/impl/Tuscany.java b/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/main/java/org/apache/tuscany/sca/impl/Tuscany.java
index 6915ca73d7..5c6ca7476e 100644
--- a/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/main/java/org/apache/tuscany/sca/impl/Tuscany.java
+++ b/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/main/java/org/apache/tuscany/sca/impl/Tuscany.java
@@ -65,38 +65,40 @@ public class Tuscany {
URL nodeConfigURL = nodeDirectory.toURI().resolve("node.xml").toURL();
Node node = nodeFactory.createNode(nodeConfigURL);
- ShutdownThread shutdown = new ShutdownThread(node);
- Runtime.getRuntime().addShutdownHook(shutdown);
-
- node.start();
-
- // for testing we're going to set up a deamon that listens for
- // a shutdown message on a specified port (well it actually just
- // waits for a client to connect to the port as that's all we need
- // for now). If no port is specified then just stop straight away
-
- if (deamonPort >= 0){
- // Its a runtime that has to act as a deamon
- ServerSocket serverSocket = null;
-
- try {
- serverSocket = new ServerSocket(deamonPort);
- } catch (IOException e) {
- System.out.println("Can't create a ServerSocket on port: " + deamonPort);
- }
+ try {
+ node.start();
- // all we're doing here is waiting for a connection. If we wanted to implement
- // a real deamon we should perhaps listen to what's coming in over the resulting socket
- // and see if a shutdown has been requested
- Socket clientSocket = null;
- try {
- clientSocket = serverSocket.accept();
- } catch (IOException e) {
- System.out.println("Accept failed on port: " + deamonPort);
- }
- }
+ // for testing we're going to set up a deamon that listens for
+ // a shutdown message on a specified port (well it actually just
+ // waits for a client to connect to the port as that's all we need
+ // for now). If no port is specified then just stop straight away
+
+ if (deamonPort >= 0){
+ // Its a runtime that has to act as a deamon
+ ServerSocket serverSocket = null;
+
+ try {
+ serverSocket = new ServerSocket(deamonPort);
+ } catch (IOException e) {
+ System.out.println("Can't create a ServerSocket on port: " + deamonPort);
+ return;
+ }
+
+ // all we're doing here is waiting for a connection. If we wanted to implement
+ // a real deamon we should perhaps listen to what's coming in over the resulting socket
+ // and see if a shutdown has been requested
+ Socket clientSocket = null;
+ try {
+ clientSocket = serverSocket.accept();
+ } catch (IOException e) {
+ System.out.println("Accept failed on port: " + deamonPort);
+ return;
+ }
+ }
- node.stop();
+ } finally {
+ node.stop();
+ }
}
/**
@@ -132,18 +134,5 @@ public class Tuscany {
return false;
}
}
-
- private static class ShutdownThread extends Thread {
- private Node node;
-
- public ShutdownThread(Node node) {
- super();
- this.node = node;
- }
-
- @Override
- public void run() {
- node.stop();
- }
- }
+
} \ No newline at end of file