|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.jini.jeri.internal.runtime.SelectionManager
public final class SelectionManager
A SelectionManager provides an event dispatching layer on top of the java.nio.Selector and java.nio.SelectableChannel abstractions; it manages one-shot registrations of interest in I/O readiness events and dispatching notifications of such events to registered callback objects. SelectionManager is designed to support multiple select/dispatch threads to allow for improved I/O concurrency on symmetric multiprocessor systems. If interest in a particular I/O event is (re-)registered while there is a blocking select operation in progress, that select operation must be woken up so that it can take the new interest into account; this wakeup is achieved by writing a byte to an internal pipe that is registered with the underlying selector. A current limitation of this API is that it does not allow an executing callback to yield control in such a way that it will be scheduled to execute again without another I/O readiness event occurring. Therefore, data that gets read during a callback must also get processed, unless such processing depends on more data that has not yet been read (like the remainder of a partial message).
This implementation uses the Logger
named
com.sun.jini.jeri.internal.runtime.SelectionManager
to
log information at the following levels:
Level | Description |
---|---|
HANDLED | I/O exception caught from select operation |
Nested Class Summary | |
---|---|
class |
SelectionManager.Key
A Key represents a given SelectableChannel's registration with this SelectionManager. |
static interface |
SelectionManager.SelectionHandler
SelectionHandler is the callback interface for an object that will process an I/O readiness event that has been detected by a SelectionManager. |
private class |
SelectionManager.SelectLoop
SelectLoop provides the main loop for each I/O processing thread. |
Field Summary | |
---|---|
private static int |
concurrency
number of concurrent I/O processing threads |
private Object |
lock
lock guarding selectingThread, wakeupPending, renewQueue, readyQueue, renewMaskRef, and mutable state of all Key instances. |
private static Logger |
logger
|
private SelectionManager.Key |
readyQueue
queue of keys that have I/O operations ready to be handled |
private Map |
registeredChannels
set of registered channels, to detect duplicate registrations |
private int[] |
renewMaskRef
holder used for pass-by-reference invocations |
private SelectionManager.Key |
renewQueue
queue of keys that need to have interest masks updated |
private Thread |
selectingThread
thread with exclusive right to perform a select operation, if any |
private Selector |
selector
shared Selector used by this SelectionManager |
private static Executor |
systemThreadPool
pool of threads for executing tasks in system thread group |
private ByteBuffer |
wakeupBuffer
|
private boolean |
wakeupPending
true if a wakeup has been requested but not yet processed |
private SelectionKey |
wakeupPipeKey
|
private Pipe.SinkChannel |
wakeupPipeSink
internal pipe used to wake up a blocked select operation |
private Pipe.SourceChannel |
wakeupPipeSource
|
Constructor Summary | |
---|---|
SelectionManager()
Creates a new SelectionManager. |
Method Summary | |
---|---|
private void |
addOrUpdateReadyQueue(SelectionManager.Key key,
int newReadyMask)
|
private void |
addOrUpdateRenewQueue(SelectionManager.Key key,
int newRenewMask)
|
private void |
drainWakeupPipe()
|
private boolean |
isReadyQueueEmpty()
|
private boolean |
isRenewQueueEmpty()
|
private void |
processRenewQueue()
In preparation for performing a select operation, process all new and renewed interest registrations so that current SelectionKey interest masks are up to date. |
SelectionManager.Key |
register(SelectableChannel channel,
SelectionManager.SelectionHandler handler)
Registers the given SelectableChannel with this SelectionManager. |
private SelectionManager.Key |
removeFromReadyQueue(int[] readyMaskOut)
|
private SelectionManager.Key |
removeFromRenewQueue(int[] renewMaskOut)
|
private SelectionManager.Key |
waitForReadyKey(int[] readyMaskOut)
Waits until one of the registered channels is ready for one or more I/O operations. |
private void |
wakeupSelector()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int concurrency
private static final Logger logger
private static final Executor systemThreadPool
private final Selector selector
private final Pipe.SinkChannel wakeupPipeSink
private final Pipe.SourceChannel wakeupPipeSource
private final SelectionKey wakeupPipeKey
private final ByteBuffer wakeupBuffer
private final Map registeredChannels
private final Object lock
private Thread selectingThread
private boolean wakeupPending
private SelectionManager.Key renewQueue
private SelectionManager.Key readyQueue
private final int[] renewMaskRef
Constructor Detail |
---|
public SelectionManager() throws IOException
IOException
Method Detail |
---|
public SelectionManager.Key register(SelectableChannel channel, SelectionManager.SelectionHandler handler)
private SelectionManager.Key waitForReadyKey(int[] readyMaskOut) throws InterruptedException
InterruptedException
private void wakeupSelector()
private void drainWakeupPipe()
private void processRenewQueue()
private boolean isRenewQueueEmpty()
private SelectionManager.Key removeFromRenewQueue(int[] renewMaskOut)
private void addOrUpdateRenewQueue(SelectionManager.Key key, int newRenewMask)
private boolean isReadyQueueEmpty()
private SelectionManager.Key removeFromReadyQueue(int[] readyMaskOut)
private void addOrUpdateReadyQueue(SelectionManager.Key key, int newReadyMask)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |