git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@813721 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2009-09-11 08:46:40 +00:00
parent d4133c4de8
commit 673fee193d
1 changed files with 39 additions and 21 deletions

View File

@ -21,6 +21,7 @@ import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.MulticastSocket;
import java.net.NetworkInterface;
import java.net.SocketAddress;
import java.net.SocketTimeoutException;
import java.net.URI;
@ -53,7 +54,6 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable {
public static final String DEFAULT_HOST_IP = System.getProperty("activemq.partition.discovery", "239.255.2.3");
public static final int DEFAULT_PORT = 6155;
private static final Log LOG = LogFactory.getLog(MulticastDiscoveryAgent.class);
private static final String TYPE_SUFFIX = "ActiveMQ-4.";
private static final String ALIVE = "alive.";
@ -69,6 +69,25 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable {
private boolean useExponentialBackOff;
private int maxReconnectAttempts;
private int timeToLive = 1;
private boolean loopBackMode;
private Map<String, RemoteBrokerData> brokersByService = new ConcurrentHashMap<String, RemoteBrokerData>();
private String group = "default";
private URI discoveryURI;
private InetAddress inetAddress;
private SocketAddress sockAddress;
private DiscoveryListener discoveryListener;
private String selfService;
private MulticastSocket mcast;
private Thread runner;
private long keepAliveInterval = DEFAULT_IDLE_TIME;
private String mcInterface;
private String mcNetworkInterface;
private long lastAdvertizeTime;
private AtomicBoolean started = new AtomicBoolean(false);
private boolean reportAdvertizeFailed = true;
private ExecutorService executor = null;
class RemoteBrokerData {
final String brokerName;
final String service;
@ -161,23 +180,6 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable {
}
}
private int timeToLive = 1;
private boolean loopBackMode;
private Map<String, RemoteBrokerData> brokersByService = new ConcurrentHashMap<String, RemoteBrokerData>();
private String group = "default";
private URI discoveryURI;
private InetAddress inetAddress;
private SocketAddress sockAddress;
private DiscoveryListener discoveryListener;
private String selfService;
private MulticastSocket mcast;
private Thread runner;
private long keepAliveInterval = DEFAULT_IDLE_TIME;
private long lastAdvertizeTime;
private AtomicBoolean started = new AtomicBoolean(false);
private boolean reportAdvertizeFailed = true;
private ExecutorService executor = null;
/**
* Set the discovery listener
*
@ -249,6 +251,14 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable {
this.keepAliveInterval = keepAliveInterval;
}
public void setInterface(String mcInterface) {
this.mcInterface = mcInterface;
}
public void setNetworkInterface(String mcNetworkInterface) {
this.mcNetworkInterface = mcNetworkInterface;
}
/**
* start the discovery agent
*
@ -287,6 +297,8 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable {
LOG.trace("start - myHost = " + myHost);
LOG.trace("start - myPort = " + myPort);
LOG.trace("start - group = " + group );
LOG.trace("start - interface = " + mcInterface );
LOG.trace("start - network interface = " + mcNetworkInterface );
}
this.inetAddress = InetAddress.getByName(myHost);
@ -296,6 +308,12 @@ public class MulticastDiscoveryAgent implements DiscoveryAgent, Runnable {
mcast.setTimeToLive(getTimeToLive());
mcast.joinGroup(inetAddress);
mcast.setSoTimeout((int)keepAliveInterval);
if (mcInterface != null) {
mcast.setInterface(InetAddress.getByName(mcInterface));
}
if (mcNetworkInterface != null) {
mcast.setNetworkInterface(NetworkInterface.getByName(mcNetworkInterface));
}
runner = new Thread(this);
runner.setName(this.toString() + ":" + runner.getName());
runner.setDaemon(true);