Skip to content

Commit

Permalink
feat: Adds an overridable default value for the enableStats parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrozev committed Mar 28, 2019
1 parent 9080ccd commit 9c4e610
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions src/main/java/org/jitsi/utils/PacketQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ public abstract class PacketQueue<T>
*/
private final static int DEFAULT_CAPACITY = 256;

/**
* The default value for the {@code enableStatistics} constructor argument.
*/
private static boolean enableStatisticsDefault = false;

/**
* Sets the default value for the {@code enableStatistics} constructor
* parameter.
*
* @param enable the value to set.
*/
public static void setEnableStatisticsDefault(boolean enable)
{
enableStatisticsDefault = enable;
}

/**
* Returns true if a warning should be logged after a queue has dropped
* {@code numDroppedPackets} packets.
Expand Down Expand Up @@ -109,14 +125,14 @@ public static boolean logDroppedPacket(int numDroppedPackets)
*/
public PacketQueue()
{
this(false, "PacketQueue", null);
this(null, "PacketQueue", null);
}

/**
* Initializes a new {@link PacketQueue} instance.
* @param enableStatistics whether detailed statistics should be calculated
* and printed. WARNING: this will produce copious output (one line per
* packet added or removed).
* @param enableStatistics whether detailed statistics should be gathered.
* This might affect performance. A value of {@code null} indicates that
* the default {@link #enableStatisticsDefault} value will be used.
* @param id the ID of the packet queue, to be used for logging.
* @param packetHandler An optional handler to be used by the queue for
* packets read from it. If a non-null value is passed the queue will
Expand All @@ -126,7 +142,7 @@ public PacketQueue()
* {@link #get()} and {@link #poll()}.
*/
public PacketQueue(
boolean enableStatistics, String id, PacketHandler<T> packetHandler)
Boolean enableStatistics, String id, PacketHandler<T> packetHandler)
{
this(DEFAULT_CAPACITY, true, enableStatistics, id, packetHandler);
}
Expand All @@ -136,9 +152,9 @@ public PacketQueue(
* @param capacity the capacity of the queue.
* @param copy whether the queue is to store the instances it is given via
* the various {@code add} methods, or create a copy.
* @param enableStatistics whether detailed statistics should be calculated
* and printed. WARNING: this will produce copious output (one line per
* packet added or removed).
* @param enableStatistics whether detailed statistics should be gathered.
* This might affect performance. A value of {@code null} indicates that
* the default {@link #enableStatisticsDefault} value will be used.
* @param id the ID of the packet queue, to be used for logging.
* @param packetHandler An optional handler to be used by the queue for
* packets read from it. If a non-null value is passed the queue will
Expand All @@ -148,7 +164,7 @@ public PacketQueue(
* {@link #get()} and {@link #poll()}.
*/
public PacketQueue(int capacity, boolean copy,
boolean enableStatistics, String id,
Boolean enableStatistics, String id,
PacketHandler<T> packetHandler)
{
this(capacity, copy, enableStatistics, id, packetHandler, null);
Expand All @@ -159,9 +175,9 @@ public PacketQueue(int capacity, boolean copy,
* @param capacity the capacity of the queue.
* @param copy whether the queue is to store the instances it is given via
* the various {@code add} methods, or create a copy.
* @param enableStatistics whether detailed statistics should be calculated
* and printed. WARNING: this will produce copious output (one line per
* packet added or removed).
* @param enableStatistics whether detailed statistics should be gathered.
* This might affect performance. A value of {@code null} indicates that
* the default {@link #enableStatisticsDefault} value will be used.
* @param id the ID of the packet queue, to be used for logging.
* @param packetHandler An optional handler to be used by the queue for
* packets read from it. If a non-null value is passed the queue will
Expand All @@ -175,7 +191,7 @@ public PacketQueue(int capacity, boolean copy,
public PacketQueue(
int capacity,
boolean copy,
boolean enableStatistics,
Boolean enableStatistics,
String id,
PacketHandler<T> packetHandler,
ExecutorService executor)
Expand All @@ -184,6 +200,10 @@ public PacketQueue(
this.id = id;
queue = new ArrayBlockingQueue<>(capacity);

if (enableStatistics == null)
{
enableStatistics = enableStatisticsDefault;
}
queueStatistics
= enableStatistics ? QueueStatistics.get(id) : null;

Expand Down

0 comments on commit 9c4e610

Please sign in to comment.