Package org.apache.zookeeper.common
Class NettyUtils
java.lang.Object
org.apache.zookeeper.common.NettyUtils
Helper methods for netty code.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intAttempts 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.EventLoopGroupIfEpoll.isAvailable()== true, returns a newEpollEventLoopGroup, otherwise returns a newNioEventLoopGroup.static io.netty.channel.EventLoopGroupnewNioOrEpollEventLoopGroup(int nThreads) IfEpoll.isAvailable()== true, returns a newEpollEventLoopGroup, otherwise returns a newNioEventLoopGroup.static Class<? extends io.netty.channel.socket.ServerSocketChannel>IfEpoll.isAvailable()== true, returnsEpollServerSocketChannel, otherwise returnsNioServerSocketChannel.static Class<? extends io.netty.channel.socket.SocketChannel>IfEpoll.isAvailable()== true, returnsEpollSocketChannel, otherwise returnsNioSocketChannel.
-
Constructor Details
-
NettyUtils
public NettyUtils()
-
-
Method Details
-
newNioOrEpollEventLoopGroup
public static io.netty.channel.EventLoopGroup newNioOrEpollEventLoopGroup()IfEpoll.isAvailable()== true, returns a newEpollEventLoopGroup, otherwise returns a newNioEventLoopGroup. 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) IfEpoll.isAvailable()== true, returns a newEpollEventLoopGroup, otherwise returns a newNioEventLoopGroup. Creates the event loop group using the specified number of threads instead of the default.- Parameters:
nThreads- seeNioEventLoopGroup(int).- Returns:
- a new
EventLoopGroup.
-
nioOrEpollSocketChannel
IfEpoll.isAvailable()== true, returnsEpollSocketChannel, otherwise returnsNioSocketChannel.- Returns:
- a socket channel class.
-
nioOrEpollServerSocketChannel
public static Class<? extends io.netty.channel.socket.ServerSocketChannel> nioOrEpollServerSocketChannel()IfEpoll.isAvailable()== true, returnsEpollServerSocketChannel, otherwise returnsNioServerSocketChannel.- 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.
- Returns:
- the number of client-reachable local network addresses found, or 1 if listing the network interfaces fails.
-