From d0b85b398da030ac0689da0f3692b25a21dc8890 Mon Sep 17 00:00:00 2001 From: Laplie Anderson Date: Mon, 29 Nov 2021 13:24:48 -0500 Subject: [PATCH] PR feedback --- .../java/com/timgroup/statsd/DatagramClientChannel.java | 5 +++++ .../java/com/timgroup/statsd/NamedPipeClientChannel.java | 9 ++++++++- .../java/com/timgroup/statsd/NamedPipeSocketAddress.java | 2 +- .../com/timgroup/statsd/NonBlockingStatsDClient.java | 3 +-- src/main/java/com/timgroup/statsd/StatsDSender.java | 5 +++-- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/timgroup/statsd/DatagramClientChannel.java b/src/main/java/com/timgroup/statsd/DatagramClientChannel.java index 0ac4a0cb..d5f53675 100644 --- a/src/main/java/com/timgroup/statsd/DatagramClientChannel.java +++ b/src/main/java/com/timgroup/statsd/DatagramClientChannel.java @@ -45,4 +45,9 @@ public void close() throws IOException { public String getTransportType() { return "udp"; } + + @Override + public String toString() { + return "[" + getTransportType() + "] " + address; + } } diff --git a/src/main/java/com/timgroup/statsd/NamedPipeClientChannel.java b/src/main/java/com/timgroup/statsd/NamedPipeClientChannel.java index ec297bf8..7eba3832 100644 --- a/src/main/java/com/timgroup/statsd/NamedPipeClientChannel.java +++ b/src/main/java/com/timgroup/statsd/NamedPipeClientChannel.java @@ -9,9 +9,11 @@ public class NamedPipeClientChannel implements ClientChannel { private final RandomAccessFile randomAccessFile; private final FileChannel fileChannel; + private final String pipe; public NamedPipeClientChannel(NamedPipeSocketAddress address) throws FileNotFoundException { - randomAccessFile = new RandomAccessFile(address.getPipe(), "rw"); + pipe = address.getPipe(); + randomAccessFile = new RandomAccessFile(pipe, "rw"); fileChannel = randomAccessFile.getChannel(); } @@ -35,4 +37,9 @@ public void close() throws IOException { public String getTransportType() { return "namedpipe"; } + + @Override + public String toString() { + return pipe; + } } diff --git a/src/main/java/com/timgroup/statsd/NamedPipeSocketAddress.java b/src/main/java/com/timgroup/statsd/NamedPipeSocketAddress.java index 688eb521..d4b4c4fa 100644 --- a/src/main/java/com/timgroup/statsd/NamedPipeSocketAddress.java +++ b/src/main/java/com/timgroup/statsd/NamedPipeSocketAddress.java @@ -17,7 +17,7 @@ public String getPipe() { /** * A normalized version of the pipe name that includes the `\\.\pipe\` prefix */ - public static String normalizePipeName(String pipeName) { + static String normalizePipeName(String pipeName) { if (pipeName.startsWith(NAMED_PIPE_PREFIX)) { return pipeName; } else { diff --git a/src/main/java/com/timgroup/statsd/NonBlockingStatsDClient.java b/src/main/java/com/timgroup/statsd/NonBlockingStatsDClient.java index 83f87e60..1381097b 100644 --- a/src/main/java/com/timgroup/statsd/NonBlockingStatsDClient.java +++ b/src/main/java/com/timgroup/statsd/NonBlockingStatsDClient.java @@ -1,6 +1,5 @@ package com.timgroup.statsd; -import jnr.unixsocket.UnixDatagramChannel; import jnr.unixsocket.UnixSocketAddress; import java.io.IOException; @@ -396,7 +395,7 @@ public void stop() { } } - if (telemetryClientChannel != null) { + if (telemetryClientChannel != null && telemetryClientChannel != clientChannel) { try { telemetryClientChannel.close(); } catch (final IOException e) { diff --git a/src/main/java/com/timgroup/statsd/StatsDSender.java b/src/main/java/com/timgroup/statsd/StatsDSender.java index 2a8666ed..55ddbbc0 100644 --- a/src/main/java/com/timgroup/statsd/StatsDSender.java +++ b/src/main/java/com/timgroup/statsd/StatsDSender.java @@ -94,8 +94,9 @@ void sendLoop() { buffer.clear(); if (sizeOfBuffer != sentBytes) { throw new IOException( - String.format("Could not send stat %s entirely. Only sent %d out of %d bytes", - buffer.toString(), + String.format("Could not send stat %s entirely to %s. Only sent %d out of %d bytes", + buffer, + clientChannel, sentBytes, sizeOfBuffer)); }