use of java.net.MulticastSocket in project hadoop by apache.
the class TestGangliaSink method testShouldCreateDatagramSocketByDefault.
@Test
public void testShouldCreateDatagramSocketByDefault() throws Exception {
SubsetConfiguration conf = new ConfigBuilder().subset("test.sink.ganglia");
GangliaSink30 gangliaSink = new GangliaSink30();
gangliaSink.init(conf);
DatagramSocket socket = gangliaSink.getDatagramSocket();
assertFalse("Did not create DatagramSocket", socket == null || socket instanceof MulticastSocket);
}
use of java.net.MulticastSocket in project hadoop by apache.
the class TestGangliaSink method testShouldCreateDatagramSocketIfMulticastIsDisabled.
@Test
public void testShouldCreateDatagramSocketIfMulticastIsDisabled() throws Exception {
SubsetConfiguration conf = new ConfigBuilder().add("test.sink.ganglia.multicast", false).subset("test.sink.ganglia");
GangliaSink30 gangliaSink = new GangliaSink30();
gangliaSink.init(conf);
DatagramSocket socket = gangliaSink.getDatagramSocket();
assertFalse("Did not create DatagramSocket", socket == null || socket instanceof MulticastSocket);
}
use of java.net.MulticastSocket in project tomcat by apache.
the class MultiCastSender method send.
@Override
public int send(String mess) throws Exception {
if (s == null) {
try {
group = InetAddress.getByName(config.getGroup());
if (config.getHost() != null) {
InetAddress addr = InetAddress.getByName(config.getHost());
InetSocketAddress addrs = new InetSocketAddress(addr, config.getMultiport());
s = new MulticastSocket(addrs);
} else
s = new MulticastSocket(config.getMultiport());
s.setTimeToLive(config.getTtl());
s.joinGroup(group);
} catch (Exception ex) {
log.error("Unable to use multicast: " + ex);
s = null;
return -1;
}
}
byte[] buf;
buf = mess.getBytes(StandardCharsets.US_ASCII);
DatagramPacket data = new DatagramPacket(buf, buf.length, group, config.getMultiport());
try {
s.send(data);
} catch (Exception ex) {
log.error("Unable to send collected load information: " + ex);
s.close();
s = null;
return -1;
}
return 0;
}
use of java.net.MulticastSocket in project jcollectd by collectd.
the class UdpReceiver method getSocket.
public DatagramSocket getSocket() throws IOException {
if (_socket == null) {
if (_bindAddress == null) {
_socket = new DatagramSocket(_port);
} else {
InetAddress addr = InetAddress.getByName(_bindAddress);
if (addr.isMulticastAddress()) {
MulticastSocket mcast = new MulticastSocket(_port);
if (_ifAddress != null) {
mcast.setInterface(InetAddress.getByName(_ifAddress));
}
mcast.joinGroup(addr);
_socket = mcast;
} else {
_socket = new DatagramSocket(_port, addr);
}
}
}
return _socket;
}
use of java.net.MulticastSocket in project dubbo by alibaba.
the class MulticastRegistryTest method testDefaultPort.
@Test
public void testDefaultPort() {
MulticastRegistry multicastRegistry = new MulticastRegistry(URL.valueOf("multicast://224.5.6.7"));
try {
MulticastSocket multicastSocket = multicastRegistry.getMutilcastSocket();
Assert.assertEquals(1234, multicastSocket.getLocalPort());
} finally {
multicastRegistry.destroy();
}
}
Aggregations