Package 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 Description NettyUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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()
IfEpoll.isAvailable()
== true
, returns a newEpollEventLoopGroup
, otherwise returns a newNioEventLoopGroup
.static io.netty.channel.EventLoopGroup
newNioOrEpollEventLoopGroup(int nThreads)
IfEpoll.isAvailable()
== true
, returns a newEpollEventLoopGroup
, otherwise returns a newNioEventLoopGroup
.static Class<? extends io.netty.channel.socket.ServerSocketChannel>
nioOrEpollServerSocketChannel()
IfEpoll.isAvailable()
== true
, returnsEpollServerSocketChannel
, otherwise returnsNioServerSocketChannel
.static Class<? extends io.netty.channel.socket.SocketChannel>
nioOrEpollSocketChannel()
IfEpoll.isAvailable()
== true
, returnsEpollSocketChannel
, otherwise returnsNioSocketChannel
.
-
-
-
Method Detail
-
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
public static Class<? extends io.netty.channel.socket.SocketChannel> 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.
-
-