class EventPumper extends Object implements Runnable
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:
wakeup() on pending I/OConcurrentHashSet| Constructor and Description |
|---|
EventPumper(RouterContext ctx,
NTCPTransport transport)EventPumper. |
| Modifier and Type | Method and Description |
|---|---|
static ByteBuffer | acquireBuf()High-frequency path in thread. |
void | blockIP(byte[] ip)Record the given IP as blocked. |
static void | clearInterest(SelectionKey key,
int op)Clear the given interest operation on the selection key. |
static long | getFailsafeIterationFreq()Failsafe iteration frequency in milliseconds. |
long | getIdleTimeout()The idle timeout for connections. |
static int | getMaxIdleLps()Max idle loop rate in loops per second. |
static long | getSelectorLoopDelay()Selector loop delay in milliseconds. |
boolean | isAlive()Selector can take quite a while to close after calling stopPumping() |
boolean | processWrite(NTCPConnection con,
SelectionKey key)Try to write the queued buffers for the connection. |
void | register(ServerSocketChannel chan)Register the acceptor. |
void | registerConnect(NTCPConnection con)Outbound connection registration with optional retry backoff. |
static void | releaseBuf(ByteBuffer buf)Read buffer returned to the pool. |
void | run()Run the selector event loop. |
static void | setFailsafeIterationFreq(long ms)Failsafe iteration frequency, bounded by MIN-MAX. |
static void | setInterest(SelectionKey key,
int op)Interest operations on the given selection key. |
static void | setMaxIdleLps(int lps)Max idle loop rate in loops per second, bounded 1-5000. |
static void | setSelectorLoopDelay(long ms)Selector loop delay, bounded 1-SELECTOR_MAX_DELAY ms. |
void | startPumping()Open the selector and start the pump thread. |
void | stopPumping()Stop the pump thread and wake the selector. |
void | trackFailedInboundHandshake(byte[] ip)Track failed inbound handshake (IP only, no hash). |
void | trackFailedInboundHandshake(byte[] ip,
Hash hash)Track failed inbound handshake for diagnostic stats. |
void | trackInvalidEncryption(byte[] ip,
Hash hash)Track failed inbound handshake with invalid encryption and ban if too many failures. |
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). |
public EventPumper(RouterContext ctx, NTCPTransport transport)
public static ByteBuffer acquireBuf()
public void blockIP(byte[] ip)
public static void clearInterest(SelectionKey key, int op) throws CancelledKeyException
CancelledKeyExceptionpublic static long getFailsafeIterationFreq()
public long getIdleTimeout()
public static int getMaxIdleLps()
public static long getSelectorLoopDelay()
public boolean isAlive()
public boolean processWrite(NTCPConnection con, SelectionKey key)
public void register(ServerSocketChannel chan)
public void registerConnect(NTCPConnection con)
public static void releaseBuf(ByteBuffer buf)
public static void setFailsafeIterationFreq(long ms)
public static void setInterest(SelectionKey key, int op) throws CancelledKeyException
CancelledKeyExceptionpublic static void setMaxIdleLps(int lps)
public static void setSelectorLoopDelay(long ms)
public void startPumping()
public void stopPumping()
public void trackFailedInboundHandshake(byte[] ip)
public void trackFailedInboundHandshake(byte[] ip,
Hash hash)ip - source IP address (tracked for stats only)hash - optional router hash if availablepublic void trackInvalidEncryption(byte[] ip,
Hash hash)ip - byte array IP addresshash - optional router hash if availablepublic void wantsRead(NTCPConnection con)
public void wantsWrite(NTCPConnection con)