net.i2p.router.transport.ntcp

## Class EventPumper

- java.lang.Object
- - net.i2p.router.transport.ntcp.EventPumper

- All Implemented Interfaces:
    Runnable

      class EventPumper
      extends Object
      implements Runnable

  The main NTCP NIO event loop thread responsible for high-throughput, low-latency handling of inbound and outbound NTCP connections using non-blocking I/O.

  This class is optimized for minimal overhead and maximum event dispatch efficiency. All hot paths (e.g., `processRead(java.nio.channels.SelectionKey)`, `processWrite(java.nio.channels.SelectionKey)`, `runDelayedEvents()`) avoid synchronization, allocations, and unnecessary syscalls.

  Key performance characteristics:

  - Fixed 200ms selector timeout for consistent latency
  - Immediate `wakeup()` on pending I/O (no cooldown)
  - Duplicate-free write request tracking via `ConcurrentHashSet`
  - Failsafe iteration every 2 seconds to clean stale connections
  - Efficient buffer pooling with bounded size

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `EventPumper(RouterContext ctx, NTCPTransport transport)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static ByteBuffer` | `acquireBuf()` High-frequency path in thread.
    `void` | `blockIP(byte[] ip)`
    `static void` | `clearInterest(SelectionKey key, int op)`
    `long` | `getIdleTimeout()`
    `boolean` | `isAlive()` Selector can take quite a while to close after calling stopPumping()
    `boolean` | `processWrite(NTCPConnection con, SelectionKey key)`
    `void` | `register(ServerSocketChannel chan)` Register the acceptor.
    `void` | `registerConnect(NTCPConnection con)` Outbound connection registration with optional retry backoff.
    `static void` | `releaseBuf(ByteBuffer buf)` Return a read buffer to the pool.
    `void` | `run()`
    `static void` | `setInterest(SelectionKey key, int op)`
    `void` | `startPumping()`
    `void` | `stopPumping()`
    `void` | `wantsRead(NTCPConnection con)` This is only called from NTCPConnection.complete() if there is more data, which is rare (never?) so we don't need to check for dups or make _wantsRead a Set.
    `void` | `wantsWrite(NTCPConnection con)` Called by the connection when it has data ready to write (after bw allocation).

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### EventPumper

          public EventPumper(RouterContext ctx,
                             NTCPTransport transport)

  - ### Method Detail

    - #### acquireBuf

          public static ByteBuffer acquireBuf()

      High-frequency path in thread.

    - #### blockIP

          public void blockIP(byte[] ip)

    - #### clearInterest

          public static void clearInterest(SelectionKey key,
                                           int op)
                                    throws CancelledKeyException

      Throws:
        `CancelledKeyException`

    - #### getIdleTimeout

          public long getIdleTimeout()

    - #### isAlive

          public boolean isAlive()

      Selector can take quite a while to close after calling stopPumping()

    - #### processWrite

          public boolean processWrite(NTCPConnection con,
                                      SelectionKey key)

    - #### register

          public void register(ServerSocketChannel chan)

      Register the acceptor. This is only called from NTCPTransport.bindAddress(), so it isn't clear why this needs a queue.

    - #### registerConnect

          public void registerConnect(NTCPConnection con)

      Outbound connection registration with optional retry backoff.

    - #### releaseBuf

          public static void releaseBuf(ByteBuffer buf)

      Return a read buffer to the pool. These buffers must be from acquireBuf(), i.e. capacity() == BUF_SIZE. High-frequency path in thread.

    - #### run

          public void run()

      Specified by:
        `run` in interface `Runnable`

    - #### setInterest

          public static void setInterest(SelectionKey key,
                                         int op)
                                  throws CancelledKeyException

      Throws:
        `CancelledKeyException`

    - #### startPumping

          public void startPumping()

    - #### stopPumping

          public void stopPumping()

    - #### wantsRead

          public void wantsRead(NTCPConnection con)

      This is only called from NTCPConnection.complete() if there is more data, which is rare (never?) so we don't need to check for dups or make _wantsRead a Set.

    - #### wantsWrite

          public void wantsWrite(NTCPConnection con)

      Called by the connection when it has data ready to write (after bw allocation). Only wakeup if new.