use of java.net.DatagramSocket 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.DatagramSocket 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.DatagramSocket in project hadoop by apache.
the class SimpleUdpClient method run.
public void run() throws IOException {
InetAddress IPAddress = InetAddress.getByName(host);
byte[] sendData = request.getBytes();
byte[] receiveData = new byte[65535];
// Use the provided socket if there is one, else just make a new one.
DatagramSocket socket = this.clientSocket == null ? new DatagramSocket() : this.clientSocket;
try {
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port);
socket.send(sendPacket);
socket.setSoTimeout(udpTimeoutMillis);
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
socket.receive(receivePacket);
// Check reply status
XDR xdr = new XDR(Arrays.copyOfRange(receiveData, 0, receivePacket.getLength()));
RpcReply reply = RpcReply.read(xdr);
if (reply.getState() != RpcReply.ReplyState.MSG_ACCEPTED) {
throw new IOException("Request failed: " + reply.getState());
}
} finally {
// caller of this UDP client to close that socket.
if (this.clientSocket == null) {
socket.close();
}
}
}
use of java.net.DatagramSocket in project hadoop by apache.
the class PrivilegedNfsGatewayStarter method init.
@Override
public void init(DaemonContext context) throws Exception {
System.err.println("Initializing privileged NFS client socket...");
NfsConfiguration conf = new NfsConfiguration();
int clientPort = conf.getInt(NfsConfigKeys.DFS_NFS_REGISTRATION_PORT_KEY, NfsConfigKeys.DFS_NFS_REGISTRATION_PORT_DEFAULT);
if (clientPort < 1 || clientPort > 1023) {
throw new RuntimeException("Must start privileged NFS server with '" + NfsConfigKeys.DFS_NFS_REGISTRATION_PORT_KEY + "' configured to a " + "privileged port.");
}
try {
InetSocketAddress socketAddress = new InetSocketAddress("localhost", clientPort);
registrationSocket = new DatagramSocket(null);
registrationSocket.setReuseAddress(true);
registrationSocket.bind(socketAddress);
} catch (SocketException e) {
LOG.error("Init failed for port=" + clientPort, e);
throw e;
}
args = context.getArguments();
}
use of java.net.DatagramSocket in project hadoop by apache.
the class TestUdpServer method testRequest.
static void testRequest(XDR request, XDR request2) {
try {
DatagramSocket clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName("localhost");
byte[] sendData = request.getBytes();
byte[] receiveData = new byte[65535];
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, Nfs3Constant.SUN_RPCBIND);
clientSocket.send(sendPacket);
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
clientSocket.receive(receivePacket);
clientSocket.close();
} catch (UnknownHostException e) {
System.err.println("Don't know about host: localhost.");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for " + "the connection to: localhost.");
System.exit(1);
}
}
Aggregations