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.
| Modifier and Type | Class and Description |
|---|---|
| public static interface | SelectorManager.AcceptListener
A listener for accept events. |
| public static interface |
| Modifier and Type | Field and Description |
|---|---|
| private final List | |
| private long | |
| private ThreadPoolBudget. | |
| private final AtomicInteger | |
| private final IntUnaryOperator | |
| private final ManagedSelector[] | |
| public static final int | |
| private final Executor | |
| protected static final Logger | |
| private final Scheduler |
| Access | Constructor and Description |
|---|---|
| protected | |
| protected | SelectorManager(Executor
The executor to use for handling selected executor, Scheduler EndPointsThe scheduler to use for timing events scheduler, int The number of selectors to use, or -1 for a default derived
from a heuristic over available CPUs and thread pool size. selectors)
|
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | accept(SelectableChannel
the channel to register channel, Object the attachment object attachment)Registers a channel to perform non-blocking read/write operations. |
| protected void | accepted(SelectableChannel
the channel)Callback method when a channel is accepted from the |
| public Closeable | Returns: A Closable that allows the acceptor to be cancelledthe server channel to register server)Registers a server channel for accept operations. |
| public boolean | addEventListener(EventListener
An EventListener listener)Overrides org. Implements org. |
| protected ManagedSelector | |
| public void | connect(SelectableChannel
the channel to register channel, Object the attachment object attachment)Registers a channel to perform a non-blocking connect. |
| public void | connectionClosed(Connection
the connection just closed connection, Throwable the cause of the close or null for normal close cause)Callback method invoked when a connection is closed. |
| protected void | connectionFailed(SelectableChannel
the channel that attempted the connect channel, Throwable the exception that caused the connect to fail ex, Object the attachment object associated at registration attachment)Callback method invoked when a non-blocking connect cannot be completed. |
| public void | connectionOpened(Connection
the connection just opened connection, Object the attachment associated with the creation of the connection context)Callback method invoked when a connection is opened. |
| private static int | |
| protected SelectableChannel | |
| protected boolean | |
| protected void | doStart()
Overrides org. |
| protected void | doStop()
Overrides org. |
| protected void | endPointClosed(EndPoint
the endpoint being closed endpoint)Callback method invoked when an endpoint is closed. |
| protected void | endPointOpened(EndPoint
the endpoint being opened endpoint)Callback method invoked when an endpoint is opened. |
| protected void | |
| public long | |
| public Executor | |
| public Scheduler | |
| public int | |
| public int | |
| protected boolean | |
| public abstract Connection | Returns: a new connectionthe channel associated to the connection channel, EndPoint the endpoint endpoint, Object the attachment attachment)Factory method to create |
| protected abstract EndPoint | Returns: a new endpointthe channel associated to the endpoint channel, ManagedSelector the selector the channel is registered to selector, SelectionKey the selection key selectionKey)Factory method to create |
| protected ManagedSelector | Returns: a newManagedSelectoran identifier for the id)to createFactory method for |
| protected Selector | |
| protected void | |
| protected void | |
| protected void | |
| public boolean | removeEventListener(EventListener
the listener to remove listener)Overrides org. Implements org. |
| public void | setConnectTimeout(long
the number of milliseconds for the timeout milliseconds)Set the connect timeout (in milliseconds) |
| public String | toString()
Overrides org. |
| _acceptListeners | back to summary |
|---|---|
| private final List<SelectorManager. | |
| _connectTimeout | back to summary |
|---|---|
| private long _connectTimeout | |
| _lease | back to summary |
|---|---|
| private ThreadPoolBudget. | |
| _selectorIndex | back to summary |
|---|---|
| private final AtomicInteger _selectorIndex | |
| _selectorIndexUpdate | back to summary |
|---|---|
| private final IntUnaryOperator _selectorIndexUpdate | |
| _selectors | back to summary |
|---|---|
| private final ManagedSelector[] _selectors | |
| DEFAULT_CONNECT_TIMEOUT | back to summary |
|---|---|
| public static final int DEFAULT_CONNECT_TIMEOUT | |
| executor | back to summary |
|---|---|
| private final Executor executor | |
| LOG | back to summary |
|---|---|
| protected static final Logger LOG Hides org. | |
| scheduler | back to summary |
|---|---|
| private final Scheduler scheduler | |
| SelectorManager | back to summary |
|---|---|
| protected SelectorManager(Executor executor, Scheduler scheduler) | |
| SelectorManager | back to summary |
|---|---|
| protected SelectorManager(Executor executor, Scheduler scheduler, int selectors) | |
| accept | back to summary |
|---|---|
public void accept(SelectableChannel channel)
| |
| accept | back to summary |
|---|---|
| public void accept(SelectableChannel 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
| |
| accepted | back to summary |
|---|---|
| protected void accepted(SelectableChannel channel) throws IOException Callback method when a channel is accepted from the
| |
| acceptor | back to summary |
|---|---|
| public Closeable acceptor(SelectableChannel server) Registers a server channel for accept operations.
When a
| |
| addEventListener | back to summary |
|---|---|
| public boolean addEventListener(EventListener listener) Overrides org. Implements org. Doc from org. Add an event listener. EventListeners added by this method are also added as beans.
| |
| chooseSelector | back to summary |
|---|---|
| protected ManagedSelector chooseSelector() | |
| connect | back to summary |
|---|---|
| public void connect(SelectableChannel channel, Object attachment) Registers a channel to perform a non-blocking connect. The channel must be set in non-blocking mode,
| |
| connectionClosed | back to summary |
|---|---|
| public void connectionClosed(Connection connection, Throwable cause) Callback method invoked when a connection is closed.
| |
| connectionFailed | back to summary |
|---|---|
| protected void connectionFailed(SelectableChannel channel, Throwable ex, Object attachment) Callback method invoked when a non-blocking connect cannot be completed. By default it just logs with level warning.
| |
| connectionOpened | back to summary |
|---|---|
| public void connectionOpened(Connection connection, Object context) Callback method invoked when a connection is opened.
| |
| defaultSelectors | back to summary |
|---|---|
| private static int defaultSelectors(Executor executor) | |
| doAccept | back to summary |
|---|---|
| protected SelectableChannel doAccept(SelectableChannel server) throws IOException | |
| doFinishConnect | back to summary |
|---|---|
| protected boolean doFinishConnect(SelectableChannel channel) throws IOException | |
| doStart | back to summary |
|---|---|
| protected void doStart() throws Exception Overrides org. Doc from org. Starts the managed lifecycle beans in the order they were added.
| |
| doStop | back to summary |
|---|---|
| protected void doStop() throws Exception Overrides org. Doc from org. Stops the managed lifecycle beans in the reverse order they were added.
| |
| endPointClosed | back to summary |
|---|---|
| protected void endPointClosed(EndPoint endpoint) Callback method invoked when an endpoint is closed.
| |
| endPointOpened | back to summary |
|---|---|
| protected void endPointOpened(EndPoint endpoint) Callback method invoked when an endpoint is opened.
| |
| execute | back to summary |
|---|---|
| protected void execute(Runnable task) Executes the given task in a different thread.
| |
| getConnectTimeout | back to summary |
|---|---|
| public long getConnectTimeout() Get the connect timeout
| |
| getExecutor | back to summary |
|---|---|
public Executor getExecutor()
| |
| getScheduler | back to summary |
|---|---|
public Scheduler getScheduler()
| |
| getSelectorCount | back to summary |
|---|---|
public int getSelectorCount()
| |
| getTotalKeys | back to summary |
|---|---|
| public int getTotalKeys() Get total number of keys from each selector.
| |
| isConnectionPending | back to summary |
|---|---|
| protected boolean isConnectionPending(SelectableChannel channel) | |
| newConnection | back to summary |
|---|---|
| public abstract Connection newConnection(SelectableChannel channel, EndPoint endpoint, Object attachment) throws IOException Factory method to create
| |
| newEndPoint | back to summary |
|---|---|
| protected abstract EndPoint newEndPoint(SelectableChannel channel, ManagedSelector selector, SelectionKey selectionKey) throws IOException Factory method to create This method is invoked as a result of the registration of a channel via
| |
| newSelector | back to summary |
|---|---|
| protected ManagedSelector newSelector(int id) Factory method for
| |
| newSelector | back to summary |
|---|---|
| protected Selector newSelector() throws IOException | |
| onAccepted | back to summary |
|---|---|
| protected void onAccepted(SelectableChannel channel) | |
| onAcceptFailed | back to summary |
|---|---|
| protected void onAcceptFailed(SelectableChannel channel, Throwable cause) | |
| onAccepting | back to summary |
|---|---|
| protected void onAccepting(SelectableChannel channel) | |
| removeEventListener | back to summary |
|---|---|
| public boolean removeEventListener(EventListener listener) Overrides org. Implements org. Doc from org. Remove an event listener.
| |
| setConnectTimeout | back to summary |
|---|---|
| public void setConnectTimeout(long milliseconds) Set the connect timeout (in milliseconds)
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides org. Doc from java. Returns a string representation of the object. | |
A listener for accept events.
This listener is called from either the selector or acceptor thread and implementations must be non blocking and fast.
| Modifier and Type | Method and Description |
|---|---|
| public default void | onAccepted(SelectableChannel
the accepted channel channel)Called after the accepted channel has been allocated an |
| public default void | onAcceptFailed(SelectableChannel
the accepted channel channel, Throwable the cause of the failure cause)Called if the processing of the accepted channel fails prior to calling
|
| public default void | onAccepting(SelectableChannel
the accepted channel channel)Called immediately after a new SelectableChannel is accepted, but
before it has been submitted to the |
| onAccepted | back to summary |
|---|---|
| public default void onAccepted(SelectableChannel channel) Called after the accepted channel has been allocated an
| |
| onAcceptFailed | back to summary |
|---|---|
| public default void onAcceptFailed(SelectableChannel channel, Throwable cause) Called if the processing of the accepted channel fails prior to calling
| |
| onAccepting | back to summary |
|---|---|
| public default void onAccepting(SelectableChannel channel) Called immediately after a new SelectableChannel is accepted, but
before it has been submitted to the
| |