Each UDPSender instance corresponds to a UDPEndpoint, owning its own dedicated sending thread and queue. Packets to be sent are enqueued by the PacketPusher.
This class utilizes a CoDel-based priority blocking queue to limit packet queueing delay and manages bandwidth throttling for sending.
Supports graceful startup and shutdown signaling using a poison packet.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classInternal runner class responsible for dequeuing and sending UDP packets.Field Summary
Modifier and TypeFieldDescriptionprivate intCached CoDel target, refreshed at most once perCODEL_TARGET_TTL.private longWhen the cache was last refreshed.private final RouterContextThe router context.private final booleanTrue in dummy mode, which sends nothing.private final SocketListenerThe listener owning the socket.private booleanTrue while the sender should keep running.private final LogThe log for the sender.private StringThe thread name of the sender.private final BlockingQueue<UDPPacket> The packets waiting to be sent.private final UDPSender.RunnerThe thread sending the packets.private final DatagramSocketThe socket to send the datagrams on.static final intCoDel interval in milliseconds between checks for a packet entering the queue.static final intCoDel algorithm target delay in milliseconds and interval to control pacing.private static final longHow long a cached PROP_CODEL_TARGET value stays valid.private static final intMost packets queued for sending.private static final intMinimum and maximum queue sizes depend on system performance.static final StringProperty name overriding the CoDel check interval.static final StringProperty name overriding the CoDel target delay.(package private) static final long[]Time rate intervals for statistics collection.private static final intPoison packet message type used to signal shutdown to sender thread.Constructor Summary
ConstructorsConstructorDescriptionUDPSender(RouterContext ctx, DatagramSocket socket, String name, SocketListener lsnr) Create a UDPSender with the given context, socket, name, and endpoint listener.Method Summary
Modifier and TypeMethodDescriptionvoidAdds a UDP packet to the send queue.voidclear()Clears the outbound packet queue.private intThe CoDel target delay in ms, fromPROP_CODEL_TARGET, read at most once per second.booleanReturns whether detailed full statistics gathering is enabled.voidshutdown()Gracefully shuts down the UDP sender thread.voidstartup()Starts the UDP sender thread.
Field Details
_context
The router context._log
The log for the sender._socket
The socket to send the datagrams on._name
The thread name of the sender._outboundQueue
The packets waiting to be sent._keepRunning
private volatile boolean _keepRunningTrue while the sender should keep running._runner
The thread sending the packets._dummy
private final boolean _dummyTrue in dummy mode, which sends nothing._endpoint
The listener owning the socket.TYPE_POISON
private static final int TYPE_POISONPoison packet message type used to signal shutdown to sender thread.- See Also:
MIN_QUEUE_SIZE
private static final int MIN_QUEUE_SIZEMinimum and maximum queue sizes depend on system performance. Queue sizes are tuned to compete with NTCP bandwidth requests and to optimize CoDel behavior.- See Also:
MAX_QUEUE_SIZE
private static final int MAX_QUEUE_SIZEMost packets queued for sending.- See Also:
CODEL_TARGET
public static final int CODEL_TARGETCoDel algorithm target delay in milliseconds and interval to control pacing.- See Also:
CODEL_INTERVAL
public static final int CODEL_INTERVALCoDel interval in milliseconds between checks for a packet entering the queue.- See Also:
PROP_CODEL_TARGET
Property name overriding the CoDel target delay.- See Also:
PROP_CODEL_INTERVAL
Property name overriding the CoDel check interval.- See Also:
RATES
static final long[] RATESTime rate intervals for statistics collection.CODEL_TARGET_TTL
private static final long CODEL_TARGET_TTLHow long a cached PROP_CODEL_TARGET value stays valid.- See Also:
_codelTarget
private volatile int _codelTargetCached CoDel target, refreshed at most once perCODEL_TARGET_TTL._codelTargetRead
private volatile long _codelTargetReadWhen the cache was last refreshed.
Constructor Details
UDPSender
Create a UDPSender with the given context, socket, name, and endpoint listener. Initializes the CoDel priority queue and all relevant rate statistics trackers.- Parameters:
ctx- the router contextsocket- the UDP datagram socket to send packets onname- thread name identifier for this senderlsnr- the associated socket listener endpoint
Method Details
fullStats
public boolean fullStats()Returns whether detailed full statistics gathering is enabled.- Returns:
- true if full stats are enabled, false otherwise
startup
public void startup()Starts the UDP sender thread.This method cannot be called more than once as the socket is final.
shutdown
public void shutdown()Gracefully shuts down the UDP sender thread.Clears the outbound queue and signals the runner thread to stop by enqueueing a poison packet. Waits briefly for the queue to drain.
clear
public void clear()Clears the outbound packet queue.Typically used in preparation for sending destroy notifications.
add
Adds a UDP packet to the send queue.This operation blocks if the queue is full, which may back up the PacketPusher thread. Packets that are too large or too small are dropped or warned respectively. Bandwidth requests for the packet are initiated before queueing.
- Parameters:
packet- the UDP packet to enqueue for sending
codelTarget
private int codelTarget()The CoDel target delay in ms, fromPROP_CODEL_TARGET, read at most once per second. An unparseable value logs once per read and falls back toCODEL_TARGET, as does an unset property.- Returns:
- the CoDel target delay in ms, never null