Home / Class/ ManualIoEventLoopRunner Class — netty Architecture

ManualIoEventLoopRunner Class — netty Architecture

Architecture documentation for the ManualIoEventLoopRunner class in ManualEventLoopTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  e61f0aaf_7cf5_2dea_972c_51997ee44af8["ManualIoEventLoopRunner"]
  225130a2_5093_d89c_ccad_1b5f3b519fae["ManualEventLoopTest.java"]
  e61f0aaf_7cf5_2dea_972c_51997ee44af8 -->|defined in| 225130a2_5093_d89c_ccad_1b5f3b519fae
  569fe781_e331_036b_7453_a3b8c5422375["ManualIoEventLoopRunner()"]
  e61f0aaf_7cf5_2dea_972c_51997ee44af8 -->|method| 569fe781_e331_036b_7453_a3b8c5422375
  0cd60ac9_8ee4_d40c_6ef2_249d540cc521["mainLoop()"]
  e61f0aaf_7cf5_2dea_972c_51997ee44af8 -->|method| 0cd60ac9_8ee4_d40c_6ef2_249d540cc521
  76348b11_722a_68f7_da94_18a9704b39b9["safeExecute()"]
  e61f0aaf_7cf5_2dea_972c_51997ee44af8 -->|method| 76348b11_722a_68f7_da94_18a9704b39b9
  d3622feb_d0a1_b069_819a_5203feae0519["execute()"]
  e61f0aaf_7cf5_2dea_972c_51997ee44af8 -->|method| d3622feb_d0a1_b069_819a_5203feae0519

Relationship Graph

Source Code

transport-native-epoll/src/test/java/io/netty/channel/epoll/ManualEventLoopTest.java lines 156–222

        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");
                    }
                }
                ioEventLoop.wakeup();
            }
        }

Frequently Asked Questions

What is the ManualIoEventLoopRunner class?
ManualIoEventLoopRunner is a class in the netty codebase, defined in transport-native-epoll/src/test/java/io/netty/channel/epoll/ManualEventLoopTest.java.
Where is ManualIoEventLoopRunner defined?
ManualIoEventLoopRunner is defined in transport-native-epoll/src/test/java/io/netty/channel/epoll/ManualEventLoopTest.java at line 156.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free