activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [2/2] activemq git commit: [AMQ-5520] Use a network interface that actually supports multicast and is up
Date Wed, 14 Jan 2015 19:45:10 GMT
[AMQ-5520] Use a network interface that actually supports multicast and is up


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/f4eade2b
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/f4eade2b
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/f4eade2b

Branch: refs/heads/trunk
Commit: f4eade2bb3bb83131f17d2768d2218770f0123d3
Parents: 0d81564
Author: Daniel Kulp <dkulp@apache.org>
Authored: Wed Jan 14 13:43:10 2015 -0500
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Wed Jan 14 13:43:10 2015 -0500

----------------------------------------------------------------------
 .../multicast/MulticastDiscoveryAgent.java      | 25 ++++++++++++++++++++
 1 file changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/f4eade2b/activemq-client/src/main/java/org/apache/activemq/transport/discovery/multicast/MulticastDiscoveryAgent.java
----------------------------------------------------------------------
diff --git a/activemq-client/src/main/java/org/apache/activemq/transport/discovery/multicast/MulticastDiscoveryAgent.java
b/activemq-client/src/main/java/org/apache/activemq/transport/discovery/multicast/MulticastDiscoveryAgent.java
index 98d3dd2..345ffdb 100755
--- a/activemq-client/src/main/java/org/apache/activemq/transport/discovery/multicast/MulticastDiscoveryAgent.java
+++ b/activemq-client/src/main/java/org/apache/activemq/transport/discovery/multicast/MulticastDiscoveryAgent.java
@@ -21,12 +21,17 @@ import java.io.IOException;
 import java.net.DatagramPacket;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
+import java.net.InterfaceAddress;
 import java.net.MulticastSocket;
 import java.net.NetworkInterface;
 import java.net.SocketAddress;
+import java.net.SocketException;
 import java.net.SocketTimeoutException;
 import java.net.URI;
+import java.util.ArrayList;
+import java.util.Enumeration;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutorService;
@@ -316,6 +321,7 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable
{
                 mcast.joinGroup(sockAddress, NetworkInterface.getByName(mcJoinNetworkInterface));
             }
             else {
+                mcast.setNetworkInterface(findNetworkInterface());
             	mcast.joinGroup(inetAddress);
             }
             mcast.setSoTimeout((int)keepAliveInterval);
@@ -332,6 +338,25 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable
{
             doAdvertizeSelf();
         }
     }
+    
+    private NetworkInterface findNetworkInterface() throws SocketException {
+        Enumeration<NetworkInterface> ifcs = NetworkInterface.getNetworkInterfaces();
+        List<NetworkInterface> possibles = new ArrayList<NetworkInterface>();
+        while (ifcs.hasMoreElements()) {
+            NetworkInterface ni = ifcs.nextElement();
+            if (ni.supportsMulticast()
+                && ni.isUp()) {
+                for (InterfaceAddress ia : ni.getInterfaceAddresses()) {
+                    if (ia.getAddress() instanceof java.net.Inet4Address
+                        && !ia.getAddress().isLoopbackAddress()
+                        && !ni.getDisplayName().startsWith("vnic")) {
+                        possibles.add(ni);
+                    }
+                }
+            }
+        }
+        return possibles.isEmpty() ? null : possibles.get(possibles.size() - 1);
+    }
 
     /**
      * stop the channel


Mime
View raw message