java.lang.Object
java.lang.Thread
net.i2p.client.streaming.impl.PacketDispatcher.Worker
All Implemented Interfaces:
Runnable
Enclosing class:
PacketDispatcher

class PacketDispatcher.Workerextends Thread
One worker drains its own bounded queue; started in the dispatcher ctor.
  • Field Details

    • _queue

      The packets waiting for this worker.
    • _processor

      private final PacketDispatcher.PacketProcessor _processor
      The processor handling the packets.
    • _context

      private final I2PAppContext _context
      The app context.
    • _busy

      volatile int _busy
      Entries currently inside process(); read by resize to prove idle.
    • _retired

      private boolean _retired
      Set by retire() before it drains, under the same monitor as offer(), so a handoff either lands before the drain (and is freed by it) or is refused - never accepted into a queue nothing will ever drain again.
  • Constructor Details

    • Worker

      Worker(int shard, int queueCapacity, PacketDispatcher.PacketProcessor processor, I2PAppContext context)
      A shard's worker, not started here - the dispatcher starts the whole array at once so a resize can swap the shards over as a unit.
      Parameters:
      shard - shard index, used only to name the thread
      queueCapacity - entries this shard holds before producers wait
      processor - how to process an entry, from the dispatcher
      context - for the backlog and queue-depth rates, null in tests
  • Method Details

    • offer

      boolean offer(PacketDispatcher.Entry e)
      Hand an entry to this worker, refusing it if the worker has been retired, so a handoff racing with a resize or shutdown cannot park the entry in a queue nothing will drain again.
      Parameters:
      e - the entry to enqueue
      Returns:
      true if the entry was queued and will be processed
    • awaitIdle

      void awaitIdle() throws InterruptedException
      Wait until this shard has nothing queued and nothing in process(), so retiring it cannot drop an entry that was already accepted.
      Throws:
      InterruptedException - if interrupted while waiting
    • retire

      void retire()
      Interrupt the worker and free any queued-but-unprocessed entries.
    • run

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread