healchow commented on code in PR #5778:
URL: https://github.com/apache/inlong/pull/5778#discussion_r963186036
##########
inlong-common/src/main/java/org/apache/inlong/common/util/NetworkUtils.java:
##########
@@ -17,59 +17,55 @@
package org.apache.inlong.common.util;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
public class NetworkUtils {
- public static String INNER_NETWORK_INTERFACE = "eth1";
- private static String localIp = null;
+ private static final Logger LOGGER =
LoggerFactory.getLogger(NetworkUtils.class);
+ private static String localIp;
static {
localIp = getLocalIp();
}
/**
* get local ip
- * @return
*/
public static String getLocalIp() {
- if (localIp == null) {
- String ip = null;
- Enumeration<NetworkInterface> allInterface;
- try {
- allInterface = NetworkInterface.getNetworkInterfaces();
- for (; allInterface.hasMoreElements(); ) {
- NetworkInterface oneInterface = allInterface.nextElement();
- String interfaceName = oneInterface.getName();
- if (oneInterface.isLoopback()
- || !oneInterface.isUp()
- || !interfaceName
- .equalsIgnoreCase(INNER_NETWORK_INTERFACE)) {
- continue;
- }
+ if (!StringUtils.isEmpty(localIp)) {
Review Comment:
Suggest using `StringUtils.isNotBlank()`.
##########
inlong-common/src/main/java/org/apache/inlong/common/util/NetworkUtils.java:
##########
@@ -17,59 +17,55 @@
package org.apache.inlong.common.util;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
public class NetworkUtils {
- public static String INNER_NETWORK_INTERFACE = "eth1";
- private static String localIp = null;
+ private static final Logger LOGGER =
LoggerFactory.getLogger(NetworkUtils.class);
+ private static String localIp;
static {
localIp = getLocalIp();
}
/**
* get local ip
- * @return
*/
public static String getLocalIp() {
- if (localIp == null) {
- String ip = null;
- Enumeration<NetworkInterface> allInterface;
- try {
- allInterface = NetworkInterface.getNetworkInterfaces();
- for (; allInterface.hasMoreElements(); ) {
- NetworkInterface oneInterface = allInterface.nextElement();
- String interfaceName = oneInterface.getName();
- if (oneInterface.isLoopback()
- || !oneInterface.isUp()
- || !interfaceName
- .equalsIgnoreCase(INNER_NETWORK_INTERFACE)) {
- continue;
- }
+ if (!StringUtils.isEmpty(localIp)) {
+ return localIp;
+ }
+ Enumeration<NetworkInterface> allInterface;
+ String ip = "127.0.0.1";
+ try {
+ allInterface = NetworkInterface.getNetworkInterfaces();
+ for (; allInterface.hasMoreElements(); ) {
Review Comment:
Suggest changing the `for` to `while` or `forEach`.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]