Home / Class/ NioIoHandler Class — netty Architecture

NioIoHandler Class — netty Architecture

Architecture documentation for the NioIoHandler class in NioIoHandler.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  db526e28_8aae_a182_b56b_dc12824d89f5["NioIoHandler"]
  2d4c619e_d0e7_ae1e_01cd_be0ede62fcff["NioIoHandler.java"]
  db526e28_8aae_a182_b56b_dc12824d89f5 -->|defined in| 2d4c619e_d0e7_ae1e_01cd_be0ede62fcff
  1fe26af5_5f33_63e3_463c_759a5b11bf13["NioIoHandler()"]
  db526e28_8aae_a182_b56b_dc12824d89f5 -->|method| 1fe26af5_5f33_63e3_463c_759a5b11bf13
  d43dc98f_6738_d8a6_e838_daf73bfcfdca["SelectorTuple()"]
  db526e28_8aae_a182_b56b_dc12824d89f5 -->|method| d43dc98f_6738_d8a6_e838_daf73bfcfdca
  475feb3b_c07e_8d6a_78ae_29eec2f1cc00["SelectorProvider()"]
  db526e28_8aae_a182_b56b_dc12824d89f5 -->|method| 475feb3b_c07e_8d6a_78ae_29eec2f1cc00
  91e9bee4_1b62_e088_9fb3_4b12427baefc["Selector()"]
  db526e28_8aae_a182_b56b_dc12824d89f5 -->|method| 91e9bee4_1b62_e088_9fb3_4b12427baefc
  ae37b325_68e5_9e90_c068_f26772ec2481["numRegistered()"]
  db526e28_8aae_a182_b56b_dc12824d89f5 -->|method| ae37b325_68e5_9e90_c068_f26772ec2481
  f27bdfc6_4eb0_65a5_41b2_aec72f84c1c2["registeredSet()"]
  db526e28_8aae_a182_b56b_dc12824d89f5 -->|method| f27bdfc6_4eb0_65a5_41b2_aec72f84c1c2
  0cde094c_1fde_4ca0_aa21_b607ebeae5b5["rebuildSelector0()"]
  db526e28_8aae_a182_b56b_dc12824d89f5 -->|method| 0cde094c_1fde_4ca0_aa21_b607ebeae5b5
  e9a9d9b5_5b44_37ef_926e_f9603c23831b["NioIoHandle()"]
  db526e28_8aae_a182_b56b_dc12824d89f5 -->|method| e9a9d9b5_5b44_37ef_926e_f9603c23831b
  41821303_3efa_21af_a764_702fd895fc53["NioIoOps()"]
  db526e28_8aae_a182_b56b_dc12824d89f5 -->|method| 41821303_3efa_21af_a764_702fd895fc53
  60fdcec8_2616_1645_9189_9d99251306f1["IoRegistration()"]
  db526e28_8aae_a182_b56b_dc12824d89f5 -->|method| 60fdcec8_2616_1645_9189_9d99251306f1
  bfebd9e6_05a3_0eea_3b0f_b34d5870ab36["run()"]
  db526e28_8aae_a182_b56b_dc12824d89f5 -->|method| bfebd9e6_05a3_0eea_3b0f_b34d5870ab36
  7006124b_c1a3_1e03_afbd_e97032ecd2dd["handleLoopException()"]
  db526e28_8aae_a182_b56b_dc12824d89f5 -->|method| 7006124b_c1a3_1e03_afbd_e97032ecd2dd
  bb59a7a2_77ef_52ff_0c57_820c55b1ec5b["processSelectedKeys()"]
  db526e28_8aae_a182_b56b_dc12824d89f5 -->|method| bb59a7a2_77ef_52ff_0c57_820c55b1ec5b

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/nio/NioIoHandler.java lines 57–813

public final class NioIoHandler implements IoHandler {

    private static final InternalLogger logger = InternalLoggerFactory.getInstance(NioIoHandler.class);

    private static final int CLEANUP_INTERVAL = 256; // XXX Hard-coded value, but won't need customization.

    private static final boolean DISABLE_KEY_SET_OPTIMIZATION =
            SystemPropertyUtil.getBoolean("io.netty.noKeySetOptimization", false);

    private static final int MIN_PREMATURE_SELECTOR_RETURNS = 3;
    private static final int SELECTOR_AUTO_REBUILD_THRESHOLD;

    private final IntSupplier selectNowSupplier = new IntSupplier() {
        @Override
        public int get() throws Exception {
            return selectNow();
        }
    };

    // Workaround for JDK NIO bug.
    //
    // See:
    // - https://bugs.openjdk.java.net/browse/JDK-6427854 for first few dev (unreleased) builds of JDK 7
    // - https://bugs.openjdk.java.net/browse/JDK-6527572 for JDK prior to 5.0u15-rev and 6u10
    // - https://github.com/netty/netty/issues/203
    static {
        int selectorAutoRebuildThreshold = SystemPropertyUtil.getInt("io.netty.selectorAutoRebuildThreshold", 512);
        if (selectorAutoRebuildThreshold < MIN_PREMATURE_SELECTOR_RETURNS) {
            selectorAutoRebuildThreshold = 0;
        }

        SELECTOR_AUTO_REBUILD_THRESHOLD = selectorAutoRebuildThreshold;

        if (logger.isDebugEnabled()) {
            logger.debug("-Dio.netty.noKeySetOptimization: {}", DISABLE_KEY_SET_OPTIMIZATION);
            logger.debug("-Dio.netty.selectorAutoRebuildThreshold: {}", SELECTOR_AUTO_REBUILD_THRESHOLD);
        }
    }

    /**
     * The NIO {@link Selector}.
     */
    private Selector selector;
    private Selector unwrappedSelector;
    private SelectedSelectionKeySet selectedKeys;

    private final SelectorProvider provider;

    /**
     * Boolean that controls determines if a blocked Selector.select should
     * break out of its selection process. In our case we use a timeout for
     * the select method and the select method will block for that time unless
     * waken up.
     */
    private final AtomicBoolean wakenUp = new AtomicBoolean();

    private final SelectStrategy selectStrategy;
    private final ThreadAwareExecutor executor;
    private int cancelledKeys;
    private boolean needsToSelectAgain;

    private NioIoHandler(ThreadAwareExecutor executor, SelectorProvider selectorProvider,
                         SelectStrategy strategy) {
        this.executor = ObjectUtil.checkNotNull(executor, "executionContext");
        this.provider = ObjectUtil.checkNotNull(selectorProvider, "selectorProvider");
        this.selectStrategy = ObjectUtil.checkNotNull(strategy, "selectStrategy");
        final SelectorTuple selectorTuple = openSelector();
        this.selector = selectorTuple.selector;
        this.unwrappedSelector = selectorTuple.unwrappedSelector;
    }

    private static final class SelectorTuple {
        final Selector unwrappedSelector;
        final Selector selector;

        SelectorTuple(Selector unwrappedSelector) {
            this.unwrappedSelector = unwrappedSelector;
            this.selector = unwrappedSelector;
        }

        SelectorTuple(Selector unwrappedSelector, Selector selector) {

Frequently Asked Questions

What is the NioIoHandler class?
NioIoHandler is a class in the netty codebase, defined in transport/src/main/java/io/netty/channel/nio/NioIoHandler.java.
Where is NioIoHandler defined?
NioIoHandler is defined in transport/src/main/java/io/netty/channel/nio/NioIoHandler.java at line 57.

Analyze Your Own Codebase

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

Try Supermodel Free