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)blockIP. |
static void | clearInterest(SelectionKey key,
int op)clearInterest. |
static long | getFailsafeIterationFreq()Get the failsafe iteration frequency in milliseconds |
long | getIdleTimeout() |
static long | getSelectorLoopDelay()Get the selector loop delay in milliseconds |
boolean | isAlive()Selector can take quite a while to close after calling stopPumping() |
boolean | processWrite(NTCPConnection con,
SelectionKey key)processWrite. |
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()run. |
static void | setFailsafeIterationFreq(long ms)Set the failsafe iteration frequency, bounded by MIN-MAX |
static void | setInterest(SelectionKey key,
int op)setInterest. |
static void | setSelectorLoopDelay(long ms)Set the selector loop delay, bounded 1-SELECTOR_MAX_DELAY ms. |
void | startPumping()startPumping. |
void | stopPumping()stopPumping. |
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 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 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)