public class ManagedSelector extends ContainerLifeCycle implements Dumpable
ManagedSelector wraps a Selector simplifying non-blocking operations on channels.
ManagedSelector runs the select loop, which waits on Selector.select() until events
happen for registered channels. When events happen, it notifies the EndPoint associated
with the channel.
| Modifier and Type | Class and Description |
|---|---|
(package private) class |
ManagedSelector.Accept |
(package private) class |
ManagedSelector.Acceptor |
private class |
ManagedSelector.CloseConnections |
(package private) class |
ManagedSelector.Connect |
private class |
ManagedSelector.CreateEndPoint |
private class |
ManagedSelector.DestroyEndPoint |
private static class |
ManagedSelector.DumpKeys |
static interface |
ManagedSelector.Selectable
A
ManagedSelector.Selectable is an EndPoint that wish to be
notified of non-blocking events by the ManagedSelector. |
private class |
ManagedSelector.SelectorProducer |
static interface |
ManagedSelector.SelectorUpdate
A selector update to be done when the selector has been woken.
|
private class |
ManagedSelector.Start |
private class |
ManagedSelector.StopSelector |
AbstractLifeCycle.AbstractLifeCycleListenerContainer.InheritedListener, Container.ListenerLifeCycle.Listener| Modifier and Type | Field and Description |
|---|---|
private int |
_id |
private boolean |
_selecting |
private java.nio.channels.Selector |
_selector |
private SelectorManager |
_selectorManager |
private java.util.concurrent.atomic.AtomicBoolean |
_started |
private ExecutionStrategy |
_strategy |
private java.util.Deque<ManagedSelector.SelectorUpdate> |
_updateable |
private java.util.Deque<ManagedSelector.SelectorUpdate> |
_updates |
private static boolean |
FORCE_SELECT_NOW |
private static Logger |
LOG |
| Constructor and Description |
|---|
ManagedSelector(SelectorManager selectorManager,
int id) |
| Modifier and Type | Method and Description |
|---|---|
private void |
createEndPoint(java.nio.channels.SelectableChannel channel,
java.nio.channels.SelectionKey selectionKey) |
(package private) void |
destroyEndPoint(EndPoint endPoint) |
protected void |
doStart()
Starts the managed lifecycle beans in the order they were added.
|
protected void |
doStop()
Stops the managed lifecycle beans in the reverse order they were added.
|
void |
dump(java.lang.Appendable out,
java.lang.String indent)
Dump this object (and children) into an Appendable using the provided indent after any new lines.
|
protected void |
endPointClosed(EndPoint endPoint) |
protected void |
endPointOpened(EndPoint endPoint) |
private void |
execute(java.lang.Runnable task) |
private int |
getActionSize() |
java.nio.channels.Selector |
getSelector() |
protected void |
handleSelectFailure(java.nio.channels.Selector selector,
java.lang.Throwable failure) |
protected int |
nioSelect(java.nio.channels.Selector selector,
boolean now) |
protected void |
onSelectFailed(java.lang.Throwable cause) |
private void |
processConnect(java.nio.channels.SelectionKey key,
ManagedSelector.Connect connect) |
(package private) static int |
safeInterestOps(java.nio.channels.SelectionKey selectionKey) |
(package private) static int |
safeReadyOps(java.nio.channels.SelectionKey selectionKey) |
protected int |
select(java.nio.channels.Selector selector) |
int |
size() |
void |
submit(ManagedSelector.SelectorUpdate update)
Submit an
ManagedSelector.SelectorUpdate to be acted on between calls to Selector.select() |
private void |
submit(ManagedSelector.SelectorUpdate update,
boolean lazy) |
java.lang.String |
toString() |
private void |
wakeup() |
addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeansaddLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stopclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitdump, dump, dumpContainer, dumpIterable, dumpMapEntries, dumpObject, dumpObjects, dumpSelf, namedprivate static final Logger LOG
private static final boolean FORCE_SELECT_NOW
private final java.util.concurrent.atomic.AtomicBoolean _started
private boolean _selecting
private final SelectorManager _selectorManager
private final int _id
private final ExecutionStrategy _strategy
private java.nio.channels.Selector _selector
private java.util.Deque<ManagedSelector.SelectorUpdate> _updates
private java.util.Deque<ManagedSelector.SelectorUpdate> _updateable
public ManagedSelector(SelectorManager selectorManager, int id)
public java.nio.channels.Selector getSelector()
protected void doStart()
throws java.lang.Exception
ContainerLifeCycledoStart in class ContainerLifeCyclejava.lang.Exceptionprotected void doStop()
throws java.lang.Exception
ContainerLifeCycledoStop in class ContainerLifeCyclejava.lang.Exceptionprotected int nioSelect(java.nio.channels.Selector selector,
boolean now)
throws java.io.IOException
java.io.IOExceptionprotected int select(java.nio.channels.Selector selector)
throws java.io.IOException
java.io.IOExceptionprotected void handleSelectFailure(java.nio.channels.Selector selector,
java.lang.Throwable failure)
throws java.io.IOException
java.io.IOExceptionprotected void onSelectFailed(java.lang.Throwable cause)
public int size()
public void submit(ManagedSelector.SelectorUpdate update)
ManagedSelector.SelectorUpdate to be acted on between calls to Selector.select()update - The selector update to apply at next wakeupprivate void submit(ManagedSelector.SelectorUpdate update, boolean lazy)
private void wakeup()
private void execute(java.lang.Runnable task)
private void processConnect(java.nio.channels.SelectionKey key,
ManagedSelector.Connect connect)
protected void endPointOpened(EndPoint endPoint)
protected void endPointClosed(EndPoint endPoint)
private void createEndPoint(java.nio.channels.SelectableChannel channel,
java.nio.channels.SelectionKey selectionKey)
throws java.io.IOException
java.io.IOExceptionvoid destroyEndPoint(EndPoint endPoint)
private int getActionSize()
static int safeReadyOps(java.nio.channels.SelectionKey selectionKey)
static int safeInterestOps(java.nio.channels.SelectionKey selectionKey)
public void dump(java.lang.Appendable out,
java.lang.String indent)
throws java.io.IOException
Dumpabledump in interface Dumpabledump in class ContainerLifeCycleout - The appendable to dump toindent - The indent to apply after any new lines.java.io.IOException - if unable to write to Appendablepublic java.lang.String toString()
toString in class AbstractLifeCycle