java.lang.Object
net.i2p.router.transport.ntcp.Writer

public class Writerextends Object
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 Details

    • Writer

      public Writer(RouterContext ctx)
      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

      public void wantsWrite(NTCPConnection con, String source)
      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 pool
      source - a caller-supplied label naming the code that requested the write, used only for debug logging
    • connectionClosed

      public void connectionClosed(NTCPConnection con)
      Removes a closed connection from the queues.
      Parameters:
      con - the connection that has closed and must no longer be drained or written