tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r1100932 - /tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/client/HazelcastClientEndpointRegistry.java
Date Mon, 09 May 2011 09:44:43 GMT
Author: antelder
Date: Mon May  9 09:44:43 2011
New Revision: 1100932

URL: http://svn.apache.org/viewvc?rev=1100932&view=rev
Log:
Simplify the approach to trying to find a local runtime instance, the previous code didn't
work with some network configs

Modified:
    tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/client/HazelcastClientEndpointRegistry.java

Modified: tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/client/HazelcastClientEndpointRegistry.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/client/HazelcastClientEndpointRegistry.java?rev=1100932&r1=1100931&r2=1100932&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/client/HazelcastClientEndpointRegistry.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/domain-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/client/HazelcastClientEndpointRegistry.java
Mon May  9 09:44:43 2011
@@ -19,11 +19,9 @@
 
 package org.apache.tuscany.sca.endpoint.hazelcast.client;
 
-import java.net.BindException;
+import java.io.IOException;
 import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.ServerSocket;
-import java.util.Enumeration;
+import java.net.Socket;
 import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -86,7 +84,7 @@ public class HazelcastClientEndpointRegi
             }
         }
         if (rc.getWKAs().size() < 1) {
-            throw new IllegalArgumentException("Must specify remote IP address(es) for domain");
+            throw new IllegalArgumentException("No local domain instance found, please use
domain URI 'wka=' argument to define IP address(es) for domain");
         }
         
         // Hazelcast is outputs a lot on info level log messages which are unnecessary for
us,
@@ -109,31 +107,24 @@ public class HazelcastClientEndpointRegi
     }
 
     /**
-     * See if there's a local IP listening on port 14820
+     * As a default connect to a local runtime instance listening on port 14820
      */
-    protected static String getDefaultWKA() {
-        try {
-            Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
-            while (nis.hasMoreElements()) {
-                NetworkInterface ni = nis.nextElement();
-                Enumeration<InetAddress> ips = ni.getInetAddresses();
-                while (ips.hasMoreElements()) {
-                    InetAddress addr = ips.nextElement();
-                    ServerSocket ss = null;
-                    try {
-                        ss = new ServerSocket(14820, 0, addr);
-                    } catch (BindException e) {
-                        return addr.getHostAddress() + ":14820";
-                    } finally {
-                        if (ss != null) {
-                            ss.close();
-                        }
-                    }
-                }
-            }
-        } catch (Exception e) {
-        }
-        return null;
-    }    
-    
+	protected static String getDefaultWKA() {
+        Socket s = null;
+		try {
+	        s = new Socket(InetAddress.getLocalHost(), 14820);
+	        if (s.isConnected()) {
+	    		return s.getInetAddress().getHostAddress() + ":14820";
+	        }
+		} catch (IOException e) {
+		} finally {
+			if (s != null) {
+				try {
+					s.close();
+				} catch (IOException e) {
+				}
+			}
+		}
+        return null;	        	
+	}
 }



Mime
View raw message