use of java.net.DatagramSocket in project pinpoint by naver.
the class SpanStreamUdpSender method createChannel.
private DatagramChannel createChannel(String host, int port, int timeout, int sendBufferSize) {
DatagramChannel datagramChannel = null;
DatagramSocket socket = null;
try {
datagramChannel = DatagramChannel.open();
socket = datagramChannel.socket();
socket.setSoTimeout(timeout);
socket.setSendBufferSize(sendBufferSize);
if (logger.isWarnEnabled()) {
final int checkSendBufferSize = socket.getSendBufferSize();
if (sendBufferSize != checkSendBufferSize) {
logger.warn("DatagramChannel.setSendBufferSize() error. {}!={}", sendBufferSize, checkSendBufferSize);
}
}
InetSocketAddress serverAddress = new InetSocketAddress(host, port);
datagramChannel.connect(serverAddress);
return datagramChannel;
} catch (IOException e) {
if (socket != null) {
socket.close();
}
if (datagramChannel != null) {
try {
datagramChannel.close();
} catch (IOException ignored) {
}
}
throw new IllegalStateException("DatagramChannel create fail. Cause" + e.getMessage(), e);
}
}
use of java.net.DatagramSocket in project pinpoint by naver.
the class NioUDPDataSender method createChannel.
private DatagramChannel createChannel(String host, int port, int timeout, int sendBufferSize) {
DatagramChannel datagramChannel = null;
DatagramSocket socket = null;
try {
datagramChannel = DatagramChannel.open();
socket = datagramChannel.socket();
socket.setSoTimeout(timeout);
socket.setSendBufferSize(sendBufferSize);
if (logger.isWarnEnabled()) {
final int checkSendBufferSize = socket.getSendBufferSize();
if (sendBufferSize != checkSendBufferSize) {
logger.warn("DatagramChannel.setSendBufferSize() error. {}!={}", sendBufferSize, checkSendBufferSize);
}
}
InetSocketAddress serverAddress = new InetSocketAddress(host, port);
datagramChannel.connect(serverAddress);
return datagramChannel;
} catch (IOException e) {
if (socket != null) {
socket.close();
}
if (datagramChannel != null) {
try {
datagramChannel.close();
} catch (IOException ignored) {
}
}
throw new IllegalStateException("DatagramChannel create fail. Cause" + e.getMessage(), e);
}
}
use of java.net.DatagramSocket in project pinpoint by naver.
the class UDPChecker method check.
@Override
protected boolean check(InetSocketAddress address, byte[] requestData, byte[] expectedResponseData) {
DatagramSocket socket = null;
try {
socket = createSocket();
write(socket, requestData, address);
byte[] responseData = read(socket, expectedResponseData.length);
return Arrays.equals(expectedResponseData, responseData);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (socket != null) {
socket.close();
}
}
return false;
}
use of java.net.DatagramSocket in project pinpoint by naver.
the class UDPChecker method createSocket.
private DatagramSocket createSocket(InetSocketAddress socketAddress) throws IOException {
DatagramSocket socket = new DatagramSocket();
socket.connect(socketAddress);
socket.setSoTimeout(3000);
return socket;
}
use of java.net.DatagramSocket in project pinpoint by naver.
the class TestUDPReceiver method start.
@PostConstruct
@Override
public void start() {
logger.info("{} start.", receiverName);
afterPropertiesSet();
final DatagramSocket socket = this.socket;
if (socket == null) {
throw new IllegalStateException("socket is null.");
}
bindSocket(socket, bindAddress, port);
logger.info("UDP Packet reader:{} started.", ioThreadSize);
for (int i = 0; i < ioThreadSize; i++) {
io.execute(new Runnable() {
@Override
public void run() {
receive(socket);
}
});
}
}
Aggregations