java.lang.Object
net.i2p.router.transport.ntcp.Reader
Pool of running threads which will process any read bytes on any of the NTCPConnections, including decryption of the data read, connection handshaking, parsing bytes into I2NP messages, etc. Provides efficient buffer management and connection lifecycle coordination. Supports dynamic thread count adjustment via
adjustThreads().Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classThread reading the assigned connections.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicIntegerTracks how many runner threads are actively processing (not parked).private final RouterContextThe router context.private final Set<NTCPConnection> Connections being read by a runner.private final LogLogger for the NTCP reader.private final Set<NTCPConnection> Connections waiting for a runner.private final Set<NTCPConnection> Connections to read after the live ones.private final CopyOnWriteArrayList<Reader.Runner> The running reader threads.private static intNumber of reader threads.private static final AtomicIntegerSequence number of the reader threads.private static final intMost reader threads allowed.private static final intFewest reader threads allowed.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 intReader thread count.doubleReader pool utilization as a ratio (0.0-1.0).private voidProcess everything read.static voidsetThreadCount(int count) Reader thread count, bounded by MIN_THREADS-MAX_THREADS.voidstartReading(int numReaders) Starts the given number of reader threads.private voidStarts one more reader thread if needed.voidStop all reader threads.voidwantsRead(NTCPConnection con) Registers a connection to be read.
Field Details
_log
Logger for the NTCP reader._context
The router context._pendingConnections
Connections waiting for a runner._liveReads
Connections being read by a runner._readAfterLive
Connections to read after the live ones._runners
The running reader threads._threadCount
private static volatile int _threadCountNumber of reader threads.MIN_THREADS
MAX_THREADS
_threadNum
Sequence number of the reader threads._activeCount
Tracks how many runner threads are actively processing (not parked).
Constructor Details
Reader
Reader thread pool for the given context.- Parameters:
ctx- the router context supplying the log and the clock
Method Details
getThreadCount
public static int getThreadCount()Reader thread count.- Returns:
- the target number of reader threads, 2 to 16
getActiveCount
public int getActiveCount()Number of threads currently processing (not parked).- Returns:
- the count of runners that are inside the read loop
getUtilization
public double getUtilization()Reader pool utilization as a ratio (0.0-1.0). NaN if no runners are active (pool not started).- Returns:
- the utilization as a ratio from 0.0 to 1.0, or NaN if no runners are active
setThreadCount
public static void setThreadCount(int count) Reader thread count, bounded by MIN_THREADS-MAX_THREADS.- Parameters:
count- the requested target, clamped into the range 2 to 16
startReading
public void startReading(int numReaders) Starts the given number of reader threads.- Parameters:
numReaders- how many runners to add to those already started
startRunner
private void startRunner()Starts one more reader thread if needed.adjustThreads
public void adjustThreads()Dynamically adjust thread count to match the target.stopReading
public void stopReading()Stop all reader threads.wantsRead
Registers a connection to be read. High-frequency per-buffer path.- Parameters:
con- the connection with data waiting to be read
connectionClosed
Removes a closed connection from the queues.- Parameters:
con- the connection to drop from the pending and read-after-live queues
processRead
Process everything read. Return read buffers back to the pool as we process them.- Parameters:
con- the connection whose read buffers are processed, ignored if null