Skip to content

Commit 2047344

Browse files
committed
Add debugging print statements
1 parent ff12520 commit 2047344

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

src/main/java/com/timgroup/statsd/NonBlockingStatsDClientBuilder.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,16 +385,21 @@ protected static Callable<SocketAddress> staticUnixResolution(
385385
// Use reflection to avoid compiling Java 16+ classes in incompatible versions
386386
Class<?> unixDomainSocketAddressClass = Class.forName("java.net.UnixDomainSocketAddress");
387387
Method ofMethod = unixDomainSocketAddressClass.getMethod("of", String.class);
388-
// return type SocketAddress instead of UnixSocketAddress for compatibility with
389-
//the native SocketChannels in Unix*ClientChannel.java
388+
// return type SocketAddress for compatibility with UnixStreamClientChannel.java
390389
socketAddress = (SocketAddress) ofMethod.invoke(null, path);
390+
System.out.println("========== Native UDS socket address: " + socketAddress);
391+
System.out.println("========== Native UDS socket address type: " + socketAddress.getClass().getName());
391392
} catch (Exception e) {
392393
throw new StatsDClientException("Failed to create UnixSocketAddress for native UDS implementation", e);
393394
}
394395
} else {
395396
socketAddress = new UnixSocketAddress(path);
397+
System.out.println("========== JNR socket address: " + socketAddress);
398+
System.out.println("========== JNR socket address type: " + socketAddress.getClass().getName());
396399
}
397-
return new UnixSocketAddressWithTransport(socketAddress, transportType);
400+
UnixSocketAddressWithTransport result = new UnixSocketAddressWithTransport(socketAddress, transportType);
401+
System.out.println("========== Final result type: " + result.getClass().getName());
402+
return result;
398403
}
399404
};
400405
}

src/main/java/com/timgroup/statsd/UnixStreamClientChannel.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class UnixStreamClientChannel implements ClientChannel {
3232
UnixStreamClientChannel(SocketAddress address, int timeout, int connectionTimeout, int bufferSize) throws IOException {
3333
this.delegate = null;
3434
this.address = address;
35+
System.out.println("========== Constructor address: " + address);
36+
System.out.println("========== Constructor address type: " + address.getClass().getName());
3537
this.timeout = timeout;
3638
this.connectionTimeout = connectionTimeout;
3739
this.bufferSize = bufferSize;
@@ -142,6 +144,8 @@ private void connect() throws IOException {
142144
channel.socket().setSoTimeout(connectionTimeout);
143145
}
144146
try {
147+
System.out.println("========== Native UDS connect address: " + address);
148+
System.out.println("========== Native UDS connect address type: " + address.getClass().getName());
145149
Method connectMethod = SocketChannel.class.getMethod("connect", SocketAddress.class);
146150
boolean connected = (boolean) connectMethod.invoke(channel, address);
147151
// socketchannel is failing to connect here :(
@@ -153,6 +157,7 @@ private void connect() throws IOException {
153157
throw new IOException("Connection failed");
154158
}
155159
}
160+
System.out.println("========== Connection successful");
156161
channel.socket().setSoTimeout(Math.max(timeout, 0));
157162
if (bufferSize > 0) {
158163
channel.socket().setSendBufferSize(bufferSize);
@@ -191,6 +196,9 @@ private void connect() throws IOException {
191196
unixAddress = new UnixSocketAddress(address.toString());
192197
}
193198

199+
System.out.println("========== JNR connect address: " + unixAddress);
200+
System.out.println("========== JNR connect address type: " + unixAddress.getClass().getName());
201+
194202
if (!channel.connect(unixAddress)) {
195203
if (connectionTimeout > 0 && System.nanoTime() > deadline) {
196204
throw new IOException("Connection timed out");

src/test/java/com/timgroup/statsd/UnixStreamSocketDummyStatsDServer.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ public class UnixStreamSocketDummyStatsDServer extends DummyStatsDServer {
2222
public UnixStreamSocketDummyStatsDServer(String socketPath) throws IOException {
2323
server = UnixServerSocketChannel.open();
2424
server.configureBlocking(true);
25-
server.socket().bind(new UnixSocketAddress(socketPath));
25+
UnixSocketAddress address = new UnixSocketAddress(socketPath);
26+
System.out.println("========== Server bind address: " + address);
27+
System.out.println("========== Server bind address type: " + address.getClass().getName());
28+
server.socket().bind(address);
2629
this.listen();
2730
}
2831

@@ -38,6 +41,8 @@ protected void receive(ByteBuffer packet) throws IOException {
3841

3942
@Override
4043
protected void listen() {
44+
System.out.println("========== Server local address: " + server.getLocalSocketAddress());
45+
System.out.println("========== Server local address type: " + server.getLocalSocketAddress().getClass().getName());
4146
logger.info("Listening on " + server.getLocalSocketAddress());
4247
Thread thread = new Thread(new Runnable() {
4348
@Override
@@ -52,6 +57,8 @@ public void run() {
5257
if (clientChannel != null) {
5358
clientChannel.configureBlocking(true);
5459
try {
60+
System.out.println("========== Client remote address: " + clientChannel.getRemoteSocketAddress());
61+
System.out.println("========== Client remote address type: " + clientChannel.getRemoteSocketAddress().getClass().getName());
5562
logger.info("Accepted connection from " + clientChannel.getRemoteSocketAddress());
5663
} catch (Exception e) {
5764
logger.warning("Failed to get remote socket address");

0 commit comments

Comments
 (0)