Top Description Inners Fields Constructors Methods
io.netty.channel.nio

public final Class NioEventLoop

extends SingleThreadEventLoop
Class Inheritance
Imports
io.netty.channel.Channel, .ChannelException, .EventLoop, .EventLoopException, .EventLoopTaskQueueFactory, .SelectStrategy, .SingleThreadEventLoop, io.netty.util.IntSupplier, io.netty.util.concurrent.RejectedExecutionHandler, io.netty.util.internal.ObjectUtil, .PlatformDependent, .ReflectionUtil, .SystemPropertyUtil, io.netty.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.io.IOException, java.lang.reflect.Field, java.nio.channels.CancelledKeyException, .SelectableChannel, .Selector, .SelectionKey, java.nio.channels.spi.SelectorProvider, java.security.AccessController, .PrivilegedAction, java.util.ArrayList, .Collection, .Iterator, .NoSuchElementException, .Queue, .Set, java.util.concurrent.Executor, java.util.concurrent.atomic.AtomicLong

SingleThreadEventLoop implementation which register the Channel's to a Selector and so does the multi-plexing of these in the event loop.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final long
private int
private static final int
private static final boolean
private volatile int
private static final InternalLogger
private static final int
private boolean
private final AtomicLong
private static final long
private final SelectorProvider
private SelectedSelectionKeySet
private final IntSupplier
private Selector
private static final int
private final SelectStrategy
private Selector
Inherited from io.netty.channel.SingleThreadEventLoop:
DEFAULT_MAX_PENDING_TASKS

Constructor Summary

AccessConstructor and Description
pack-priv
NioEventLoop(NioEventLoopGroup parent, Executor executor, SelectorProvider selectorProvider, SelectStrategy strategy, RejectedExecutionHandler rejectedExecutionHandler, EventLoopTaskQueueFactory taskQueueFactory, EventLoopTaskQueueFactory tailTaskQueueFactory)

Method Summary

Modifier and TypeMethod and Description
protected boolean
protected boolean
beforeScheduledTaskSubmitted(long
deadline of the to-be-scheduled task relative to AbstractScheduledEventExecutor#getCurrentTimeNanos()
deadlineNanos
)

Overrides io.netty.util.concurrent.AbstractScheduledEventExecutor.beforeScheduledTaskSubmitted.

Called from arbitrary non-EventExecutor threads prior to scheduled task submission.
pack-priv void
protected void
cleanup()

Overrides io.netty.util.concurrent.SingleThreadEventExecutor.cleanup.

Do nothing, sub-classes may override
private void
public int
getIoRatio()

Returns the percentage of the desired amount of time spent for I/O in the event loop.

private static void
private static void
private static Queue<Runnable>
protected Queue<Runnable>
newTaskQueue(int maxPendingTasks)

Overrides io.netty.util.concurrent.SingleThreadEventExecutor.newTaskQueue.

Create a new Queue which will holds the tasks to execute.
private static Queue<Runnable>
newTaskQueue0(int maxPendingTasks)

private NioEventLoop.SelectorTuple
private void
private static void
private void
private void
private void
public void
rebuildSelector()

Replaces the current Selector of this event loop with newly created Selectors to work around the infamous epoll 100% CPU bug.

private void
public void
register(final SelectableChannel ch, final int interestOps, final NioTask<?> task)

Registers an arbitrary SelectableChannel, not necessarily created by Netty, to the Selector of this event loop.

private void
register0(SelectableChannel ch, int interestOps, NioTask<?> task)

public int
registeredChannels()

Overrides io.netty.channel.SingleThreadEventLoop.registeredChannels.

Returns the number of Channels registered with this EventLoop or -1 if operation is not supported.
public Iterator<Channel>
protected void
run()

Implements abstract io.netty.util.concurrent.SingleThreadEventExecutor.run.

Run the tasks in the taskQueue
private int
select(long deadlineNanos)

private void
pack-priv int
public SelectorProvider
selectorProvider()

Returns the SelectorProvider used by this NioEventLoop to obtain the Selector.

public void
setIoRatio(int ioRatio)

Sets the percentage of the desired amount of time spent for I/O in the event loop.

