Home / Function/ run() — netty Function Reference

run() — netty Function Reference

Architecture documentation for the run() function in EpollIoHandler.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  243595e7_7d39_0bf2_9688_f649d92dd080["run()"]
  e531fecb_b495_8b97_8d1b_49ff2b5ccdbb["EpollIoHandler"]
  243595e7_7d39_0bf2_9688_f649d92dd080 -->|defined in| e531fecb_b495_8b97_8d1b_49ff2b5ccdbb
  4aa9de2f_f867_a7f5_9506_2614f2af30b4["epollBusyWait()"]
  243595e7_7d39_0bf2_9688_f649d92dd080 -->|calls| 4aa9de2f_f867_a7f5_9506_2614f2af30b4
  5ac1ec81_fd61_e81b_dbef_8f44b4fadfb7["epollWaitTimeboxed()"]
  243595e7_7d39_0bf2_9688_f649d92dd080 -->|calls| 5ac1ec81_fd61_e81b_dbef_8f44b4fadfb7
  3d9ab7a8_4acc_8749_739f_f379b1c97919["epollWaitNoTimerChange()"]
  243595e7_7d39_0bf2_9688_f649d92dd080 -->|calls| 3d9ab7a8_4acc_8749_739f_f379b1c97919
  df22a564_5fd0_ed67_ef54_504075dee5df["epollWait()"]
  243595e7_7d39_0bf2_9688_f649d92dd080 -->|calls| df22a564_5fd0_ed67_ef54_504075dee5df
  4e253f99_0b70_4990_9891_90c4147a53a9["wakeup()"]
  243595e7_7d39_0bf2_9688_f649d92dd080 -->|calls| 4e253f99_0b70_4990_9891_90c4147a53a9
  5ba14c5c_ef39_cdce_457c_9129f8d99762["processReady()"]
  243595e7_7d39_0bf2_9688_f649d92dd080 -->|calls| 5ba14c5c_ef39_cdce_457c_9129f8d99762
  6a4e5217_6a46_08ca_6276_ed11e222423e["handleLoopException()"]
  243595e7_7d39_0bf2_9688_f649d92dd080 -->|calls| 6a4e5217_6a46_08ca_6276_ed11e222423e
  style 243595e7_7d39_0bf2_9688_f649d92dd080 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport-classes-epoll/src/main/java/io/netty/channel/epoll/EpollIoHandler.java lines 393–484

    @Override
    public int run(IoHandlerContext context) {
        int handled = 0;
        try {
            int strategy = selectStrategy.calculateStrategy(selectNowSupplier, !context.canBlock());
            switch (strategy) {
                case SelectStrategy.CONTINUE:
                    if (context.shouldReportActiveIoTime()) {
                        context.reportActiveIoTime(0); // Report zero as we did no I/O.
                    }
                    return 0;

                case SelectStrategy.BUSY_WAIT:
                    strategy = epollBusyWait();
                    break;

                case SelectStrategy.SELECT:
                    if (pendingWakeup) {
                        // We are going to be immediately woken so no need to reset wakenUp
                        // or check for timerfd adjustment.
                        strategy = epollWaitTimeboxed();
                        if (strategy != 0) {
                            break;
                        }
                        // We timed out so assume that we missed the write event due to an
                        // abnormally failed syscall (the write itself or a prior epoll_wait)
                        logger.warn("Missed eventfd write (not seen after > 1 second)");
                        pendingWakeup = false;
                        if (!context.canBlock()) {
                            break;
                        }
                        // fall-through
                    }

                    long curDeadlineNanos = context.deadlineNanos();
                    if (curDeadlineNanos == -1L) {
                        curDeadlineNanos = NONE; // nothing on the calendar
                    }
                    nextWakeupNanos.set(curDeadlineNanos);
                    try {
                        if (context.canBlock()) {
                            if (curDeadlineNanos == prevDeadlineNanos) {
                                // No timer activity needed
                                strategy = epollWaitNoTimerChange();
                            } else {
                                // Timerfd needs to be re-armed or disarmed
                                long result = epollWait(context, curDeadlineNanos);
                                // The result contains the actual return value and if a timer was used or not.
                                // We need to "unpack" using the helper methods exposed in Native.
                                strategy = Native.epollReady(result);
                                prevDeadlineNanos = Native.epollTimerWasUsed(result) ? curDeadlineNanos : NONE;
                            }
                        }
                    } finally {
                        // Try get() first to avoid much more expensive CAS in the case we
                        // were woken via the wakeup() method (submitted task)
                        if (nextWakeupNanos.get() == AWAKE || nextWakeupNanos.getAndSet(AWAKE) == AWAKE) {
                            pendingWakeup = true;
                        }
                    }
                    // fallthrough
                default:
            }
            if (strategy > 0) {
                handled = strategy;
                if (context.shouldReportActiveIoTime()) {
                    long activeIoStartTimeNanos = System.nanoTime();
                    if (processReady(events, strategy)) {
                        prevDeadlineNanos = NONE;
                    }
                    long activeIoEndTimeNanos = System.nanoTime();
                    context.reportActiveIoTime(activeIoEndTimeNanos - activeIoStartTimeNanos);
                } else {
                    if (processReady(events, strategy)) {
                        prevDeadlineNanos = NONE;
                    }
                }
            } else if (context.shouldReportActiveIoTime()) {
                context.reportActiveIoTime(0);
            }

Domain

Subdomains

Frequently Asked Questions

What does run() do?
run() is a function in the netty codebase, defined in transport-classes-epoll/src/main/java/io/netty/channel/epoll/EpollIoHandler.java.
Where is run() defined?
run() is defined in transport-classes-epoll/src/main/java/io/netty/channel/epoll/EpollIoHandler.java at line 393.
What does run() call?
run() calls 7 function(s): epollBusyWait, epollWait, epollWaitNoTimerChange, epollWaitTimeboxed, handleLoopException, processReady, wakeup.

Analyze Your Own Codebase

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

Try Supermodel Free