Home / Function/ registeredChannelsIterator() — netty Function Reference

registeredChannelsIterator() — netty Function Reference

Architecture documentation for the registeredChannelsIterator() function in NioEventLoop.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  26e0baf5_c575_6164_08df_e160edaebda6["registeredChannelsIterator()"]
  b837b976_90bd_d303_000d_805c26e1d843["NioEventLoop"]
  26e0baf5_c575_6164_08df_e160edaebda6 -->|defined in| b837b976_90bd_d303_000d_805c26e1d843
  style 26e0baf5_c575_6164_08df_e160edaebda6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport/src/main/java/io/netty/channel/nio/NioEventLoop.java lines 179–245

    @Override
    public Iterator<Channel> registeredChannelsIterator() {
        assert inEventLoop();
        final Set<SelectionKey> keys =  ((NioIoHandler) ioHandler()).registeredSet();
        if (keys.isEmpty()) {
            return ChannelsReadOnlyIterator.empty();
        }
        return new Iterator<Channel>() {
            final Iterator<SelectionKey> selectionKeyIterator =
                    ObjectUtil.checkNotNull(keys, "selectionKeys")
                            .iterator();
            Channel next;
            boolean isDone;

            @Override
            public boolean hasNext() {
                if (isDone) {
                    return false;
                }
                Channel cur = next;
                if (cur == null) {
                    cur = next = nextOrDone();
                    return cur != null;
                }
                return true;
            }

            @Override
            public Channel next() {
                if (isDone) {
                    throw new NoSuchElementException();
                }
                Channel cur = next;
                if (cur == null) {
                    cur = nextOrDone();
                    if (cur == null) {
                        throw new NoSuchElementException();
                    }
                }
                next = nextOrDone();
                return cur;
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException("remove");
            }

            private Channel nextOrDone() {
                Iterator<SelectionKey> it = selectionKeyIterator;
                while (it.hasNext()) {
                    SelectionKey key = it.next();
                    if (key.isValid()) {
                        Object attachment = key.attachment();
                        if (attachment instanceof NioIoHandler.DefaultNioRegistration) {
                            NioIoHandle handle =  ((NioIoHandler.DefaultNioRegistration) attachment).handle();
                            if (handle instanceof AbstractNioChannel.AbstractNioUnsafe) {
                                return ((AbstractNioChannel.AbstractNioUnsafe) handle).channel();
                            }
                        }
                    }
                }
                isDone = true;
                return null;
            }
        };
    }

Domain

Subdomains

Frequently Asked Questions

What does registeredChannelsIterator() do?
registeredChannelsIterator() is a function in the netty codebase, defined in transport/src/main/java/io/netty/channel/nio/NioEventLoop.java.
Where is registeredChannelsIterator() defined?
registeredChannelsIterator() is defined in transport/src/main/java/io/netty/channel/nio/NioEventLoop.java at line 179.

Analyze Your Own Codebase

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

Try Supermodel Free