private boolean
unexpectedSelectorWakeup(int selectCnt)

pack-priv Selector
protected void
Inherited from io.netty.channel.SingleThreadEventLoop:
afterRunningAllTasksexecuteAfterEventLoopIterationhasTasksnextparentpendingTasksregisterregisterregister

Field Detail

AWAKEback to summary
private static final long AWAKE
cancelledKeysback to summary
private int cancelledKeys
CLEANUP_INTERVALback to summary
private static final int CLEANUP_INTERVAL
DISABLE_KEY_SET_OPTIMIZATIONback to summary
private static final boolean DISABLE_KEY_SET_OPTIMIZATION
ioRatioback to summary
private volatile int ioRatio
loggerback to summary
private static final InternalLogger logger

Hides io.netty.util.concurrent.SingleThreadEventExecutor.logger.

MIN_PREMATURE_SELECTOR_RETURNSback to summary
private static final int MIN_PREMATURE_SELECTOR_RETURNS
needsToSelectAgainback to summary
private boolean needsToSelectAgain
nextWakeupNanosback to summary
private final AtomicLong nextWakeupNanos
NONEback to summary
private static final long NONE
providerback to summary
private final SelectorProvider provider
selectedKeysback to summary
private SelectedSelectionKeySet selectedKeys
selectNowSupplierback to summary
private final IntSupplier selectNowSupplier
selectorback to summary
private Selector selector

The NIO Selector.

SELECTOR_AUTO_REBUILD_THRESHOLDback to summary
private static final int SELECTOR_AUTO_REBUILD_THRESHOLD
selectStrategyback to summary
private final SelectStrategy selectStrategy
unwrappedSelectorback to summary
private Selector unwrappedSelector

Constructor Detail

NioEventLoopback to summary
pack-priv NioEventLoop(NioEventLoopGroup parent, Executor executor, SelectorProvider selectorProvider, SelectStrategy strategy, RejectedExecutionHandler rejectedExecutionHandler, EventLoopTaskQueueFactory taskQueueFactory, EventLoopTaskQueueFactory tailTaskQueueFactory)

Method Detail

afterScheduledTaskSubmittedback to summary
protected boolean afterScheduledTaskSubmitted(long deadlineNanos)

Overrides io.netty.util.concurrent.AbstractScheduledEventExecutor.afterScheduledTaskSubmitted.

Doc from io.netty.util.concurrent.AbstractScheduledEventExecutor.afterScheduledTaskSubmitted.

See beforeScheduledTaskSubmitted(long). Called only after that method returns false.

Parameters
deadlineNanos:long

relative to AbstractScheduledEventExecutor#getCurrentTimeNanos()

Returns:boolean

true if the EventExecutor thread should be woken, false otherwise

Annotations
@Override
beforeScheduledTaskSubmittedback to summary
protected boolean beforeScheduledTaskSubmitted(long deadlineNanos)

Overrides io.netty.util.concurrent.AbstractScheduledEventExecutor.beforeScheduledTaskSubmitted.

Doc from io.netty.util.concurrent.AbstractScheduledEventExecutor.beforeScheduledTaskSubmitted.

Called from arbitrary non-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, 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.

Parameters
deadlineNanos:long

deadline of the to-be-scheduled task relative to AbstractScheduledEventExecutor#getCurrentTimeNanos()

Returns:boolean

true if the EventExecutor thread should be woken, false otherwise

Annotations
@Override
cancelback to summary
pack-priv void cancel(SelectionKey key)
cleanupback to summary
protected void cleanup()

Overrides io.netty.util.concurrent.SingleThreadEventExecutor.cleanup.

Doc from io.netty.util.concurrent.SingleThreadEventExecutor.cleanup.

Do nothing, sub-classes may override

Annotations
@Override
closeAllback to summary
private void closeAll()
getIoRatioback to summary
public int getIoRatio()

Returns the percentage of the desired amount of time spent for I/O in the event loop.

handleLoopExceptionback to summary
private static void handleLoopException(Throwable t)
invokeChannelUnregisteredback to summary
private static void invokeChannelUnregistered(NioTask<SelectableChannel> task, SelectionKey k, Throwable cause)
newTaskQueueback to summary
private static Queue<Runnable> newTaskQueue(EventLoopTaskQueueFactory queueFactory)
newTaskQueueback to summary
protected Queue<Runnable> newTaskQueue(int maxPendingTasks)

