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

class ClientWriterRunnerextends Object implements Runnable
Copied from net.i2p.router.client We need a single thread that writes so we don't have issues with the Piped Streams used in InternalSocket.
  • Field Details

    • _out

      private final OutputStream _out
      Where messages are written to the router.
    • _session

      private final I2PSessionImpl _session
      The session whose messages are written.
    • _messagesToWrite

      private final BlockingQueue<I2CPMessage> _messagesToWrite
      Messages waiting to reach the router.
    • __Id

      private static final AtomicLong __Id
      Counts the writer threads created.
    • MAX_QUEUE_SIZE

      private static final int MAX_QUEUE_SIZE
      Most messages queued before writes start blocking.
    • MAX_SEND_WAIT

      private static final long MAX_SEND_WAIT
      Longest a send waits for the queue to drain, in ms.
  • Constructor Details

    • ClientWriterRunner

      public ClientWriterRunner(OutputStream out, I2PSessionImpl session)
      Create the writer for a session, buffering I2CP messages queued for output to that session.

      As of 0.9.11 does not start the thread, caller must call startWriting().

      Parameters:
      out - stream the I2CP messages are written to, buffered internally
      session - session to poll for closure and to report write failures to
  • Method Details

    • startWriting

      public void startWriting()
      Starts the daemon thread that drains the queue and writes to the session's output stream.
    • addMessage

      public void addMessage(I2CPMessage msg) throws I2PSessionException
      Add this message to the writer's queue. Blocking if queue is full.
      Parameters:
      msg - the message to queue for writing to the session's output stream
      Throws:
      I2PSessionException - if we wait too long or are interrupted
    • 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