Skip to content

Commit

Permalink
Merge pull request #152 from rhusar/MODCLUSTER-432_osx_fix
Browse files Browse the repository at this point in the history
MODCLUSTER-432 Multicast discovery does not work on Mac OS X, fails with "Can't assign requested address"
  • Loading branch information
jfclere committed Jul 9, 2015
2 parents 385a9cf + d74dc22 commit 9202ebd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
Expand Up @@ -28,8 +28,7 @@

/**
* @author Paul Ferraro
*
*/
public interface AdvertiseListenerFactory {
public AdvertiseListener createListener(MCMPHandler handler, AdvertiseConfiguration config) throws IOException;
AdvertiseListener createListener(MCMPHandler handler, AdvertiseConfiguration config) throws IOException;
}
Expand Up @@ -34,19 +34,20 @@
import org.jboss.modcluster.advertise.MulticastSocketFactory;

/**
* On Linux, we attempt to avoid cross-talk problem by binding the MulticastSocket to the multicast address, if possible. See
* {@linkplain https://jira.jboss.org/jira/browse/JGRP-777}
* On Linux, Solaris and HP-UX, we attempt to avoid cross-talk problem by binding the {@link MulticastSocket} to the
* multicast address, if possible. See <a href="https://jira.jboss.org/jira/browse/JGRP-777">JGRP-777</a>.
*
* @author Paul Ferraro
*/
public class MulticastSocketFactoryImpl implements MulticastSocketFactory {
final Logger log = Logger.getLogger(this.getClass());

private final boolean linuxlike;
private final boolean canBindMulticastSocket;

public MulticastSocketFactoryImpl() {
String value = this.getSystemProperty("os.name");
this.linuxlike = (value != null) && (value.toLowerCase().startsWith("linux") || value.toLowerCase().startsWith("mac") || value.toLowerCase().startsWith("hp"));
this.canBindMulticastSocket = (value != null) && (value.toLowerCase().startsWith("linux") ||
value.toLowerCase().startsWith("sun") || value.toLowerCase().startsWith("hp"));
}

private String getSystemProperty(final String key) {
Expand All @@ -65,13 +66,9 @@ public String run() {
return AccessController.doPrivileged(action);
}

/**
* @{inheritDoc
* @see org.jboss.modcluster.advertise.MulticastSocketFactory#createMulticastSocket(java.net.InetAddress, int)
*/
@Override
public MulticastSocket createMulticastSocket(InetAddress address, int port) throws IOException {
if ((address == null) || !this.linuxlike) return new MulticastSocket(port);
if ((address == null) || !this.canBindMulticastSocket) return new MulticastSocket(port);

if (!address.isMulticastAddress()) {
ModClusterLogger.LOGGER.createMulticastSocketWithUnicastAddress(address);
Expand Down
Expand Up @@ -46,7 +46,6 @@
import org.jboss.modcluster.mcmp.MCMPHandler;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.ArgumentCaptor;

Expand Down Expand Up @@ -100,7 +99,6 @@ public void tearDown() {
}

@Test
@Ignore("MODCLUSTER-432")
public void testBasicOperation() throws IOException, NoSuchAlgorithmException {
ArgumentCaptor<InetAddress> capturedAddress = ArgumentCaptor.forClass(InetAddress.class);

Expand Down
Expand Up @@ -31,7 +31,6 @@

import org.jboss.modcluster.advertise.impl.MulticastSocketFactoryImpl;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;

/**
Expand All @@ -51,7 +50,6 @@ public class MulticastSocketFactoryImplTestCase {
private static final int PORT = 23364;

@Test
@Ignore("MODCLUSTER-432")
public void testMulticastSocketNoCrossTalk() throws IOException {
InetAddress address = InetAddress.getByName(GROUP1);

Expand Down

0 comments on commit 9202ebd

Please sign in to comment.