viviel commented on a change in pull request #97:
URL: https://github.com/apache/incubator-tubemq/pull/97#discussion_r429932827



##########
File path: 
tubemq-core/src/main/java/org/apache/tubemq/corebase/utils/AddressUtils.java
##########
@@ -34,31 +40,29 @@ public static synchronized String getLocalAddress() throws 
Exception {
         return localIPAddress;
     }
 
-    public static boolean validLocalIp(String currLocalHost) throws Exception {
+    public static boolean validLocalIp(String currLocalHost) {
         if (TStringUtils.isNotEmpty(localIPAddress)
                 && localIPAddress.equals(currLocalHost)) {
             return true;
         }
-        Enumeration<NetworkInterface> allInterface = 
NetworkInterface.getNetworkInterfaces();
-        if (allInterface == null) {
-            throw new Exception("Get NetworkInterfaces is null");
-        }
+
+        Enumeration<NetworkInterface> allInterface = listNetworkInterface();
+
         return checkValidIp(allInterface, currLocalHost);
     }
 
-    private static boolean checkValidIp(Enumeration<NetworkInterface> 
allInterface,
-                                        String currLocalHost) throws Exception 
{
-        String localIp = null;
+    private static boolean checkValidIp(Enumeration<NetworkInterface> 
allInterface, String currLocalHost) {

Review comment:
       The initial idea is only for IPV4, if the IPV4 address cannot be 
obtained on the machine. Will cause an exception to the user, let the user 
specify the IP address, which is why the two constructors are not marked with 
@deprecated annotation.
   
   Now, I understand that IPV4 and IPV6 are used together. In that case, I will 
reorganize the process
   
   There are two options:
   
   First, get the address completely automatically
   1. Priority access to IPV4 address.
   2. If not available, obtain an IPV6 address.
   3. No IP can be obtained, choose one of the two below
      1) Throw the exception to the user
      2) Get IP from InetAddress
   
   Second, give priority to obtain IP from the designated network interface
   1. Try to obtain IPV4 from the specified network card. If not, obtain IPV4 
from other network interfaces.
   2. If IPV4 is not obtained in the previous step, try to obtain IPV6 from the 
specified network interface. Otherwise, obtain IPV6 from other network 
interfaces.
   3. No IP can be obtained, choose one of the two below
      1) Throw the exception to the user
      2) Get IP from InetAddress




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to