java.lang.Object
net.i2p.router.transport.ntcp.NTCPSendFinisher
Handles asynchronous post-send processing of OutNetMessage using a dynamically resizable thread pool executor with a bounded queue and backpressure. Provides efficient message serialization and prevents resource exhaustion.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classFactory naming the finisher pool's threads.private static classExecutor growing and shrinking the finisher pool.private classExecutes the transport's afterSend callback for the message.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final I2PAppContextThe app context.private static final AtomicIntegerSequence number of the finish events.private ThreadPoolExecutorPool running the finish events.private final LogLogger for the send finisher.private static intThreads in the finisher pool.private static intEvents queued for the finishers.private final NTCPTransportThe transport whose sends are finished.private static final long[]Time windows of the send rate stats.Constructor Summary
ConstructorsConstructorDescriptionNTCPSendFinisher(I2PAppContext context, NTCPTransport transport) Create a new send finisher.Method Summary
Modifier and TypeMethodDescriptionvoidadd(OutNetMessage msg) Adds a message to the finishing queue to call afterSend asynchronously.voidadjustThreads(int newMax) Adjusts the thread pool size for the running executor.intNumber of threads currently processing tasks.static intCurrent max send finisher threads.intCurrent pool size (total threads).static intCurrent send finisher queue capacity.intCurrent queue size (pending send-finish tasks).doubleSend finisher pool utilization as a ratio (0.0-1.0).static voidsetMaxThreads(int threads) Max send finisher threads for new instances.static voidsetQueueCapacity(int capacity) Send finisher queue capacity for new instances.voidstart()Starts the thread pool executor for processing send finish tasks.voidstop()Stops the thread pool executor, waiting briefly for termination.
Field Details
_maxThreads
private static volatile int _maxThreadsThreads in the finisher pool._queueCapacity
private static volatile int _queueCapacityEvents queued for the finishers._context
The app context._transport
The transport whose sends are finished._log
Logger for the send finisher._count
Sequence number of the finish events._executor
Pool running the finish events.RATES
private static final long[] RATESTime windows of the send rate stats.
Constructor Details
NTCPSendFinisher
Create a new send finisher.- Parameters:
context- the I2P app contexttransport- the NTCP transport
Method Details
getMaxThreads
public static int getMaxThreads()Current max send finisher threads.- Returns:
- the max thread count
setMaxThreads
public static void setMaxThreads(int threads) Max send finisher threads for new instances.- Parameters:
threads- the new max thread count
getQueueCapacity
public static int getQueueCapacity()Current send finisher queue capacity.- Returns:
- the queue capacity
setQueueCapacity
public static void setQueueCapacity(int capacity) Send finisher queue capacity for new instances.- Parameters:
capacity- the new queue capacity
start
public void start()Starts the thread pool executor for processing send finish tasks.stop
public void stop()Stops the thread pool executor, waiting briefly for termination.adjustThreads
public void adjustThreads(int newMax) Adjusts the thread pool size for the running executor. If the pool is not running, this is a no-op (new size takes effect on next start).- Parameters:
newMax- the new max thread count
getQueueSize
public int getQueueSize()Current queue size (pending send-finish tasks).- Returns:
- current queue depth, or 0 if not running
getActiveCount
public int getActiveCount()Number of threads currently processing tasks.- Returns:
- active thread count, or 0 if not running
getPoolSize
public int getPoolSize()Current pool size (total threads).- Returns:
- pool size, or 0 if not running
getUtilization
public double getUtilization()Send finisher pool utilization as a ratio (0.0-1.0). Returns NaN if pool not started.- Returns:
- the utilization ratio
add
Adds a message to the finishing queue to call afterSend asynchronously. If the executor is stopped or saturated, falls back to caller running the task.- Parameters:
msg- the message to process after sending