Author: andygumbrecht
Date: Fri Jun 29 11:46:39 2012
New Revision: 1355329

URL: http://svn.apache.org/viewvc?rev=1355329&view=rev
Log:
Make MulticastPulseClient utility more resilient to slow network.
Fix MulticastPulseAgent client host lookup and only check if required.

Modified:
    
openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastPulseClient.java
    
openejb/trunk/openejb/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MulticastPulseAgent.java

Modified: 
openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastPulseClient.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastPulseClient.java?rev=1355329&r1=1355328&r2=1355329&view=diff
==============================================================================
--- 
openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastPulseClient.java
 (original)
+++ 
openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/MulticastPulseClient.java
 Fri Jun 29 11:46:39 2012
@@ -387,7 +387,7 @@ public class MulticastPulseClient extend
             opt('p', "port").type(int.class).value(6142)
                     .description("Multicast port");
 
-            opt('t', "timeout").type(int.class).value(150)
+            opt('t', "timeout").type(int.class).value(1000)
                     .description("Pulse back timeout");
         }
 
@@ -417,10 +417,10 @@ public class MulticastPulseClient extend
 
         final Options options = arguments.options();
 
-        final String group = options.get("group", "*");
+        final String discover = options.get("group", "*");
         final String mchost = options.get("host", "239.255.3.2");
         final int mcport = options.get("port", 6142);
-        final int timeout = options.get("timeout", 150);
+        final int timeout = options.get("timeout", 1500);
         final AtomicBoolean running = new AtomicBoolean(true);
 
         final Thread t = new Thread(new Runnable() {
@@ -431,7 +431,7 @@ public class MulticastPulseClient extend
                     Set<URI> uriSet = null;
                     try {
                         uriSet = MulticastPulseClient.discoverURIs(
-                                group,
+                                discover,
                                 new HashSet<String>(Arrays.asList("ejbd", 
"ejbds", "http", "https")),
                                 mchost,
                                 mcport,
@@ -441,6 +441,7 @@ public class MulticastPulseClient extend
                     }
 
                     if (uriSet != null && uriSet.size() > 0) {
+
                         for (URI uri : uriSet) {
 
                             final String server = 
uri.getScheme().replace("mp-", "");
@@ -460,7 +461,7 @@ public class MulticastPulseClient extend
                             boolean b = false;
                             final Socket s = new Socket();
                             try {
-                                s.connect(new InetSocketAddress(host, port), 
150);
+                                s.connect(new InetSocketAddress(host, port), 
1000);
                                 b = true;
                             } catch (Throwable e) {
                                 //Ignore
@@ -472,16 +473,16 @@ public class MulticastPulseClient extend
                                 }
                             }
 
-                            System.out.println("ServerHost: " + server + " - 
Group: " + group + " - Service: " + uri.toASCIIString() + " is reachable: " + 
b);
+                            System.out.println(server + ":" + group + " - " + 
uri.toASCIIString() + " is reachable: " + b);
                         }
                     } else {
-                        System.out.println("Did not discover any URIs to 
test");
+                        System.out.println("### Failed to discover server: " + 
discover);
                     }
 
                     System.out.println(".");
 
                     try {
-                        Thread.sleep(1000);
+                        Thread.sleep(500);
                     } catch (InterruptedException e) {
                         //Ignore
                     }

Modified: 
openejb/trunk/openejb/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MulticastPulseAgent.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MulticastPulseAgent.java?rev=1355329&r1=1355328&r2=1355329&view=diff
==============================================================================
--- 
openejb/trunk/openejb/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MulticastPulseAgent.java
 (original)
+++ 
openejb/trunk/openejb/server/openejb-multicast/src/main/java/org/apache/openejb/server/discovery/MulticastPulseAgent.java
 Fri Jun 29 11:46:39 2012
@@ -205,17 +205,18 @@ public class MulticastPulseAgent impleme
 
                                     s = (s.replace(CLIENT, ""));
 
-                                    final String client = sa.toString();
-                                    if (MulticastPulseAgent.this.loopbackOnly) 
{
-                                        //We only have local services, so make 
sure the request is from a local source else ignore it
-                                        if 
(!MulticastPulseAgent.isLocalAddress(client, false)) {
-                                            log.debug(String.format("Ignoring 
client %1$s pulse request for group: %2$s - No remote services available", 
client, s));
-                                            return;
-                                        }
-                                    }
+                                    final String client = ((InetSocketAddress) 
sa).getAddress().getHostAddress();
 
                                     if 
(MulticastPulseAgent.this.group.equals(s) || "*".equals(s)) {
 
+                                        if 
(MulticastPulseAgent.this.loopbackOnly) {
+                                            //We only have local services, so 
make sure the request is from a local source else ignore it
+                                            if 
(!MulticastPulseAgent.isLocalAddress(client, false)) {
+                                                
log.debug(String.format("Ignoring remote client %1$s pulse request for group: 
%2$s - No remote services available", client, s));
+                                                continue;
+                                            }
+                                        }
+
                                         log.debug(String.format("Answering 
client %1$s pulse request for group: %2$s", client, s));
                                         
ms.send(MulticastPulseAgent.this.response);
                                     } else {


Reply via email to