@Override protected void doStart() throws ElasticSearchException {
try {
this.datagramPacketReceive = new DatagramPacket(new byte[bufferSize], bufferSize);
this.datagramPacketSend = new DatagramPacket(new byte[bufferSize], bufferSize, InetAddress.getByName(group), port);
} catch (Exception e) {
throw new DiscoveryException("Failed to set datagram packets", e);
}
try {
MulticastSocket multicastSocket;
// if (NetworkUtils.canBindToMcastAddress()) {
// try {
// multicastSocket = new MulticastSocket(new InetSocketAddress(group, port));
// } catch (Exception e) {
// logger.debug("Failed to create multicast socket by binding to group address, binding to port", e);
// multicastSocket = new MulticastSocket(port);
// }
// } else {
multicastSocket = new MulticastSocket(port);
// }
multicastSocket.setTimeToLive(ttl);
// set the send interface
InetAddress multicastInterface = networkService.resolvePublishHostAddress(address);
multicastSocket.setInterface(multicastInterface);
multicastSocket.joinGroup(InetAddress.getByName(group));
multicastSocket.setReceiveBufferSize(bufferSize);
multicastSocket.setSendBufferSize(bufferSize);
multicastSocket.setSoTimeout(60000);
this.multicastSocket = multicastSocket;
} catch (Exception e) {
throw new DiscoveryException("Failed to setup multicast socket", e);
}
this.receiver = new Receiver();
this.receiverThread = daemonThreadFactory(settings, "discovery#multicast#received").newThread(receiver);
this.receiverThread.start();