Overrides io.netty.util.concurrent.SingleThreadEventExecutor.newTaskQueue.

Doc from io.netty.util.concurrent.SingleThreadEventExecutor.newTaskQueue.

Create a new 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.

Annotations
@Override
newTaskQueue0back to summary
private static Queue<Runnable> newTaskQueue0(int maxPendingTasks)
openSelectorback to summary
private NioEventLoop.SelectorTuple openSelector()
processSelectedKeyback to summary
private void processSelectedKey(SelectionKey k, AbstractNioChannel ch)
processSelectedKeyback to summary
private static void processSelectedKey(SelectionKey k, NioTask<SelectableChannel> task)
processSelectedKeysback to summary
private void processSelectedKeys()
processSelectedKeysOptimizedback to summary
private void processSelectedKeysOptimized()
processSelectedKeysPlainback to summary
private void processSelectedKeysPlain(Set<SelectionKey> selectedKeys)
rebuildSelectorback to summary
public void rebuildSelector()

Replaces the current Selector of this event loop with newly created Selectors to work around the infamous epoll 100% CPU bug.

rebuildSelector0back to summary
private void rebuildSelector0()
registerback to summary
public void register(final SelectableChannel ch, final int interestOps, final NioTask<?> task)

Registers an arbitrary 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.

register0back to summary
private void register0(SelectableChannel ch, int interestOps, NioTask<?> task)
registeredChannelsback to summary
public int registeredChannels()

Overrides io.netty.channel.SingleThreadEventLoop.registeredChannels.

Doc from io.netty.channel.SingleThreadEventLoop.registeredChannels.

Returns the number of Channels registered with this EventLoop or -1 if operation is not supported. The returned value is not guaranteed to be exact accurate and should be viewed as a best effort.

Annotations
@Override
registeredChannelsIteratorback to summary
public Iterator<Channel> registeredChannelsIterator()

Overrides io.netty.channel.SingleThreadEventLoop.registeredChannelsIterator.

Returns:Iterator<Channel>

Doc from io.netty.channel.SingleThreadEventLoop.registeredChannelsIterator.

read-only iterator of active Channels 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.

Annotations
@Override
runback to summary
protected void run()

Implements abstract io.netty.util.concurrent.SingleThreadEventExecutor.run.

Doc from io.netty.util.concurrent.SingleThreadEventExecutor.run.

Run the tasks in the taskQueue

Annotations
@Override
selectback to summary
private int select(long deadlineNanos) throws IOException
selectAgainback to summary
private void selectAgain()
selectNowback to summary
pack-priv int selectNow() throws IOException
selectorProviderback to summary
public SelectorProvider selectorProvider()

Returns the SelectorProvider used by this NioEventLoop to obtain the Selector.

setIoRatioback to summary
public void setIoRatio(int ioRatio)

Sets the percentage of the desired amount of time spent for I/O in the event loop. Value range from 1-100. The default value is 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.

unexpectedSelectorWakeupback to summary
private boolean unexpectedSelectorWakeup(int selectCnt)
unwrappedSelectorback to summary
pack-priv Selector unwrappedSelector()
wakeupback to summary
protected void wakeup(boolean inEventLoop)

Overrides io.netty.util.concurrent.SingleThreadEventExecutor.wakeup.

Annotations
@Override
io.netty.channel.nio back to summary

private final Class NioEventLoop.SelectorTuple

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final Selector
pack-priv final Selector

Constructor Summary

AccessConstructor and Description
pack-priv
SelectorTuple(Selector unwrappedSelector)

pack-priv
SelectorTuple(Selector unwrappedSelector, Selector selector)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

selectorback to summary
pack-priv final Selector selector
unwrappedSelectorback to summary
pack-priv final Selector unwrappedSelector

Constructor Detail

SelectorTupleback to summary
pack-priv SelectorTuple(Selector unwrappedSelector)
SelectorTupleback to summary
pack-priv SelectorTuple(Selector unwrappedSelector, Selector selector)