mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-26 14:02: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:
parent
03311272ce
commit
9be420c9bc
1 changed files with 16 additions and 1 deletions
|
@ -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();
|
||||||
|
|
Loading…
Reference in a new issue