NettyUtils (Apache ZooKeeper - Server 3.7.0 API)
Date: 2021-03-17

org.apache.zookeeper.common

## Class NettyUtils

- java.lang.Object
- - org.apache.zookeeper.common.NettyUtils

-     public class NettyUtils
      extends Object

  Helper methods for netty code.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `NettyUtils()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static int` | `getClientReachableLocalInetAddressCount()` Attempts to detect and return the number of local network addresses that could be used by a client to reach this server.
    `static io.netty.channel.EventLoopGroup` | `newNioOrEpollEventLoopGroup()` If `Epoll.isAvailable()` `== true`, returns a new `EpollEventLoopGroup`, otherwise returns a new `NioEventLoopGroup`.
    `static io.netty.channel.EventLoopGroup` | `newNioOrEpollEventLoopGroup(int nThreads)` If `Epoll.isAvailable()` `== true`, returns a new `EpollEventLoopGroup`, otherwise returns a new `NioEventLoopGroup`.
    `static Class<? extends io.netty.channel.socket.ServerSocketChannel>` | `nioOrEpollServerSocketChannel()` If `Epoll.isAvailable()` `== true`, returns `EpollServerSocketChannel`, otherwise returns `NioServerSocketChannel`.
    `static Class<? extends io.netty.channel.socket.SocketChannel>` | `nioOrEpollSocketChannel()` If `Epoll.isAvailable()` `== true`, returns `EpollSocketChannel`, otherwise returns `NioSocketChannel`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### NettyUtils

          public NettyUtils()

  - ### Method Detail

    - #### newNioOrEpollEventLoopGroup

          public static io.netty.channel.EventLoopGroup newNioOrEpollEventLoopGroup()

      If `Epoll.isAvailable()` `== true`, returns a new `EpollEventLoopGroup`, otherwise returns a new `NioEventLoopGroup`. Creates the event loop group using the default number of threads.
      Returns:
        a new `EventLoopGroup`.

    - #### newNioOrEpollEventLoopGroup

          public static io.netty.channel.EventLoopGroup newNioOrEpollEventLoopGroup(int nThreads)

      If `Epoll.isAvailable()` `== true`, returns a new `EpollEventLoopGroup`, otherwise returns a new `NioEventLoopGroup`. Creates the event loop group using the specified number of threads instead of the default.
      Parameters:
        `nThreads` - see `NioEventLoopGroup(int)`.
      Returns:
        a new `EventLoopGroup`.

    - #### nioOrEpollSocketChannel

          public static Class<? extends io.netty.channel.socket.SocketChannel> nioOrEpollSocketChannel()

      If `Epoll.isAvailable()` `== true`, returns `EpollSocketChannel`, otherwise returns `NioSocketChannel`.
      Returns:
        a socket channel class.

    - #### nioOrEpollServerSocketChannel

          public static Class<? extends io.netty.channel.socket.ServerSocketChannel> nioOrEpollServerSocketChannel()

      If `Epoll.isAvailable()` `== true`, returns `EpollServerSocketChannel`, otherwise returns `NioServerSocketChannel`.
      Returns:
        a server socket channel class.

    - #### getClientReachableLocalInetAddressCount

          public static int getClientReachableLocalInetAddressCount()

      Attempts to detect and return the number of local network addresses that could be used by a client to reach this server. This means we exclude the following address types:
      - Multicast addresses. Zookeeper server sockets use TCP, thus cannot bind to a multicast address.
      - Link-local addresses. Routers don't forward traffic sent to a link-local address, so any realistic server deployment would not have clients using these.
      - Loopback addresses. These are typically only used for testing.
      Any remaining addresses are counted, and the total count is returned. This number is used to configure the number of threads for the "boss" event loop group, to make sure we have enough threads for each address in case the server is configured to listen on all available addresses. If listing the network interfaces fails, this method will return 1.
      Returns:
        the number of client-reachable local network addresses found, or 1 if listing the network interfaces fails.

Copyright © 2008–2021 The Apache Software Foundation. All rights reserved.