Class SelectorManager
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.io.SelectorManager
-
- All Implemented Interfaces:
Container,Destroyable,Dumpable,LifeCycle
public abstract class SelectorManager extends ContainerLifeCycle implements Dumpable
SelectorManagermanages a number ofManagedSelectors that simplify the non-blocking primitives provided by the JVM via thejava.niopackage.SelectorManagersubclasses implement methods to return protocol-specificEndPoints andConnections.
-
-
Nested Class Summary
-
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.LifeCycle
LifeCycle.Listener
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_CONNECT_TIMEOUTprotected static LoggerLOG-
Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, RUNNING, STARTED, STARTING, STOP_ON_FAILURE, STOPPED, STOPPING
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedSelectorManager(Executor executor, Scheduler scheduler)protectedSelectorManager(Executor executor, Scheduler scheduler, int selectors)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaccept(SocketChannel channel)voidaccept(SocketChannel channel, Object attachment)Registers a channel to perform non-blocking read/write operations.protected voidaccepted(SocketChannel channel)Callback method when a channel is accepted from theServerSocketChannelpassed toacceptor(ServerSocketChannel).voidacceptor(ServerSocketChannel server)Registers a server channel for accept operations.voidconnect(SocketChannel channel, Object attachment)Registers a channel to perform a non-blocking connect.voidconnectionClosed(Connection connection)Callback method invoked when a connection is closed.protected voidconnectionFailed(SocketChannel channel, Throwable ex, Object attachment)Callback method invoked when a non-blocking connect cannot be completed.voidconnectionOpened(Connection connection)Callback method invoked when a connection is opened.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 voidexecute(Runnable task)Executes the given task in a different thread.protected booleanfinishConnect(SocketChannel channel)longgetConnectTimeout()Get the connect timeoutExecutionStrategy.FactorygetExecutionStrategyFactory()ExecutorgetExecutor()SchedulergetScheduler()intgetSelectorCount()intgetSelectorPriorityDelta()Deprecated.not implementedabstract ConnectionnewConnection(SocketChannel channel, EndPoint endpoint, Object attachment)Factory method to createConnection.protected abstract EndPointnewEndPoint(SocketChannel channel, ManagedSelector selector, SelectionKey selectionKey)Factory method to createEndPoint.protected ManagedSelectornewSelector(int id)Factory method forManagedSelector.voidsetConnectTimeout(long milliseconds)Set the connect timeout (in milliseconds)voidsetExecutionStrategyFactory(ExecutionStrategy.Factory _executionFactory)voidsetSelectorPriorityDelta(int selectorPriorityDelta)Deprecated.not implemented-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, dumpThis, getBean, getBeans, getBeans, isManaged, 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
-
-
-
-
Field Detail
-
DEFAULT_CONNECT_TIMEOUT
public static final int DEFAULT_CONNECT_TIMEOUT
- See Also:
- Constant Field Values
-
LOG
protected static final Logger LOG
-
-
Method Detail
-
getExecutor
public Executor getExecutor()
-
getScheduler
public Scheduler getScheduler()
-
getConnectTimeout
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
-
getExecutionStrategyFactory
public ExecutionStrategy.Factory getExecutionStrategyFactory()
- Returns:
- the
ExecutionStrategy.Factoryused byManagedSelector
-
setExecutionStrategyFactory
public void setExecutionStrategyFactory(ExecutionStrategy.Factory _executionFactory)
- Parameters:
_executionFactory- theExecutionStrategy.Factoryused byManagedSelector
-
getSelectorPriorityDelta
@Deprecated public int getSelectorPriorityDelta()
Deprecated.not implemented- Returns:
- the selector priority delta
-
setSelectorPriorityDelta
@Deprecated public void setSelectorPriorityDelta(int selectorPriorityDelta)
Deprecated.not implemented- Parameters:
selectorPriorityDelta- the selector priority delta
-
execute
protected void execute(Runnable task)
Executes the given task in a different thread.- Parameters:
task- the task to execute
-
getSelectorCount
public int getSelectorCount()
- Returns:
- the number of selectors in use
-
connect
public void connect(SocketChannel channel, Object attachment)
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(SocketChannel, Object)
-
accept
public void accept(SocketChannel channel)
- Parameters:
channel- the channel to accept- See Also:
accept(SocketChannel, Object)
-
accept
public void accept(SocketChannel channel, Object attachment)
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
public void acceptor(ServerSocketChannel server)
Registers a server channel for accept operations. When a
SocketChannelis accepted from the givenServerSocketChannelthen theaccepted(SocketChannel)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
-
accepted
protected void accepted(SocketChannel channel) throws IOException
Callback method when a channel is accepted from theServerSocketChannelpassed toacceptor(ServerSocketChannel). 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
protected void doStart() throws Exception- Overrides:
doStartin classContainerLifeCycle- Throws:
Exception
-
newSelector
protected ManagedSelector newSelector(int id)
Factory method for
ManagedSelector.- Parameters:
id- an identifier for theto create- Returns:
- a new
ManagedSelector
-
doStop
protected void doStop() throws Exception- Overrides:
doStopin classContainerLifeCycle- Throws:
Exception
-
endPointOpened
protected void endPointOpened(EndPoint endpoint)
Callback method invoked when an endpoint is opened.
- Parameters:
endpoint- the endpoint being opened
-
endPointClosed
protected void endPointClosed(EndPoint endpoint)
Callback method invoked when an endpoint is closed.
- Parameters:
endpoint- the endpoint being closed
-
connectionOpened
public void connectionOpened(Connection connection)
Callback method invoked when a connection is opened.
- Parameters:
connection- the connection just opened
-
connectionClosed
public void connectionClosed(Connection connection)
Callback method invoked when a connection is closed.
- Parameters:
connection- the connection just closed
-
finishConnect
protected boolean finishConnect(SocketChannel channel) throws IOException
- Throws:
IOException
-
connectionFailed
protected void connectionFailed(SocketChannel channel, Throwable ex, Object attachment)
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(SocketChannel 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(SocketChannel, Object)oraccept(SocketChannel).- 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(SocketChannel, EndPoint, Object)
-
newConnection
public abstract Connection newConnection(SocketChannel 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- See Also:
newEndPoint(SocketChannel, ManagedSelector, SelectionKey)
-
-