java.lang.Object
net.i2p.client.streaming.impl.RetransmissionTimer

public class RetransmissionTimerextends Object
Per-destination timer for scheduling packet retransmissions. Uses dedicated SimpleTimer2 shards (not the router-global one) to isolate streaming timer events from contention with other subsystems.

The events are spread over SHARDS independent timers, so a connection whose timer queue is saturated by retransmission/ack events cannot hold up an unrelated connection's handshake or keepalive. Each shard keeps SimpleTimer2's two worker threads, so a single long-running event blocks only its own workers.

  • Field Details

    • SHARDS

      private static final int SHARDS
      Number of independent timer shards. Connections are assigned round-robin, halving the chance that concurrent connections share a timer queue.
      See Also:
    • _shards

      private final SimpleTimer2[] _shards
      The timers, split into shards to spread the locking
    • _counter

      private final AtomicInteger _counter
      Round-robin index choosing the next shard
  • Constructor Details

    • RetransmissionTimer

      RetransmissionTimer(I2PAppContext ctx, String name)
      New timer with dedicated SimpleTimer2 shards.
      Parameters:
      ctx - the application context
      name - used for the timer thread names
  • Method Details

    • getSharedTimer

      public SimpleTimer2 getSharedTimer()
      A SimpleTimer2 instance for a new consumer. Shards are handed out round-robin; a component that calls this once at construction (a Connection, the packet queue, the accept handler, ...) gets a stable shard for its lifetime. No caller depends on two calls returning the same instance.
      Returns:
      one of the dedicated SimpleTimer2 instances
    • addEvent

      public void addEvent(SimpleTimer2.TimedEvent event, long timeoutMs)
      Schedule an event via one of the dedicated timers.
      Parameters:
      event - the SimpleTimer2 event to fire once timeoutMs has elapsed
      timeoutMs - delay in ms
    • stop

      public void stop()
      Stop all dedicated timers.