From e0f5b3ebd3785a7b73372d422fb28f1cedd25638 Mon Sep 17 00:00:00 2001 From: slaws Date: Wed, 25 May 2011 12:49:47 +0000 Subject: Set up listener to allow consistent shutdown git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1127503 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/tuscany/sca/impl/Tuscany.java | 77 ++++++++++------------ 1 file changed, 33 insertions(+), 44 deletions(-) (limited to 'sca-java-2.x') 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 -- cgit v1.2.3