public final class NioEventLoop extends SingleThreadEventLoop
SingleThreadEventLoop
implementation which register the Channel
's to a
Selector
and so does the multi-plexing of these in the event loop.Modifier and Type | Field and Description |
---|---|
private int |
cancelledKeys |
private static int |
CLEANUP_INTERVAL |
private static boolean |
DISABLE_KEYSET_OPTIMIZATION |
private int |
ioRatio |
private static InternalLogger |
logger |
private static int |
MIN_PREMATURE_SELECTOR_RETURNS |
private boolean |
needsToSelectAgain |
private java.util.concurrent.Callable<java.lang.Integer> |
pendingTasksCallable |
private java.nio.channels.spi.SelectorProvider |
provider |
private SelectedSelectionKeySet |
selectedKeys |
private IntSupplier |
selectNowSupplier |
(package private) java.nio.channels.Selector |
selector
The NIO
Selector . |
private static int |
SELECTOR_AUTO_REBUILD_THRESHOLD |
private SelectStrategy |
selectStrategy |
private java.util.concurrent.atomic.AtomicBoolean |
wakenUp
Boolean that controls determines if a blocked Selector.select should
break out of its selection process.
|
DEFAULT_MAX_PENDING_TASKS
Constructor and Description |
---|
NioEventLoop(NioEventLoopGroup parent,
java.util.concurrent.ThreadFactory threadFactory,
java.nio.channels.spi.SelectorProvider selectorProvider,
SelectStrategy strategy,
RejectedExecutionHandler rejectedExecutionHandler) |
Modifier and Type | Method and Description |
---|---|
(package private) void |
cancel(java.nio.channels.SelectionKey key) |
protected void |
cleanup()
Do nothing, sub-classes may override
|
private void |
closeAll() |
int |
getIoRatio()
Returns the percentage of the desired amount of time spent for I/O in the event loop.
|
private static void |
handleLoopException(java.lang.Throwable t) |
private static void |
invokeChannelUnregistered(NioTask<java.nio.channels.SelectableChannel> task,
java.nio.channels.SelectionKey k,
java.lang.Throwable cause) |
protected java.util.Queue<java.lang.Runnable> |
newTaskQueue(int maxPendingTasks)
Create a new
Queue which will holds the tasks to execute. |
private java.nio.channels.Selector |
openSelector() |
int |
pendingTasks()
Return the number of tasks that are pending for processing.
|
protected java.lang.Runnable |
pollTask() |
private void |
processSelectedKey(java.nio.channels.SelectionKey k,
AbstractNioChannel ch) |
private static void |
processSelectedKey(java.nio.channels.SelectionKey k,
NioTask<java.nio.channels.SelectableChannel> task) |
private void |
processSelectedKeys() |
private void |
processSelectedKeysOptimized(java.nio.channels.SelectionKey[] selectedKeys) |
private void |
processSelectedKeysPlain(java.util.Set<java.nio.channels.SelectionKey> selectedKeys) |
void |
rebuildSelector()
Replaces the current
Selector of this event loop with newly created Selector s to work
around the infamous epoll 100% CPU bug. |
void |
register(java.nio.channels.SelectableChannel ch,
int interestOps,
NioTask<?> task)
Registers an arbitrary
SelectableChannel , not necessarily created by Netty, to the Selector
of this event loop. |
protected void |
run() |
private void |
select(boolean oldWakenUp) |
private void |
selectAgain() |
(package private) int |
selectNow() |
java.nio.channels.spi.SelectorProvider |
selectorProvider()
|
void |
setIoRatio(int ioRatio)
Sets the percentage of the desired amount of time spent for I/O in the event loop.
|
protected void |
wakeup(boolean inEventLoop) |
next, parent, register, register, wakesUpForTask
addShutdownHook, addTask, awaitTermination, confirmShutdown, delayNanos, execute, hasTasks, inEventLoop, interruptThread, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isShuttingDown, isTerminated, newTaskQueue, peekTask, reject, removeShutdownHook, removeTask, runAllTasks, runAllTasks, shutdown, shutdownGracefully, takeTask, terminationFuture, threadProperties, updateLastExecutionTime
cancelScheduledTasks, hasScheduledTasks, nanoTime, nextScheduledTaskNano, pollScheduledTask, pollScheduledTask, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay
inEventLoop, iterator, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, newTaskFor, newTaskFor, shutdownGracefully, shutdownNow, submit, submit, submit
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
inEventLoop, inEventLoop, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture
isShuttingDown, iterator, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, shutdown, shutdownGracefully, shutdownGracefully, shutdownNow, submit, submit, submit, terminationFuture
private static final InternalLogger logger
private static final int CLEANUP_INTERVAL
private static final boolean DISABLE_KEYSET_OPTIMIZATION
private static final int MIN_PREMATURE_SELECTOR_RETURNS
private static final int SELECTOR_AUTO_REBUILD_THRESHOLD
private final IntSupplier selectNowSupplier
private final java.util.concurrent.Callable<java.lang.Integer> pendingTasksCallable
java.nio.channels.Selector selector
Selector
.private SelectedSelectionKeySet selectedKeys
private final java.nio.channels.spi.SelectorProvider provider
private final java.util.concurrent.atomic.AtomicBoolean wakenUp
private final SelectStrategy selectStrategy
private volatile int ioRatio
private int cancelledKeys
private boolean needsToSelectAgain
NioEventLoop(NioEventLoopGroup parent, java.util.concurrent.ThreadFactory threadFactory, java.nio.channels.spi.SelectorProvider selectorProvider, SelectStrategy strategy, RejectedExecutionHandler rejectedExecutionHandler)
private java.nio.channels.Selector openSelector()
public java.nio.channels.spi.SelectorProvider selectorProvider()
protected java.util.Queue<java.lang.Runnable> newTaskQueue(int maxPendingTasks)
SingleThreadEventExecutor
Queue
which will holds the tasks to execute. This default implementation will return a
LinkedBlockingQueue
but if your sub-class of SingleThreadEventExecutor
will not do any blocking
calls on the this Queue
it may make sense to @Override
this and return some more performant
implementation that does not support blocking operations at all.newTaskQueue
in class SingleThreadEventExecutor
public int pendingTasks()
SingleThreadEventExecutor
pendingTasks
in class SingleThreadEventExecutor
public void register(java.nio.channels.SelectableChannel ch, int interestOps, NioTask<?> task)
SelectableChannel
, not necessarily created by Netty, to the Selector
of this event loop. Once the specified SelectableChannel
is registered, the specified task
will
be executed by this event loop when the SelectableChannel
is ready.public int getIoRatio()
public void setIoRatio(int ioRatio)
50
, which means the event loop will try to spend the same amount of time for I/O as for non-I/O tasks.public void rebuildSelector()
Selector
of this event loop with newly created Selector
s to work
around the infamous epoll 100% CPU bug.protected void run()
run
in class SingleThreadEventExecutor
private static void handleLoopException(java.lang.Throwable t)
private void processSelectedKeys()
protected void cleanup()
SingleThreadEventExecutor
cleanup
in class SingleThreadEventExecutor
void cancel(java.nio.channels.SelectionKey key)
protected java.lang.Runnable pollTask()
pollTask
in class SingleThreadEventExecutor
Queue#poll()}
private void processSelectedKeysPlain(java.util.Set<java.nio.channels.SelectionKey> selectedKeys)
private void processSelectedKeysOptimized(java.nio.channels.SelectionKey[] selectedKeys)
private void processSelectedKey(java.nio.channels.SelectionKey k, AbstractNioChannel ch)
private static void processSelectedKey(java.nio.channels.SelectionKey k, NioTask<java.nio.channels.SelectableChannel> task)
private void closeAll()
private static void invokeChannelUnregistered(NioTask<java.nio.channels.SelectableChannel> task, java.nio.channels.SelectionKey k, java.lang.Throwable cause)
protected void wakeup(boolean inEventLoop)
wakeup
in class SingleThreadEventExecutor
int selectNow() throws java.io.IOException
java.io.IOException
private void select(boolean oldWakenUp) throws java.io.IOException
java.io.IOException
private void selectAgain()