Package org.apache.zookeeper.server
Class NIOServerCnxnFactory.SelectorThread
- java.lang.Object
-
- java.lang.Thread
-
- org.apache.zookeeper.server.ZooKeeperThread
-
- org.apache.zookeeper.server.NIOServerCnxnFactory.SelectorThread
-
- All Implemented Interfaces:
Runnable
- Enclosing class:
- NIOServerCnxnFactory
public class NIOServerCnxnFactory.SelectorThread extends ZooKeeperThread
The SelectorThread receives newly accepted connections from the AcceptThread and is responsible for selecting for I/O readiness across the connections. This thread is the only thread that performs any non-threadsafe or potentially blocking calls on the selector (registering new connections and reading/writing interest ops). Assignment of a connection to a SelectorThread is permanent and only one SelectorThread will ever interact with the connection. There are 1-N SelectorThreads, with connections evenly apportioned between the SelectorThreads. If there is a worker thread pool, when a connection has I/O to perform the SelectorThread removes it from selection by clearing its interest ops and schedules the I/O for processing by a worker thread. When the work is complete, the connection is placed on the ready queue to have its interest ops restored and resume selection. If there is no worker thread pool, the SelectorThread performs the I/O directly.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
-
Field Summary
-
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description SelectorThread(int id)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addAcceptedConnection(SocketChannel accepted)
Place new accepted connection onto a queue for adding.boolean
addInterestOpsUpdateRequest(SelectionKey sk)
Place interest op update requests onto a queue so that only the selector thread modifies interest ops, because interest ops reads/sets are potentially blocking operations if other select operations are happening.void
run()
The main loop for the thread selects() on the connections and dispatches ready I/O work requests, then registers all pending newly accepted connections and updates any interest ops on the queue.-
Methods inherited from class org.apache.zookeeper.server.ZooKeeperThread
handleException
-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
-
-
-
-
Constructor Detail
-
SelectorThread
public SelectorThread(int id) throws IOException
- Throws:
IOException
-
-
Method Detail
-
addAcceptedConnection
public boolean addAcceptedConnection(SocketChannel accepted)
Place new accepted connection onto a queue for adding. Do this so only the selector thread modifies what keys are registered with the selector.
-
addInterestOpsUpdateRequest
public boolean addInterestOpsUpdateRequest(SelectionKey sk)
Place interest op update requests onto a queue so that only the selector thread modifies interest ops, because interest ops reads/sets are potentially blocking operations if other select operations are happening.
-
-