Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0F4DC17A59 for ; Wed, 14 Jan 2015 19:45:08 +0000 (UTC) Received: (qmail 20425 invoked by uid 500); 14 Jan 2015 19:45:09 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 20381 invoked by uid 500); 14 Jan 2015 19:45:09 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 20279 invoked by uid 99); 14 Jan 2015 19:45:09 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Jan 2015 19:45:09 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 59588A428CE; Wed, 14 Jan 2015 19:45:09 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dkulp@apache.org To: commits@activemq.apache.org Date: Wed, 14 Jan 2015 19:45:10 -0000 Message-Id: <0570fb4a8b9941b698a7e588cb0a3128@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/2] activemq git commit: [AMQ-5520] Use a network interface that actually supports multicast and is up [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 Authored: Wed Jan 14 13:43:10 2015 -0500 Committer: Daniel Kulp 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 ifcs = NetworkInterface.getNetworkInterfaces(); + List possibles = new ArrayList(); + 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