Home / Class/ DefaultNioRegistration Class — netty Architecture

DefaultNioRegistration Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  c6073e28_17d5_4721_0af6_5408fdac51c7["DefaultNioRegistration"]
  2d4c619e_d0e7_ae1e_01cd_be0ede62fcff["NioIoHandler.java"]
  c6073e28_17d5_4721_0af6_5408fdac51c7 -->|defined in| 2d4c619e_d0e7_ae1e_01cd_be0ede62fcff
  96dde752_a78e_83fa_711c_f2457b04b981["DefaultNioRegistration()"]
  c6073e28_17d5_4721_0af6_5408fdac51c7 -->|method| 96dde752_a78e_83fa_711c_f2457b04b981
  81658107_0f7f_08d8_d895_227dac2dc581["NioIoHandle()"]
  c6073e28_17d5_4721_0af6_5408fdac51c7 -->|method| 81658107_0f7f_08d8_d895_227dac2dc581
  56dd9bc9_ce9b_0c5c_2e5c_47ecf95d0f0a["register()"]
  c6073e28_17d5_4721_0af6_5408fdac51c7 -->|method| 56dd9bc9_ce9b_0c5c_2e5c_47ecf95d0f0a
  d8af7763_2ed1_67c5_4a82_024ebdb0f128["T()"]
  c6073e28_17d5_4721_0af6_5408fdac51c7 -->|method| d8af7763_2ed1_67c5_4a82_024ebdb0f128
  ef8255b9_2b69_3cc8_b9f4_09f59f321f26["isValid()"]
  c6073e28_17d5_4721_0af6_5408fdac51c7 -->|method| ef8255b9_2b69_3cc8_b9f4_09f59f321f26
  c0885bd9_fe2e_eec9_0856_fd56da15c7cf["submit()"]
  c6073e28_17d5_4721_0af6_5408fdac51c7 -->|method| c0885bd9_fe2e_eec9_0856_fd56da15c7cf
  ecdfe176_a66d_99e6_189e_28d99cc27fe0["cancel()"]
  c6073e28_17d5_4721_0af6_5408fdac51c7 -->|method| ecdfe176_a66d_99e6_189e_28d99cc27fe0
  b2d60452_c9f9_89ec_0be0_2d281d72f3a4["close()"]
  c6073e28_17d5_4721_0af6_5408fdac51c7 -->|method| b2d60452_c9f9_89ec_0be0_2d281d72f3a4
  5fe8a1db_0ebd_9490_dba5_1e6fdafec1c6["handle()"]
  c6073e28_17d5_4721_0af6_5408fdac51c7 -->|method| 5fe8a1db_0ebd_9490_dba5_1e6fdafec1c6

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/nio/NioIoHandler.java lines 318–390

    final class DefaultNioRegistration implements IoRegistration {
        private final AtomicBoolean canceled = new AtomicBoolean();
        private final NioIoHandle handle;
        private volatile SelectionKey key;

        DefaultNioRegistration(ThreadAwareExecutor executor, NioIoHandle handle, NioIoOps initialOps, Selector selector)
                throws IOException {
            this.handle = handle;
            key = handle.selectableChannel().register(selector, initialOps.value, this);
        }

        NioIoHandle handle() {
            return handle;
        }

        void register(Selector selector) throws IOException {
            SelectionKey newKey = handle.selectableChannel().register(selector, key.interestOps(), this);
            key.cancel();
            key = newKey;
        }

        @SuppressWarnings("unchecked")
        @Override
        public <T> T attachment() {
            return (T) key;
        }

        @Override
        public boolean isValid() {
            return !canceled.get() && key.isValid();
        }

        @Override
        public long submit(IoOps ops) {
            if (!isValid()) {
                return -1;
            }
            int v = cast(ops).value;
            key.interestOps(v);
            return v;
        }

        @Override
        public boolean cancel() {
            if (!canceled.compareAndSet(false, true)) {
                return false;
            }
            key.cancel();
            cancelledKeys++;
            if (cancelledKeys >= CLEANUP_INTERVAL) {
                cancelledKeys = 0;
                needsToSelectAgain = true;
            }
            handle.unregistered();
            return true;
        }

        void close() {
            cancel();
            try {
                handle.close();
            } catch (Exception e) {
                logger.debug("Exception during closing " + handle, e);
            }
        }

        void handle(int ready) {
            if (!isValid()) {
                return;
            }
            handle.handle(this, NioIoOps.eventOf(ready));
        }
    }

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free