Class NioEventLoop

    • Field Detail

      • DISABLE_KEY_SET_OPTIMIZATION

        private static final boolean DISABLE_KEY_SET_OPTIMIZATION
      • MIN_PREMATURE_SELECTOR_RETURNS

        private static final int MIN_PREMATURE_SELECTOR_RETURNS
        See Also:
        Constant Field Values
      • SELECTOR_AUTO_REBUILD_THRESHOLD

        private static final int SELECTOR_AUTO_REBUILD_THRESHOLD
      • selectNowSupplier

        private final IntSupplier selectNowSupplier
      • selector

        private java.nio.channels.Selector selector
        The NIO Selector.
      • unwrappedSelector

        private java.nio.channels.Selector unwrappedSelector
      • provider

        private final java.nio.channels.spi.SelectorProvider provider
      • nextWakeupNanos

        private final java.util.concurrent.atomic.AtomicLong nextWakeupNanos
      • ioRatio

        private volatile int ioRatio
      • cancelledKeys

        private int cancelledKeys
      • needsToSelectAgain

        private boolean needsToSelectAgain
    • Method Detail

      • selectorProvider

        public java.nio.channels.spi.SelectorProvider selectorProvider()
        Returns the SelectorProvider used by this NioEventLoop to obtain the Selector.
      • newTaskQueue

        protected java.util.Queue<java.lang.Runnable> newTaskQueue​(int maxPendingTasks)
        Description copied from class: SingleThreadEventExecutor
        Create a new Queue which will holds the tasks to execute. This default implementation will return a LinkedBlockingQueue but if your sub-class of SingleThreadEventExecutor will not do any blocking calls on the this Queue it may make sense to @Override this and return some more performant implementation that does not support blocking operations at all.
        Overrides:
        newTaskQueue in class SingleThreadEventExecutor
      • newTaskQueue0

        private static java.util.Queue<java.lang.Runnable> newTaskQueue0​(int maxPendingTasks)
      • register

        public void register​(java.nio.channels.SelectableChannel ch,
                             int interestOps,
                             NioTask<?> task)
        Registers an arbitrary SelectableChannel, not necessarily created by Netty, to the Selector of this event loop. Once the specified SelectableChannel is registered, the specified task will be executed by this event loop when the SelectableChannel is ready.
      • register0

        private void register0​(java.nio.channels.SelectableChannel ch,
                               int interestOps,
                               NioTask<?> task)
      • getIoRatio

        public int getIoRatio()
        Returns the percentage of the desired amount of time spent for I/O in the event loop.
      • setIoRatio

        public void setIoRatio​(int ioRatio)
        Sets the percentage of the desired amount of time spent for I/O in the event loop. Value range from 1-100. The default value is 50, which means the event loop will try to spend the same amount of time for I/O as for non-I/O tasks. The lower the number the more time can be spent on non-I/O tasks. If value set to 100, this feature will be disabled and event loop will not attempt to balance I/O and non-I/O tasks.
      • rebuildSelector

        public void rebuildSelector()
        Replaces the current Selector of this event loop with newly created Selectors to work around the infamous epoll 100% CPU bug.
      • registeredChannelsIterator

        public java.util.Iterator<Channel> registeredChannelsIterator()
        Overrides:
        registeredChannelsIterator in class SingleThreadEventLoop
        Returns:
        read-only iterator of active Channels registered with this EventLoop. The returned value is not guaranteed to be exact accurate and should be viewed as a best effort. This method is expected to be called from within event loop.
      • rebuildSelector0

        private void rebuildSelector0()
      • selectReturnPrematurely

        private boolean selectReturnPrematurely​(int selectCnt,
                                                boolean ranTasks,
                                                int strategy)
      • unexpectedSelectorWakeup

        private boolean unexpectedSelectorWakeup​(int selectCnt)
      • handleLoopException

        private static void handleLoopException​(java.lang.Throwable t)
      • processSelectedKeys

        private void processSelectedKeys()
      • cancel

        void cancel​(java.nio.channels.SelectionKey key)
      • processSelectedKeysPlain

        private void processSelectedKeysPlain​(java.util.Set<java.nio.channels.SelectionKey> selectedKeys)
      • processSelectedKeysOptimized

        private void processSelectedKeysOptimized()
      • processSelectedKey

        private void processSelectedKey​(java.nio.channels.SelectionKey k,
                                        AbstractNioChannel ch)
      • processSelectedKey

        private static void processSelectedKey​(java.nio.channels.SelectionKey k,
                                               NioTask<java.nio.channels.SelectableChannel> task)
      • closeAll

        private void closeAll()
      • invokeChannelUnregistered

        private static void invokeChannelUnregistered​(NioTask<java.nio.channels.SelectableChannel> task,
                                                      java.nio.channels.SelectionKey k,
                                                      java.lang.Throwable cause)
      • unwrappedSelector

        java.nio.channels.Selector unwrappedSelector()
      • selectNow

        int selectNow()
               throws java.io.IOException
        Throws:
        java.io.IOException
      • select

        private int select​(long deadlineNanos)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • selectAgain

        private void selectAgain()