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.ThreadThread.State, Thread.UncaughtExceptionHandler
 
- 
 - 
Field Summary- 
Fields inherited from class java.lang.ThreadMAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
- 
 - 
Constructor SummaryConstructors Constructor Description SelectorThread(int id)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddAcceptedConnection(SocketChannel accepted)Place new accepted connection onto a queue for adding.booleanaddInterestOpsUpdateRequest(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.voidrun()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.ZooKeeperThreadhandleException
 - 
Methods inherited from class java.lang.ThreadactiveCount, 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- 
SelectorThreadpublic SelectorThread(int id) throws IOException- Throws:
- IOException
 
 
- 
 - 
Method Detail- 
addAcceptedConnectionpublic 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.
 - 
addInterestOpsUpdateRequestpublic 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.
 
- 
 
-