1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 09:39:39 +02:00

SMACK-129 - Added a property in smack-config file for the default packet collector size and set it much lower than the previous default. Also made the max size for packet collectors configurable from the constructor.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/smack_3_2_0@12509 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
rcollier 2011-06-18 18:18:03 +00:00
parent 0c88e19d3b
commit da5434505b
5 changed files with 97 additions and 15 deletions

View file

@ -32,8 +32,9 @@ import java.util.LinkedList;
* use than a {@link PacketListener} when you need to wait for a specific
* result.<p>
*
* Each packet collector will queue up to 2^16 packets for processing before
* older packets are automatically dropped.
* Each packet collector will queue up a configured number of packets for processing before
* older packets are automatically dropped. The default number is retrieved by
* {@link SmackConfiguration#getPacketCollectorSize()}.
*
* @see Connection#createPacketCollector(PacketFilter)
* @author Matt Tucker
@ -45,7 +46,7 @@ public class PacketCollector {
* reached, older packets will be automatically dropped from the queue as
* new packets are added.
*/
private static final int MAX_PACKETS = 65536;
private int maxPackets = SmackConfiguration.getPacketCollectorSize();
private PacketFilter packetFilter;
private LinkedList<Packet> resultQueue;
@ -65,6 +66,19 @@ public class PacketCollector {
this.resultQueue = new LinkedList<Packet>();
}
/**
* Creates a new packet collector. If the packet filter is <tt>null</tt>, then
* all packets will match this collector.
*
* @param conection the connection the collector is tied to.
* @param packetFilter determines which packets will be returned by this collector.
* @param maxSize the maximum number of packets that will be stored in the collector.
*/
protected PacketCollector(Connection conection, PacketFilter packetFilter, int maxSize) {
this(conection, packetFilter);
maxPackets = maxSize;
}
/**
* Explicitly cancels the packet collector so that no more results are
* queued up. Once a packet collector has been cancelled, it cannot be
@ -180,7 +194,7 @@ public class PacketCollector {
}
if (packetFilter == null || packetFilter.accept(packet)) {
// If the max number of packets has been reached, remove the oldest one.
if (resultQueue.size() == MAX_PACKETS) {
if (resultQueue.size() == maxPackets) {
resultQueue.removeLast();
}
// Add the new packet.