java.lang.Object
net.i2p.router.client.ClientWriterRunner
All Implemented Interfaces:
Runnable

class ClientWriterRunnerextends Object implements Runnable
Writes I2CP messages to a client asynchronously, so a hung client app cannot take down the whole router. Without this, the JobQueue would block until the client reads from their i2cp socket.

For external I2CP connections only.

  • Field Details

    • _messagesToWrite

      private final BlockingQueue<I2CPMessage> _messagesToWrite
      Messages waiting to go out to the client.
    • _runner

      private final ClientConnectionRunner _runner
      The connection these messages belong to.
    • _context

      private final RouterContext _context
      The router context the writer runs in.
    • queueSize

      private static volatile int queueSize
      Max messages queued per client before blocking.
  • Constructor Details

    • ClientWriterRunner

      public ClientWriterRunner(RouterContext ctx, ClientConnectionRunner runner)
      Creates a new client writer runner.
      Parameters:
      ctx - the router context
      runner - the client connection runner
  • Method Details

    • getQueueSize

      public static int getQueueSize()
      The current size of the message queue.
      Returns:
      the queue size
    • setQueueSize

      public static void setQueueSize(int val)
      Update the message queue size, clamped to the supported range.
      Parameters:
      val - the new queue size
    • addMessage

      public void addMessage(I2CPMessage msg) throws I2CPMessageException
      Add this message to the writer's queue

      Nonblocking, throws exception if queue is full.

      Parameters:
      msg - the message to add
      Throws:
      I2CPMessageException - if the queue is full
    • stopWriting

      public void stopWriting()
      No more messages - don't even try to send what we have.
    • run

      public void run()
      Specified by:
      run in interface Runnable