Package org.jitsi.utils.queue
Class PacketQueue
-
- All Implemented Interfaces:
public class PacketQueue<T>An abstract queue of packets.
Boris Grozev
Yura Yaroshevich
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfacePacketQueue.PacketHandlerA simple interface to handle packets.
public interfacePacketQueue.ObserverAn interface to observe a queue, to collect statistics or similar.
-
Field Summary
Fields Modifier and Type Field Description public static booleanenableStatisticsDefault
-
Constructor Summary
Constructors Constructor Description PacketQueue(int capacity, Boolean enableStatistics, String id, PacketQueue.PacketHandler<T> packetHandler, ExecutorService executor, Clock clock)Initializes a new PacketQueue instance. PacketQueue(int capacity, Boolean enableStatistics, String id, PacketQueue.PacketHandler<T> packetHandler, ExecutorService executor, Clock clock, boolean interruptOnClose)Initializes a new PacketQueue instance. PacketQueue(int capacity, Boolean enableStatistics, String id, PacketQueue.PacketHandler<T> packetHandler, ExecutorService executor)Initializes a new PacketQueue instance.
-
Method Summary
Modifier and Type Method Description static booleangetEnableStatisticsDefault()static voidsetEnableStatisticsDefault(boolean enable)Sets the default value for the enableStatisticsconstructor parameter.voidadd(T pkt)Adds a specific packet ( T) instance to the queue.voidclose()Closes current PacketQueue instance. intsize()Get the current number of packets queued in this queue. intcapacity()Get the maximum number of packets queued in this queue. Stringid()Get the ID of this queue. JSONObjectgetDebugState()Gets a JSON representation of the parts of this object's state that are deemed useful for debugging. voidsetErrorHandler(@NotNull() ErrorHandler errorHandler)Sets the handler of errors (packets dropped or exceptions caught while processing). -
-
Constructor Detail
-
PacketQueue
PacketQueue(int capacity, Boolean enableStatistics, String id, PacketQueue.PacketHandler<T> packetHandler, ExecutorService executor, Clock clock)
Initializes a new PacketQueue instance.- Parameters:
capacity- the capacity of the queue.enableStatistics- whether detailed statistics should be gathered by constructing an Observer.id- the ID of the packet queue, to be used for logging.packetHandler- An handler to be used by the queue for packets read from it.executor- An executor service to use to execute packetHandler for items added to queue.clock- If {@param enableStatistics} is true (or resolves as true), a clock to use to construct the Observer.
-
PacketQueue
PacketQueue(int capacity, Boolean enableStatistics, String id, PacketQueue.PacketHandler<T> packetHandler, ExecutorService executor, Clock clock, boolean interruptOnClose)
Initializes a new PacketQueue instance.- Parameters:
capacity- the capacity of the queue.enableStatistics- whether detailed statistics should be gathered by constructing an Observer.id- the ID of the packet queue, to be used for logging.packetHandler- An handler to be used by the queue for packets read from it.executor- An executor service to use to execute packetHandler for items added to queue.clock- If {@param enableStatistics} is true (or resolves as true), a clock to use to construct the Observer.interruptOnClose- whether the running task (if any) should be interrupted when the queue is closed.
-
PacketQueue
PacketQueue(int capacity, Boolean enableStatistics, String id, PacketQueue.PacketHandler<T> packetHandler, ExecutorService executor)
Initializes a new PacketQueue instance.- Parameters:
capacity- the capacity of the queue.enableStatistics- whether detailed statistics should be gathered using a QueueStatisticsObserver as a default queue observer.id- the ID of the packet queue, to be used for logging.packetHandler- An handler to be used by the queue for packets read from it.executor- An executor service to use to execute packetHandler for items added to queue.
-
-
Method Detail
-
getEnableStatisticsDefault
static boolean getEnableStatisticsDefault()
-
setEnableStatisticsDefault
static void setEnableStatisticsDefault(boolean enable)
Sets the default value for the
enableStatisticsconstructor parameter.- Parameters:
enable- the value to set.
-
add
void add(T pkt)
Adds a specific packet (
T) instance to the queue.- Parameters:
pkt- the packet to add.
-
close
void close()
Closes current PacketQueue instance. No items will be added to queue when it's closed. Asynchronous queue processing by asyncQueueHandler is stopped.
-
size
int size()
Get the current number of packets queued in this queue.
-
capacity
int capacity()
Get the maximum number of packets queued in this queue.
-
getDebugState
JSONObject getDebugState()
Gets a JSON representation of the parts of this object's state that are deemed useful for debugging.
-
setErrorHandler
void setErrorHandler(@NotNull() ErrorHandler errorHandler)
Sets the handler of errors (packets dropped or exceptions caught while processing).
- Parameters:
errorHandler- the handler to set.
-
-
-
-