NioEventLoop Class — netty Architecture
Architecture documentation for the NioEventLoop class in NioEventLoop.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD b837b976_90bd_d303_000d_805c26e1d843["NioEventLoop"] 58e82f83_12e8_b44f_2d4a_a134b9b32e94["NioEventLoop.java"] b837b976_90bd_d303_000d_805c26e1d843 -->|defined in| 58e82f83_12e8_b44f_2d4a_a134b9b32e94 5b1e62bf_27dd_ecfc_dc96_9e9aee66afba["NioEventLoop()"] b837b976_90bd_d303_000d_805c26e1d843 -->|method| 5b1e62bf_27dd_ecfc_dc96_9e9aee66afba 69c6d151_c104_3c34_03f5_5a41a49f7b0d["newTaskQueue()"] b837b976_90bd_d303_000d_805c26e1d843 -->|method| 69c6d151_c104_3c34_03f5_5a41a49f7b0d 33973135_5050_073f_ef5e_beb0a9b3c82b["SelectorProvider()"] b837b976_90bd_d303_000d_805c26e1d843 -->|method| 33973135_5050_073f_ef5e_beb0a9b3c82b 11a1944a_feaf_3e61_83a4_e456bb347439["register()"] b837b976_90bd_d303_000d_805c26e1d843 -->|method| 11a1944a_feaf_3e61_83a4_e456bb347439 4733bb3b_c917_0869_d029_8f8cfcc03b71["register0()"] b837b976_90bd_d303_000d_805c26e1d843 -->|method| 4733bb3b_c917_0869_d029_8f8cfcc03b71 cc7ee19e_e630_b23e_cf00_1266a42191c6["getIoRatio()"] b837b976_90bd_d303_000d_805c26e1d843 -->|method| cc7ee19e_e630_b23e_cf00_1266a42191c6 057afa1d_0672_a1b7_bf49_eab6ba7389fa["setIoRatio()"] b837b976_90bd_d303_000d_805c26e1d843 -->|method| 057afa1d_0672_a1b7_bf49_eab6ba7389fa 8d255f95_1878_3ee8_2eb7_42b7b7cbdc09["rebuildSelector()"] b837b976_90bd_d303_000d_805c26e1d843 -->|method| 8d255f95_1878_3ee8_2eb7_42b7b7cbdc09 1f50beb4_dec5_d5bf_6f44_0e83d087823d["registeredChannels()"] b837b976_90bd_d303_000d_805c26e1d843 -->|method| 1f50beb4_dec5_d5bf_6f44_0e83d087823d 26e0baf5_c575_6164_08df_e160edaebda6["registeredChannelsIterator()"] b837b976_90bd_d303_000d_805c26e1d843 -->|method| 26e0baf5_c575_6164_08df_e160edaebda6 d4fe6afc_4ba9_58fa_f555_382366c99f8c["Selector()"] b837b976_90bd_d303_000d_805c26e1d843 -->|method| d4fe6afc_4ba9_58fa_f555_382366c99f8c
Relationship Graph
Source Code
transport/src/main/java/io/netty/channel/nio/NioEventLoop.java lines 44–250
@Deprecated
public final class NioEventLoop extends SingleThreadIoEventLoop {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(NioEventLoop.class);
NioEventLoop(NioEventLoopGroup parent, Executor executor, IoHandlerFactory ioHandlerFactory,
EventLoopTaskQueueFactory taskQueueFactory,
EventLoopTaskQueueFactory tailTaskQueueFactory, RejectedExecutionHandler rejectedExecutionHandler) {
super(parent, executor, ioHandlerFactory, newTaskQueue(taskQueueFactory), newTaskQueue(tailTaskQueueFactory),
rejectedExecutionHandler);
}
private static Queue<Runnable> newTaskQueue(
EventLoopTaskQueueFactory queueFactory) {
if (queueFactory == null) {
return newTaskQueue0(DEFAULT_MAX_PENDING_TASKS);
}
return queueFactory.newTaskQueue(DEFAULT_MAX_PENDING_TASKS);
}
/**
* Returns the {@link SelectorProvider} used by this {@link NioEventLoop} to obtain the {@link Selector}.
*/
public SelectorProvider selectorProvider() {
return ((NioIoHandler) ioHandler()).selectorProvider();
}
/**
* Registers an arbitrary {@link SelectableChannel}, not necessarily created by Netty, to the {@link Selector}
* of this event loop. Once the specified {@link SelectableChannel} is registered, the specified {@code task} will
* be executed by this event loop when the {@link SelectableChannel} is ready.
*/
public void register(final SelectableChannel ch, final int interestOps, final NioTask<?> task) {
ObjectUtil.checkNotNull(ch, "ch");
if (interestOps == 0) {
throw new IllegalArgumentException("interestOps must be non-zero.");
}
if ((interestOps & ~ch.validOps()) != 0) {
throw new IllegalArgumentException(
"invalid interestOps: " + interestOps + "(validOps: " + ch.validOps() + ')');
}
ObjectUtil.checkNotNull(task, "task");
if (isShutdown()) {
throw new IllegalStateException("event loop shut down");
}
@SuppressWarnings("unchecked")
final NioTask<SelectableChannel> nioTask = (NioTask<SelectableChannel>) task;
if (inEventLoop()) {
register0(ch, interestOps, nioTask);
} else {
try {
// Offload to the EventLoop as otherwise java.nio.channels.spi.AbstractSelectableChannel.register
// may block for a long time while trying to obtain an internal lock that may be hold while selecting.
submit(new Runnable() {
@Override
public void run() {
register0(ch, interestOps, nioTask);
}
}).sync();
} catch (InterruptedException ignore) {
// Even if interrupted we did schedule it so just mark the Thread as interrupted.
Thread.currentThread().interrupt();
}
}
}
private void register0(final SelectableChannel ch, int interestOps, final NioTask<SelectableChannel> task) {
try {
IoRegistration registration = register(
new NioSelectableChannelIoHandle<SelectableChannel>(ch) {
@Override
protected void handle(SelectableChannel channel, SelectionKey key) {
try {
task.channelReady(channel, key);
} catch (Exception e) {
logger.warn("Unexpected exception while running NioTask.channelReady(...)", e);
}
}
Source
Frequently Asked Questions
What is the NioEventLoop class?
NioEventLoop is a class in the netty codebase, defined in transport/src/main/java/io/netty/channel/nio/NioEventLoop.java.
Where is NioEventLoop defined?
NioEventLoop is defined in transport/src/main/java/io/netty/channel/nio/NioEventLoop.java at line 44.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free