-
public class PacketQueue<T>An abstract queue of packets.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfacePacketQueue.PacketHandlerA simple interface to handle packets.
-
Field Summary
Fields Modifier and Type Field Description private static booleanenableStatisticsDefaultprivate ErrorHandlererrorHandler
-
Constructor Summary
Constructors Constructor Description 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 {@code enableStatistics}constructorparameter.voidsetErrorHandler(@NotNull() ErrorHandler errorHandler)Sets the handler of errors (packets dropped or exceptions caught whileprocessing). voidadd(T pkt)Adds a specific packet ( {@code T}) instance to the queue.voidclose()Closes current PacketQueue instance. JSONObjectgetDebugState()Gets a JSON representation of the parts of this object's state thatare deemed useful for debugging. -
-
Constructor Detail
-
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.This might affect performance.id- the ID of the packet queue, to be used for logging.packetHandler- An handler to be used by the queue forpackets read from it.executor- An executor service to use to executepacketHandler for items added to queue.
-
-
Method Detail
-
getEnableStatisticsDefault
static boolean getEnableStatisticsDefault()
-
setEnableStatisticsDefault
static void setEnableStatisticsDefault(boolean enable)
Sets the default value for the
{@code enableStatistics}constructorparameter.- Parameters:
enable- the value to set.
-
setErrorHandler
void setErrorHandler(@NotNull() ErrorHandler errorHandler)
Sets the handler of errors (packets dropped or exceptions caught whileprocessing).
- Parameters:
errorHandler- the handler to set.
-
add
void add(T pkt)
Adds a specific packet (
{@code T}) instance to the queue.- Parameters:
pkt- the packet to add.
-
close
void close()
Closes current PacketQueue instance. No items will be addedto queue when it's closed. Asynchronous queue processing by asyncQueueHandler is stopped.
-
getDebugState
JSONObject getDebugState()
Gets a JSON representation of the parts of this object's state thatare deemed useful for debugging.
-
-
-
-