java.lang.Object
net.i2p.router.transport.ntcp.Writer
Pool of running threads which will transform the next I2NP message into something ready to be transferred over an NTCP connection, including encryption of the data read. Provides efficient message serialization and connection lifecycle coordination. Supports dynamic thread count adjustment via
adjustThreads().Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionvoidDynamically adjust thread count to match the target.voidRemoves a closed connection from the queues.intNumber of threads currently processing (not parked).static intWriter thread count.doubleWriter pool utilization as a ratio (0.0-1.0).static voidsetThreadCount(int count) Writer thread count, bounded by MIN_THREADS-MAX_THREADS.voidstartWriting(int numWriters) Starts the given number of writer threads.voidStops all writer threads.voidwantsWrite(NTCPConnection con, String source) Registers a connection to be written.
Constructor Details
Writer
Writer thread pool for the given context.- Parameters:
ctx- the router context whose log manager supplies this pool's logger
Method Details
getThreadCount
public static int getThreadCount()Writer thread count.- Returns:
- the configured number of writer threads, always within MIN_THREADS to MAX_THREADS
getActiveCount
public int getActiveCount()Number of threads currently processing (not parked).- Returns:
- how many of the pooled writer threads are running rather than parked waiting for a connection
getUtilization
public double getUtilization()Writer pool utilization as a ratio (0.0-1.0). NaN if no writers are active (pool not started).- Returns:
- the fraction of the pooled writer threads that are running rather than parked
setThreadCount
public static void setThreadCount(int count) Writer thread count, bounded by MIN_THREADS-MAX_THREADS.- Parameters:
count- the requested thread count, clamped into the MIN_THREADS to MAX_THREADS range before being stored
startWriting
public void startWriting(int numWriters) Starts the given number of writer threads.- Parameters:
numWriters- how many additional writer threads to spin up; each one is added to the pool without stopping or replacing an existing runner
adjustThreads
public void adjustThreads()Dynamically adjust thread count to match the target.stopWriting
public void stopWriting()Stops all writer threads.wantsWrite
Registers a connection to be written. High-frequency per-buffer path.- Parameters:
con- the connection whose next outbound buffer must be serialized and sent by this poolsource- a caller-supplied label naming the code that requested the write, used only for debug logging
connectionClosed
Removes a closed connection from the queues.- Parameters:
con- the connection that has closed and must no longer be drained or written