java.lang.Object
net.i2p.sam.SAMHandlerPool.SelectorRunnable
- All Implemented Interfaces:
Runnable
- Enclosing class:
SAMHandlerPool
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateRuns the selector loop for one handler pool.Method Summary
Modifier and TypeMethodDescriptionprivate voidHand this context's teardown to the pool built for that work, so the selector thread stays free for the other connections it serves.private voiddisconnect(SAMHandlerPool.ConnContext ctx, String reason) Remove the context from the pool and stop the handler.private voiddispatchLine(SAMHandlerPool.ConnContext ctx, String line) Dispatch a complete command line to a worker thread.private voidhandlePing(SAMHandlerPool.ConnContext ctx, String line) Handle a PING or PONG from the client inline.private voidRead available data from a channel, split into lines, and dispatch complete lines.voidrun()private voidsendPing(SAMHandlerPool.ConnContext ctx, long now) Send a PING to the client and record the timestamp.
Constructor Details
SelectorRunnable
private SelectorRunnable()Runs the selector loop for one handler pool.
Method Details
run
readFromChannel
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 statech- the channel to read from- Throws:
IOException- if the read fails
dispatchLine
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 stateline- the complete command line to dispatch
handlePing
Handle a PING or PONG from the client inline.- Parameters:
ctx- the connection's stateline- the PING or PONG line received
sendPing
Send a PING to the client and record the timestamp.- Parameters:
ctx- the connection's statenow- the current time, in ms
disconnect
Remove the context from the pool and stop the handler. Called when a read error or timeout is detected.- Parameters:
ctx- the connection's statereason- why the connection is being dropped, for the log
closeOffSelector
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