public class PacketQueue extends Object
This class is responsible for managing a size limited queue of packets. This functionality is needed by the Protocol#isValidOption method. The maximum total memory size of the queue can be set with the setBacklog method. New packets can be added with the push method. Packets which are no longer needed can be retrieved and removed from the queue with the pop method.
Note: This class is not guaranteed to be thread safe.
| Constructor and Description |
|---|
PacketQueue() |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all packets from the queue.
|
long |
getBacklog()
Returns the total maximum memory size of this queue in bytes.
|
int |
getCount()
Returns the current amount of packets in this queue.
|
Packet |
pop()
Returns a packet and removes it from the queue.
|
void |
push(Packet packet)
Adds a new packet to the queue.
|
void |
setBacklog(long backlog)
Sets the total maximum memory size of this queue in bytes.
|
public void push(Packet packet)
This method adds the supplied packet to the queue. The size of the queue is incremented by the size of the supplied packet (plus some internal management overhead). If the total occupied memory size of this queue exceeds the backlog limit after adding the new packet, then already added packets will be removed from this queue until the backlog size limit is reached again.
packet - The packet to addpublic Packet pop()
public void clear()
Removing all packets of the queue is done by calling the pop method for each packet in the current queue.
public long getBacklog()
public void setBacklog(long backlog)
Each time a new packet is added with the push method, it will be verified that the total occupied memory size of the queue still falls below the supplied backlog limit. To satisfy this constraint, old packets are removed from the queue when necessary.
backlog - The new backlog sizepublic int getCount()
For each added packet this counter is incremented by one and for each removed packet (either with the pop method or automatically while resizing the queue) this counter is decremented by one. If the queue is empty, this method returns 0.
Copyright © 2023. All rights reserved.