ManualMultithreadedIoEventLoopGroup Class — netty Architecture
Architecture documentation for the ManualMultithreadedIoEventLoopGroup class in ManualEventLoopTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 7c0a5f4a_fdb0_ec41_f09f_6bfc891da25c["ManualMultithreadedIoEventLoopGroup"] 225130a2_5093_d89c_ccad_1b5f3b519fae["ManualEventLoopTest.java"] 7c0a5f4a_fdb0_ec41_f09f_6bfc891da25c -->|defined in| 225130a2_5093_d89c_ccad_1b5f3b519fae a00476b1_7dfb_d468_f53a_dbba89da2249["ManualMultithreadedIoEventLoopGroup()"] 7c0a5f4a_fdb0_ec41_f09f_6bfc891da25c -->|method| a00476b1_7dfb_d468_f53a_dbba89da2249 65b772a9_71aa_aea5_5a11_9c5cf53a49df["IoEventLoop()"] 7c0a5f4a_fdb0_ec41_f09f_6bfc891da25c -->|method| 65b772a9_71aa_aea5_5a11_9c5cf53a49df ee4df638_05ee_494c_0499_c03ca51b00e5["beforeCanBlock()"] 7c0a5f4a_fdb0_ec41_f09f_6bfc891da25c -->|method| ee4df638_05ee_494c_0499_c03ca51b00e5
Relationship Graph
Source Code
transport-native-epoll/src/test/java/io/netty/channel/epoll/ManualEventLoopTest.java lines 137–223
public static class ManualMultithreadedIoEventLoopGroup extends MultiThreadIoEventLoopGroup {
private ManualIoEventLoopRunner ioEventLoopRunner;
private Consumer<ManualIoEventLoopRunner> beforeCanBlock;
public ManualMultithreadedIoEventLoopGroup(IoHandlerFactory ioHandlerFactory) {
super(1, ioHandlerFactory);
}
@Override
protected IoEventLoop newChild(Executor executor, IoHandlerFactory ioHandlerFactory, Object... args) {
this.ioEventLoopRunner = new ManualIoEventLoopRunner(this, ioHandlerFactory,
executor, this::beforeCanBlock);
return ioEventLoopRunner.ioEventLoop;
}
protected void beforeCanBlock(Executor executor) {
}
private static class ManualIoEventLoopRunner implements Executor {
private final ManualIoEventLoop ioEventLoop;
private final Queue<Runnable> otherTasks = new ConcurrentLinkedQueue<>();
ManualIoEventLoopRunner(IoEventLoopGroup parent, IoHandlerFactory factory,
Executor executor, Consumer<Executor> beforeCanBlock) {
this.ioEventLoop = new ManualIoEventLoop(parent, null, factory) {
@Override
protected boolean canBlock() {
if (beforeCanBlock != null) {
beforeCanBlock.accept(ManualIoEventLoopRunner.this);
}
return otherTasks.isEmpty();
}
};
CountDownLatch started = new CountDownLatch(1);
executor.execute(() -> {
ioEventLoop.setOwningThread(Thread.currentThread());
// it would force a first init
ioEventLoop.runNow();
started.countDown();
mainLoop();
});
try {
started.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}
private void mainLoop() {
while (!ioEventLoop.isShuttingDown()) {
ioEventLoop.run(0);
Runnable otherTask = otherTasks.poll();
if (otherTask != null) {
safeExecute(otherTask);
}
}
while (!ioEventLoop.isTerminated() || !otherTasks.isEmpty()) {
ioEventLoop.runNow();
Runnable otherTask = otherTasks.poll();
if (otherTask != null) {
safeExecute(otherTask);
}
}
}
private void safeExecute(Runnable task) {
try {
task.run();
} catch (Throwable ignore) {
//
}
}
public void execute(Runnable otherTask) {
otherTasks.add(otherTask);
if (ioEventLoop.isShutdown()) {
if (otherTasks.remove(otherTask)) {
throw new RejectedExecutionException("Event loop shut down");
Source
Frequently Asked Questions
What is the ManualMultithreadedIoEventLoopGroup class?
ManualMultithreadedIoEventLoopGroup is a class in the netty codebase, defined in transport-native-epoll/src/test/java/io/netty/channel/epoll/ManualEventLoopTest.java.
Where is ManualMultithreadedIoEventLoopGroup defined?
ManualMultithreadedIoEventLoopGroup is defined in transport-native-epoll/src/test/java/io/netty/channel/epoll/ManualEventLoopTest.java at line 137.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free