Skip to content

Commit a8021dd

Browse files
authored
Merge pull request #67 from j3grewal/master
DNS lookup is done on every reconnect attempt
2 parents 7661a1e + 80d10f5 commit a8021dd

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/main/java/org/fluentd/logger/sender/RawSocketSender.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.io.IOException;
2727
import java.net.InetSocketAddress;
2828
import java.net.Socket;
29-
import java.net.SocketAddress;
3029
import java.nio.ByteBuffer;
3130
import java.util.Map;
3231

@@ -38,8 +37,6 @@ public class RawSocketSender implements Sender {
3837

3938
private MessagePack msgpack;
4039

41-
private SocketAddress server;
42-
4340
private Socket socket;
4441

4542
private int timeout;
@@ -52,6 +49,10 @@ public class RawSocketSender implements Sender {
5249

5350
private String name;
5451

52+
private final String host;
53+
54+
private final int port;
55+
5556
private ErrorHandler errorHandler = DEFAULT_ERROR_HANDLER;
5657

5758
public RawSocketSender() {
@@ -71,7 +72,8 @@ public RawSocketSender(String host, int port, int timeout, int bufferCapacity, R
7172
msgpack = new MessagePack();
7273
msgpack.register(Event.class, Event.EventTemplate.INSTANCE);
7374
pendings = ByteBuffer.allocate(bufferCapacity);
74-
server = new InetSocketAddress(host, port);
75+
this.host = host;
76+
this.port = port;
7577
this.reconnector = reconnector;
7678
name = String.format("%s_%d_%d_%d", host, port, timeout, bufferCapacity);
7779
this.timeout = timeout;
@@ -80,7 +82,7 @@ public RawSocketSender(String host, int port, int timeout, int bufferCapacity, R
8082
private void connect() throws IOException {
8183
try {
8284
socket = new Socket();
83-
socket.connect(server, timeout);
85+
socket.connect(new InetSocketAddress(host, port), timeout);
8486
out = new BufferedOutputStream(socket.getOutputStream());
8587
} catch (IOException e) {
8688
throw e;
@@ -153,7 +155,7 @@ private boolean flushBuffer() {
153155
if (pendings.position() == 0) {
154156
return true;
155157
} else {
156-
LOG.error("Cannot send logs to " + server.toString());
158+
LOG.error("Cannot send logs to " + socket.getInetAddress().toString());
157159
}
158160
}
159161

0 commit comments

Comments
 (0)