- All Implemented Interfaces:
org.eclipse.jetty.util.component.Container,org.eclipse.jetty.util.component.Destroyable,org.eclipse.jetty.util.component.Dumpable,org.eclipse.jetty.util.component.Dumpable.DumpableContainer,org.eclipse.jetty.util.component.LifeCycle
- Direct Known Subclasses:
ClientConnector.ClientSelectorManager
SelectorManager manages a number of ManagedSelectors that
simplify the non-blocking primitives provided by the JVM via the java.nio package.
SelectorManager subclasses implement methods to return protocol-specific
EndPoints and Connections.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA listener for accept events.static interfaceNested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.ListenerNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
org.eclipse.jetty.util.component.Dumpable.DumpableContainerNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
org.eclipse.jetty.util.component.LifeCycle.Listener -
Field Summary
FieldsFields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, STARTED, STARTING, STOPPED, STOPPINGFields inherited from interface org.eclipse.jetty.util.component.Dumpable
KEY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSelectorManager(Executor executor, org.eclipse.jetty.util.thread.Scheduler scheduler) protectedSelectorManager(Executor executor, org.eclipse.jetty.util.thread.Scheduler scheduler, int selectors) -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(SelectableChannel channel) voidaccept(SelectableChannel channel, Object attachment) Registers a channel to perform non-blocking read/write operations.protected voidaccepted(SelectableChannel channel) Callback method when a channel is accepted from theServerSocketChannelpassed toacceptor(SelectableChannel).acceptor(SelectableChannel server) Registers a server channel for accept operations.booleanaddEventListener(EventListener listener) protected ManagedSelectorvoidconnect(SelectableChannel channel, Object attachment) Registers a channel to perform a non-blocking connect.voidconnectionClosed(Connection connection, Throwable cause) Callback method invoked when a connection is closed.protected voidconnectionFailed(SelectableChannel channel, Throwable ex, Object attachment) Callback method invoked when a non-blocking connect cannot be completed.voidconnectionOpened(Connection connection, Object context) Callback method invoked when a connection is opened.protected SelectableChanneldoAccept(SelectableChannel server) protected booleandoFinishConnect(SelectableChannel channel) protected voiddoStart()protected voiddoStop()protected voidendPointClosed(EndPoint endpoint) Callback method invoked when an endpoint is closed.protected voidendPointOpened(EndPoint endpoint) Callback method invoked when an endpoint is opened.protected voidExecutes the given task in a different thread.longGet the connect timeoutorg.eclipse.jetty.util.thread.SchedulerintintGet total number of keys from each selector.protected booleanisConnectionPending(SelectableChannel channel) abstract ConnectionnewConnection(SelectableChannel channel, EndPoint endpoint, Object attachment) Factory method to createConnection.protected abstract EndPointnewEndPoint(SelectableChannel channel, ManagedSelector selector, SelectionKey selectionKey) Factory method to createEndPoint.protected Selectorprotected ManagedSelectornewSelector(int id) Factory method forManagedSelector.protected voidonAccepted(SelectableChannel channel) protected voidonAcceptFailed(SelectableChannel channel, Throwable cause) protected voidonAccepting(SelectableChannel channel) booleanremoveEventListener(EventListener listener) voidsetConnectTimeout(long milliseconds) Set the connect timeout (in milliseconds)toString()Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addManaged, contains, destroy, dump, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeansMethods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListenersMethods inherited from interface org.eclipse.jetty.util.component.Dumpable
dump, dump, dumpSelfMethods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
-
Field Details
-
DEFAULT_CONNECT_TIMEOUT
public static final int DEFAULT_CONNECT_TIMEOUT- See Also:
-
-
Constructor Details
-
SelectorManager
-
SelectorManager
protected SelectorManager(Executor executor, org.eclipse.jetty.util.thread.Scheduler scheduler, int selectors) - Parameters:
executor- The executor to use for handling selectedEndPointsscheduler- The scheduler to use for timing eventsselectors- The number of selectors to use, or -1 for a default derived from a heuristic over available CPUs and thread pool size.
-
-
Method Details
-
getExecutor
-
getScheduler
@ManagedAttribute("The Scheduler") public org.eclipse.jetty.util.thread.Scheduler getScheduler() -
getConnectTimeout
@ManagedAttribute("The Connection timeout (ms)") public long getConnectTimeout()Get the connect timeout- Returns:
- the connect timeout (in milliseconds)
-
setConnectTimeout
public void setConnectTimeout(long milliseconds) Set the connect timeout (in milliseconds)- Parameters:
milliseconds- the number of milliseconds for the timeout
-
execute
Executes the given task in a different thread.- Parameters:
task- the task to execute
-
getTotalKeys
@ManagedAttribute(value="Total number of keys in all selectors", readonly=true) public int getTotalKeys()Get total number of keys from each selector.- Returns:
- total number of selector keys
-
getSelectorCount
@ManagedAttribute("The number of NIO Selectors") public int getSelectorCount()- Returns:
- the number of selectors in use
-
chooseSelector
-
connect
Registers a channel to perform a non-blocking connect.
The channel must be set in non-blocking mode,
SocketChannel.connect(SocketAddress)must be called prior to calling this method, and the connect operation must not be completed (the return value ofSocketChannel.connect(SocketAddress)must be false).- Parameters:
channel- the channel to registerattachment- the attachment object- See Also:
-
accept
- Parameters:
channel- the channel to accept- See Also:
-
accept
Registers a channel to perform non-blocking read/write operations.
This method is called just after a channel has been accepted by
ServerSocketChannel.accept(), or just after having performed a blocking connect viaSocket.connect(SocketAddress, int), or just after a non-blocking connect viaSocketChannel.connect(SocketAddress)that completed successfully.- Parameters:
channel- the channel to registerattachment- the attachment object
-
acceptor
Registers a server channel for accept operations. When a
SocketChannelis accepted from the givenServerSocketChannelthen theaccepted(SelectableChannel)method is called, which must be overridden by a derivation of this class to handle the accepted channel- Parameters:
server- the server channel to register- Returns:
- A Closable that allows the acceptor to be cancelled
-
accepted
Callback method when a channel is accepted from theServerSocketChannelpassed toacceptor(SelectableChannel). The default impl throws anUnsupportedOperationException, so it must be overridden by subclasses if a server channel is provided.- Parameters:
channel- the- Throws:
IOException- if unable to accept channel
-
doStart
-
newSelector
Factory method for
ManagedSelector.- Parameters:
id- an identifier for theto create- Returns:
- a new
ManagedSelector
-
newSelector
- Throws:
IOException
-
doStop
-
endPointOpened
Callback method invoked when an endpoint is opened.
- Parameters:
endpoint- the endpoint being opened
-
endPointClosed
Callback method invoked when an endpoint is closed.
- Parameters:
endpoint- the endpoint being closed
-
connectionOpened
Callback method invoked when a connection is opened.
- Parameters:
connection- the connection just openedcontext- the attachment associated with the creation of the connection- See Also:
-
connectionClosed
Callback method invoked when a connection is closed.
- Parameters:
connection- the connection just closedcause- the cause of the close or null for normal close
-
doFinishConnect
- Throws:
IOException
-
isConnectionPending
-
doAccept
- Throws:
IOException
-
connectionFailed
Callback method invoked when a non-blocking connect cannot be completed.
By default it just logs with level warning.
- Parameters:
channel- the channel that attempted the connectex- the exception that caused the connect to failattachment- the attachment object associated at registration
-
newEndPoint
protected abstract EndPoint newEndPoint(SelectableChannel channel, ManagedSelector selector, SelectionKey selectionKey) throws IOException Factory method to create
EndPoint.This method is invoked as a result of the registration of a channel via
connect(SelectableChannel, Object)oraccept(SelectableChannel).- Parameters:
channel- the channel associated to the endpointselector- the selector the channel is registered toselectionKey- the selection key- Returns:
- a new endpoint
- Throws:
IOException- if the endPoint cannot be created- See Also:
-
newConnection
public abstract Connection newConnection(SelectableChannel channel, EndPoint endpoint, Object attachment) throws IOException Factory method to create
Connection.- Parameters:
channel- the channel associated to the connectionendpoint- the endpointattachment- the attachment- Returns:
- a new connection
- Throws:
IOException- if unable to create new connection
-
addEventListener
- Specified by:
addEventListenerin interfaceorg.eclipse.jetty.util.component.Container- Specified by:
addEventListenerin interfaceorg.eclipse.jetty.util.component.LifeCycle- Overrides:
addEventListenerin classorg.eclipse.jetty.util.component.ContainerLifeCycle- Parameters:
listener- An EventListener- See Also:
-
removeEventListener
- Specified by:
removeEventListenerin interfaceorg.eclipse.jetty.util.component.Container- Specified by:
removeEventListenerin interfaceorg.eclipse.jetty.util.component.LifeCycle- Overrides:
removeEventListenerin classorg.eclipse.jetty.util.component.ContainerLifeCycle
-
onAccepting
-
onAcceptFailed
-
onAccepted
-
toString
- Overrides:
toStringin classorg.eclipse.jetty.util.component.AbstractLifeCycle
-