Package org.eclipse.jetty.io
Class ManagedSelector
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.io.ManagedSelector
-
- All Implemented Interfaces:
Container
,Destroyable
,Dumpable
,Dumpable.DumpableContainer
,LifeCycle
public class ManagedSelector extends ContainerLifeCycle implements Dumpable
ManagedSelector
wraps aSelector
simplifying non-blocking operations on channels.ManagedSelector
runs the select loop, which waits onSelector.select()
until events happen for registered channels. When events happen, it notifies theEndPoint
associated with the channel.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 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
AManagedSelector.Selectable
is anEndPoint
that wish to be notified of non-blocking events by theManagedSelector
.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
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener, Container.Listener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
-
-
Field Summary
Fields Modifier and Type Field Description private int
_id
private SampleStatistic
_keyStats
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 Summary
Constructors Constructor Description ManagedSelector(SelectorManager selectorManager, int id)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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()
double
getAverageSelectedKeys()
double
getMaxSelectedKeys()
long
getSelectCount()
java.nio.channels.Selector
getSelector()
int
getTotalKeys()
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)
void
resetStats()
(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 anManagedSelector.SelectorUpdate
to be acted on between calls toSelector.select()
private void
submit(ManagedSelector.SelectorUpdate update, boolean lazy)
java.lang.String
toString()
private void
wakeup()
-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
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, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
-
-
-
-
Field Detail
-
LOG
private static final Logger LOG
-
FORCE_SELECT_NOW
private static final boolean FORCE_SELECT_NOW
-
_started
private final java.util.concurrent.atomic.AtomicBoolean _started
-
_selecting
private boolean _selecting
-
_selectorManager
private final SelectorManager _selectorManager
-
_id
private final int _id
-
_strategy
private final ExecutionStrategy _strategy
-
_selector
private java.nio.channels.Selector _selector
-
_updates
private java.util.Deque<ManagedSelector.SelectorUpdate> _updates
-
_updateable
private java.util.Deque<ManagedSelector.SelectorUpdate> _updateable
-
_keyStats
private final SampleStatistic _keyStats
-
-
Constructor Detail
-
ManagedSelector
public ManagedSelector(SelectorManager selectorManager, int id)
-
-
Method Detail
-
getSelector
public java.nio.channels.Selector getSelector()
-
doStart
protected void doStart() throws java.lang.Exception
Description copied from class:ContainerLifeCycle
Starts the managed lifecycle beans in the order they were added.- Overrides:
doStart
in classContainerLifeCycle
- Throws:
java.lang.Exception
-
doStop
protected void doStop() throws java.lang.Exception
Description copied from class:ContainerLifeCycle
Stops the managed lifecycle beans in the reverse order they were added.- Overrides:
doStop
in classContainerLifeCycle
- Throws:
java.lang.Exception
-
getTotalKeys
@ManagedAttribute(value="Total number of keys", readonly=true) public int getTotalKeys()
-
getAverageSelectedKeys
@ManagedAttribute(value="Average number of selected keys", readonly=true) public double getAverageSelectedKeys()
-
getMaxSelectedKeys
@ManagedAttribute(value="Maximum number of selected keys", readonly=true) public double getMaxSelectedKeys()
-
getSelectCount
@ManagedAttribute(value="Total number of select() calls", readonly=true) public long getSelectCount()
-
resetStats
@ManagedOperation(value="Resets the statistics", impact="ACTION") public void resetStats()
-
nioSelect
protected int nioSelect(java.nio.channels.Selector selector, boolean now) throws java.io.IOException
- Throws:
java.io.IOException
-
select
protected int select(java.nio.channels.Selector selector) throws java.io.IOException
- Throws:
java.io.IOException
-
handleSelectFailure
protected void handleSelectFailure(java.nio.channels.Selector selector, java.lang.Throwable failure) throws java.io.IOException
- Throws:
java.io.IOException
-
onSelectFailed
protected void onSelectFailed(java.lang.Throwable cause)
-
size
public int size()
-
submit
public void submit(ManagedSelector.SelectorUpdate update)
Submit anManagedSelector.SelectorUpdate
to be acted on between calls toSelector.select()
- Parameters:
update
- The selector update to apply at next wakeup
-
submit
private void submit(ManagedSelector.SelectorUpdate update, boolean lazy)
-
wakeup
private void wakeup()
-
execute
private void execute(java.lang.Runnable task)
-
processConnect
private void processConnect(java.nio.channels.SelectionKey key, ManagedSelector.Connect connect)
-
endPointOpened
protected void endPointOpened(EndPoint endPoint)
-
endPointClosed
protected void endPointClosed(EndPoint endPoint)
-
createEndPoint
private void createEndPoint(java.nio.channels.SelectableChannel channel, java.nio.channels.SelectionKey selectionKey) throws java.io.IOException
- Throws:
java.io.IOException
-
destroyEndPoint
void destroyEndPoint(EndPoint endPoint)
-
getActionSize
private int getActionSize()
-
safeReadyOps
static int safeReadyOps(java.nio.channels.SelectionKey selectionKey)
-
safeInterestOps
static int safeInterestOps(java.nio.channels.SelectionKey selectionKey)
-
dump
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException
Description copied from interface:Dumpable
Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.- Specified by:
dump
in interfaceDumpable
- Overrides:
dump
in classContainerLifeCycle
- Parameters:
out
- The appendable to dump toindent
- The indent to apply after any new lines.- Throws:
java.io.IOException
- if unable to write to Appendable
-
toString
public java.lang.String toString()
- Overrides:
toString
in classAbstractLifeCycle
-
-