eolivelli commented on a change in pull request #809: ZOOKEEPER-3272: Clean up 
netty4 code per Norman Maurer's review comments
URL: https://github.com/apache/zookeeper/pull/809#discussion_r254563288
 
 

 ##########
 File path: 
zookeeper-server/src/main/java/org/apache/zookeeper/common/NettyUtils.java
 ##########
 @@ -73,4 +103,53 @@ public static EventLoopGroup newNioOrEpollEventLoopGroup() 
{
             return NioServerSocketChannel.class;
         }
     }
+
+    private static final int DEFAULT_INET_ADDRESS_COUNT = 1;
+
+    /**
+     * 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:
+     * <ul>
+     *     <li>Multicast addresses. Zookeeper server sockets use TCP, thus 
cannot bind to a multicast address.</li>
+     *     <li>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.</li>
+     *     <li>Loopback addresses. These are typically only used for 
testing.</li>
+     * </ul>
+     * 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.
+     *
+     * @return the number of client-reachable local network addresses found, or
+     * 1 if listing the network interfaces fails.
+     */
+    public static int getClientReachableLocalInetAddressCount() {
+        try {
+            Set<InetAddress> validInetAddresses = new HashSet<>();
+            Enumeration<NetworkInterface> allNetworkInterfaces = 
NetworkInterface.getNetworkInterfaces();
+            for (NetworkInterface networkInterface : 
Collections.list(allNetworkInterfaces)) {
+                for (InetAddress inetAddress : 
Collections.list(networkInterface.getInetAddresses())) {
+                    if (inetAddress.isLinkLocalAddress()) {
+                        continue;
+                    }
+                    if (inetAddress.isMulticastAddress()) {
+                        continue;
 
 Review comment:
   If debug...log 'Ignoring inetAddress because...'

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to