tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sl...@apache.org
Subject svn commit: r1127503 - /tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/main/java/org/apache/tuscany/sca/impl/Tuscany.java
Date Wed, 25 May 2011 12:49:48 GMT
Author: slaws
Date: Wed May 25 12:49:47 2011
New Revision: 1127503

URL: http://svn.apache.org/viewvc?rev=1127503&view=rev
Log:
Set up listener to allow consistent shutdown

Modified:
    tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/main/java/org/apache/tuscany/sca/impl/Tuscany.java

Modified: tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/main/java/org/apache/tuscany/sca/impl/Tuscany.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/main/java/org/apache/tuscany/sca/impl/Tuscany.java?rev=1127503&r1=1127502&r2=1127503&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/main/java/org/apache/tuscany/sca/impl/Tuscany.java
(original)
+++ tuscany/sca-java-2.x/trunk/testing/itest/nodes/two-jvm-hazelcast/src/main/java/org/apache/tuscany/sca/impl/Tuscany.java
Wed May 25 12:49:47 2011
@@ -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



Mime
View raw message