From e793404f7c9e28b7e6612d33c761cb2243ea339a Mon Sep 17 00:00:00 2001 From: Boris Grozev Date: Tue, 22 Mar 2016 14:14:20 -0500 Subject: [PATCH] Enables statistics for the packet queue in SinglePortUdpHarvester's candidates' sockets. --- .../ice/harvest/SinglePortUdpHarvester.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java b/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java index bf72580..1cb299a 100644 --- a/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java +++ b/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java @@ -23,6 +23,7 @@ import org.ice4j.ice.*; import org.ice4j.message.*; import org.ice4j.socket.*; import org.ice4j.stack.*; +import org.ice4j.util.*; import java.io.*; import java.net.*; @@ -471,6 +472,12 @@ public class SinglePortUdpHarvester private final ArrayBlockingQueue queue = new ArrayBlockingQueue(QUEUE_SIZE); + /** + * The {@link QueueStatistics} instance optionally used to collect and + * print detailed statistics about {@link #queue}. + */ + private final QueueStatistics queueStatistics; + /** * The remote address that is associated with this socket. */ @@ -496,6 +503,15 @@ public class SinglePortUdpHarvester super((SocketAddress)null); this.remoteAddress = remoteAddress; + if (logger.isLoggable(Level.FINEST)) + { + queueStatistics = new QueueStatistics( + "SinglePort" + remoteAddress.toString().replace('/', '-')); + } + else + { + queueStatistics = null; + } } /** @@ -511,9 +527,18 @@ public class SinglePortUdpHarvester if (queue.size() == QUEUE_SIZE) { logger.info("Dropping a packet because the queue is full."); + if (queueStatistics != null) + { + queueStatistics.remove(System.currentTimeMillis()); + } queue.poll(); } + queue.offer(buf); + if (queueStatistics != null) + { + queueStatistics.add(System.currentTimeMillis()); + } queue.notifyAll(); } @@ -607,6 +632,10 @@ public class SinglePortUdpHarvester } buf = queue.poll(); + if (queueStatistics != null) + { + queueStatistics.remove(System.currentTimeMillis()); + } } }