1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 22:32:06 +01:00

Max queue size defined.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@1894 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2003-04-15 13:52:38 +00:00 committed by mtucker
parent 03311272ce
commit 9be420c9bc

View file

@ -62,13 +62,23 @@ import java.util.LinkedList;
* specified filter. The collector lets you perform blocking and polling * specified filter. The collector lets you perform blocking and polling
* operations on the result queue. So, a PacketCollector is more suitable to * operations on the result queue. So, a PacketCollector is more suitable to
* use than a {@link PacketListener} when you need to wait for a specific * use than a {@link PacketListener} when you need to wait for a specific
* result. * result.<p>
*
* Each packet collector will queue up to 2^16 packets for processing before
* older packets are automatically dropped.
* *
* @see XMPPConnection#createPacketCollector(PacketFilter) * @see XMPPConnection#createPacketCollector(PacketFilter)
* @author Matt Tucker * @author Matt Tucker
*/ */
public class PacketCollector { public class PacketCollector {
/**
* Max number of packets that any one collector can hold. After the max is
* reached, older packets will be automatically dropped from the queue as
* new packets are added.
*/
private static final int MAX_PACKETS = 65536;
private PacketFilter packetFilter; private PacketFilter packetFilter;
private LinkedList resultQueue; private LinkedList resultQueue;
private PacketReader packetReader; private PacketReader packetReader;
@ -193,6 +203,11 @@ public class PacketCollector {
return; return;
} }
if (packetFilter == null || packetFilter.accept(packet)) { if (packetFilter == null || packetFilter.accept(packet)) {
// If the max number of packets has been reached, remove the oldest one.
if (resultQueue.size() == MAX_PACKETS) {
resultQueue.removeLast();
}
// Add the new packet.
resultQueue.addFirst(packet); resultQueue.addFirst(packet);
// Notify waiting threads a result is available. // Notify waiting threads a result is available.
notifyAll(); notifyAll();