in qpid-jms-discovery/src/main/java/org/apache/qpid/jms/provider/discovery/multicast/MulticastDiscoveryAgent.java [112:188]
public void start() throws ProviderException, IllegalStateException {
if (listener == null) {
throw new IllegalStateException("No DiscoveryListener configured.");
}
if (started.compareAndSet(false, true)) {
if (group == null || group.length() == 0) {
throw new ProviderException("You must specify a group to discover");
}
if (discoveryURI == null) {
try {
discoveryURI = new URI(DEFAULT_DISCOVERY_URI_STRING);
} catch (URISyntaxException e) {
// Default is always valid.
}
if (discoveryURI == null) {
throw new RuntimeException("Discovery URI unexpectedly null");
}
}
LOG.trace("mcast - discoveryURI = {}", discoveryURI);
String myHost = discoveryURI.getHost();
int myPort = discoveryURI.getPort();
if (myHost == null || DEFAULT_HOST_STR.equals(myHost)) {
myHost = DEFAULT_HOST_IP;
}
if (myPort < 0) {
myPort = DEFAULT_PORT;
}
LOG.trace("mcast - myHost = {}", myHost);
LOG.trace("mcast - myPort = {}", myPort);
LOG.trace("mcast - group = {}", group);
LOG.trace("mcast - interface = {}", mcInterface);
LOG.trace("mcast - network interface = {}", mcNetworkInterface);
LOG.trace("mcast - join network interface = {}", mcJoinNetworkInterface);
try {
this.inetAddress = InetAddress.getByName(myHost);
this.sockAddress = new InetSocketAddress(this.inetAddress, myPort);
mcast = new MulticastSocket(myPort);
mcast.setLoopbackMode(loopBackMode);
mcast.setTimeToLive(getTimeToLive());
if (mcJoinNetworkInterface != null) {
mcast.joinGroup(sockAddress, NetworkInterface.getByName(mcJoinNetworkInterface));
} else {
if (mcNetworkInterface != null) {
mcast.setNetworkInterface(NetworkInterface.getByName(mcNetworkInterface));
} else {
trySetNetworkInterface(mcast);
}
mcast.joinGroup(inetAddress);
}
mcast.setSoTimeout((int) keepAliveInterval);
if (mcInterface != null) {
mcast.setInterface(InetAddress.getByName(mcInterface));
}
if (mcNetworkInterface != null) {
mcast.setNetworkInterface(NetworkInterface.getByName(mcNetworkInterface));
}
} catch (IOException e) {
throw ProviderExceptionSupport.createOrPassthroughFatal(e);
}
runner = new Thread(this);
runner.setName(this.toString() + ":" + runner.getName());
runner.setDaemon(true);
runner.start();
}
}