Skip to content

Commit

Permalink
Adds a method to extract the current state of a queue (for debugging).
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrozev committed Apr 18, 2019
1 parent 95b5bec commit ecf9a95
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/main/java/org/jitsi/utils/PacketQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.jitsi.utils.logging.*;
import org.jitsi.utils.stats.*;
import org.json.simple.*;

import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
Expand Down Expand Up @@ -116,6 +117,12 @@ public static boolean logDroppedPacket(int numDroppedPackets)
*/
private volatile boolean closed = false;

/**
* The maximum number of items the queue can contain before it starts
* dropping items.
*/
private final int capacity;

/**
* The number of packets which were dropped from this {@link PacketQueue} as
* a result of a packet being added while the queue is at full capacity.
Expand Down Expand Up @@ -200,6 +207,7 @@ public PacketQueue(
{
this.copy = copy;
this.id = id;
this.capacity = capacity;
queue = new ArrayBlockingQueue<>(capacity);

if (enableStatistics == null)
Expand Down Expand Up @@ -563,4 +571,24 @@ public void handleItem(T item)
}
}
}

/**
* Gets a JSON representation of the parts of this object's state that
* are deemed useful for debugging.
*/
public JSONObject getDebugState()
{
JSONObject debugState = new JSONObject();
debugState.put("id", id);
debugState.put("capacity", capacity);
debugState.put("copy", copy);
debugState.put("closed", closed);
debugState.put(
"statistics",
queueStatistics == null
? null : queueStatistics.getInstanceStats());
debugState.put("num_dropped_packets", numDroppedPackets.get());

return debugState;
}
}

0 comments on commit ecf9a95

Please sign in to comment.