java.lang.Object
net.i2p.sam.SAMHandlerPool.SelectorRunnable
All Implemented Interfaces:
Runnable
Enclosing class:
SAMHandlerPool

private class SAMHandlerPool.SelectorRunnableextends Object implements Runnable
NIO selector loop. Reads available data from all registered handler sockets, splits on newlines, dispatches complete lines to workers, and handles idle timeouts and PING/PONG.
  • Constructor Details

    • SelectorRunnable

      private SelectorRunnable()
      Runs the selector loop for one handler pool.
  • Method Details

    • run

      public void run()
      Specified by:
      run in interface Runnable
    • readFromChannel

      private void readFromChannel(SAMHandlerPool.ConnContext ctx, SocketChannel ch) throws IOException
      Read available data from a channel, split into lines, and dispatch complete lines. PING/PONG are handled inline; other commands are dispatched to the worker pool.
      Parameters:
      ctx - the connection's state
      ch - the channel to read from
      Throws:
      IOException - if the read fails
    • dispatchLine

      private void dispatchLine(SAMHandlerPool.ConnContext ctx, String line)
      Dispatch a complete command line to a worker thread. All commands from the same handler are synchronized on the handler instance to ensure serial per-connection execution. Commands from different connections run in parallel.
      Parameters:
      ctx - the connection's state
      line - the complete command line to dispatch
    • handlePing

      private void handlePing(SAMHandlerPool.ConnContext ctx, String line)
      Handle a PING or PONG from the client inline.
      Parameters:
      ctx - the connection's state
      line - the PING or PONG line received
    • sendPing

      private void sendPing(SAMHandlerPool.ConnContext ctx, long now)
      Send a PING to the client and record the timestamp.
      Parameters:
      ctx - the connection's state
      now - the current time, in ms
    • disconnect

      private void disconnect(SAMHandlerPool.ConnContext ctx, String reason)
      Remove the context from the pool and stop the handler. Called when a read error or timeout is detected.
      Parameters:
      ctx - the connection's state
      reason - why the connection is being dropped, for the log
    • closeOffSelector

      private void closeOffSelector(SAMHandlerPool.ConnContext ctx)
      Hand this context's teardown to the pool built for that work, so the selector thread stays free for the other connections it serves.
      Parameters:
      ctx - the connection's state