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.SingleThreadEventLoop.ChannelsReadOnlyIterator<T extends Channel>
SingleThreadEventExecutor.NonWakeupRunnable
AbstractEventExecutor.LazyRunnable
DEFAULT_MAX_PENDING_TASKS
限定符和类型 | 方法和说明 |
---|---|
protected boolean |
afterScheduledTaskSubmitted(long deadlineNanos)
|
protected boolean |
beforeScheduledTaskSubmitted(long deadlineNanos)
Called from arbitrary non-
EventExecutor threads prior to scheduled task submission. |
protected void |
cleanup()
Do nothing, sub-classes may override
|
int |
getIoRatio()
Returns the percentage of the desired amount of time spent for I/O in the event loop.
|
protected java.util.Queue<java.lang.Runnable> |
newTaskQueue(int maxPendingTasks)
Create a new
Queue which will holds the tasks to execute. |
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. |
int |
registeredChannels()
|
java.util.Iterator<Channel> |
registeredChannelsIterator() |
protected void |
run()
Run the tasks in the
SingleThreadEventExecutor.taskQueue |
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) |
afterRunningAllTasks, executeAfterEventLoopIteration, hasTasks, next, parent, pendingTasks, register, register, register
addShutdownHook, addTask, awaitTermination, confirmShutdown, deadlineNanos, delayNanos, execute, inEventLoop, interruptThread, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isShuttingDown, isTerminated, lazyExecute, newTaskQueue, peekTask, pollTask, pollTaskFrom, reject, reject, removeShutdownHook, removeTask, runAllTasks, runAllTasks, runAllTasksFrom, runScheduledAndExecutorTasks, shutdown, shutdownGracefully, takeTask, terminationFuture, threadProperties, updateLastExecutionTime, wakesUpForTask
cancelScheduledTasks, deadlineToDelayNanos, getCurrentTimeNanos, hasScheduledTasks, initialNanoTime, nanoTime, nextScheduledTaskDeadlineNanos, nextScheduledTaskNano, pollScheduledTask, pollScheduledTask, schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, validateScheduled
inEventLoop, iterator, newFailedFuture, newProgressivePromise, newPromise, newSucceededFuture, newTaskFor, newTaskFor, runTask, safeExecute, 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
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.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. The lower the number the more time can be spent on non-I/O tasks. If value set to
100
, this feature will be disabled and event loop will not attempt to balance I/O and 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.public int registeredChannels()
SingleThreadEventLoop
public java.util.Iterator<Channel> registeredChannelsIterator()
registeredChannelsIterator
在类中 SingleThreadEventLoop
Channel
s registered with this EventLoop
.
The returned value is not guaranteed to be exact accurate and
should be viewed as a best effort. This method is expected to be called from within
event loop.protected void run()
SingleThreadEventExecutor
SingleThreadEventExecutor.taskQueue
run
在类中 SingleThreadEventExecutor
protected void cleanup()
SingleThreadEventExecutor
cleanup
在类中 SingleThreadEventExecutor
protected void wakeup(boolean inEventLoop)
wakeup
在类中 SingleThreadEventExecutor
protected boolean beforeScheduledTaskSubmitted(long deadlineNanos)
AbstractScheduledEventExecutor
EventExecutor
threads prior to scheduled task submission.
Returns true
if the EventExecutor
thread should be woken immediately to
process the scheduled task (if not already awake).
If false
is returned, AbstractScheduledEventExecutor.afterScheduledTaskSubmitted(long)
will be called with
the same value after the scheduled task is enqueued, providing another opportunity
to wake the EventExecutor
thread if required.
beforeScheduledTaskSubmitted
在类中 AbstractScheduledEventExecutor
deadlineNanos
- deadline of the to-be-scheduled task
relative to AbstractScheduledEventExecutor.getCurrentTimeNanos()
true
if the EventExecutor
thread should be woken, false
otherwiseprotected boolean afterScheduledTaskSubmitted(long deadlineNanos)
AbstractScheduledEventExecutor
AbstractScheduledEventExecutor.beforeScheduledTaskSubmitted(long)
. Called only after that method returns false.afterScheduledTaskSubmitted
在类中 AbstractScheduledEventExecutor
deadlineNanos
- relative to AbstractScheduledEventExecutor.getCurrentTimeNanos()
true
if the EventExecutor
thread should be woken, false
otherwise