Reformat the codes

pull/2661/head
chengpu.rzh 3 years ago
parent 9a21f3d08e
commit 3628732dad

@ -80,7 +80,7 @@
<properties> <properties>
<!-- Project revision --> <!-- Project revision -->
<revision>2.2.8.RELEASE</revision> <revision>2.2.9-SNAPSHOT</revision>
<!-- Spring Cloud --> <!-- Spring Cloud -->
<spring.cloud.version>Hoxton.SR12</spring.cloud.version> <spring.cloud.version>Hoxton.SR12</spring.cloud.version>

@ -18,7 +18,7 @@
<description>Spring Cloud Alibaba Dependencies</description> <description>Spring Cloud Alibaba Dependencies</description>
<properties> <properties>
<revision>2.2.8.RELEASE</revision> <revision>2.2.9-SNAPSHOT</revision>
<sentinel.version>1.8.4</sentinel.version> <sentinel.version>1.8.4</sentinel.version>
<seata.version>1.5.1</seata.version> <seata.version>1.5.1</seata.version>
<nacos.client.version>2.1.0</nacos.client.version> <nacos.client.version>2.1.0</nacos.client.version>

@ -17,7 +17,6 @@
package com.alibaba.cloud.nacos; package com.alibaba.cloud.nacos;
import java.net.Inet4Address; import java.net.Inet4Address;
import java.net.Inet6Address; import java.net.Inet6Address;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.NetworkInterface; import java.net.NetworkInterface;
@ -166,7 +165,7 @@ public class NacosDiscoveryProperties {
private String networkInterface = ""; private String networkInterface = "";
/** /**
* choose IPV4 or IPV6,if you don't set it will choose IPV4 * choose IPV4 or IPV6,if you don't set it will choose IPV4.
*/ */
private String ipType = "IPv4"; private String ipType = "IPv4";
@ -258,12 +257,14 @@ public class NacosDiscoveryProperties {
if (StringUtils.isEmpty(networkInterface)) { if (StringUtils.isEmpty(networkInterface)) {
if (ipType.equalsIgnoreCase("IPv4")) { if (ipType.equalsIgnoreCase("IPv4")) {
ip = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); ip = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
}else if (ipType.equalsIgnoreCase("IPv6")){ }
else if (ipType.equalsIgnoreCase("IPv6")) {
ip = inetIPUtils.findFirstNonLoopbackHostInfo().getIpAddress(); ip = inetIPUtils.findFirstNonLoopbackHostInfo().getIpAddress();
int index = ip.indexOf('%'); int index = ip.indexOf('%');
ip = index > 0 ? ip.substring(0, index) : ip; ip = index > 0 ? ip.substring(0, index) : ip;
ip = "[" + ip + "]"; ip = "[" + ip + "]";
}else { }
else {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"please checking the type of IP " + ipType); "please checking the type of IP " + ipType);
} }

@ -1,13 +1,23 @@
package com.alibaba.cloud.nacos.intetuntil; /*
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.commons.logging.Log; package com.alibaba.cloud.nacos.intetuntil;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.cloud.commons.util.InetUtilsProperties;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.net.Inet6Address; import java.net.Inet6Address;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.NetworkInterface; import java.net.NetworkInterface;
@ -19,10 +29,17 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.commons.util.InetUtils;
import org.springframework.cloud.commons.util.InetUtilsProperties;
/** /**
* @author HH * @author HH
*/ */
public class InetIPv6Utils implements Closeable { public class InetIPv6Utils implements Closeable {
private final ExecutorService executorService; private final ExecutorService executorService;
private final Log log = LogFactory.getLog(InetIPv6Utils.class); private final Log log = LogFactory.getLog(InetIPv6Utils.class);
@ -47,7 +64,8 @@ public class InetIPv6Utils implements Closeable {
InetAddress address = this.findFirstNonLoopbackIPv6Address(); InetAddress address = this.findFirstNonLoopbackIPv6Address();
if (address != null) { if (address != null) {
return this.convertAddress(address); return this.convertAddress(address);
} else { }
else {
InetUtils.HostInfo hostInfo = new InetUtils.HostInfo(); InetUtils.HostInfo hostInfo = new InetUtils.HostInfo();
this.properties.setDefaultIpAddress("0:0:0:0:0:0:0:1"); this.properties.setDefaultIpAddress("0:0:0:0:0:0:0:1");
hostInfo.setHostname(this.properties.getDefaultHostname()); hostInfo.setHostname(this.properties.getDefaultHostname());
@ -61,8 +79,8 @@ public class InetIPv6Utils implements Closeable {
try { try {
int lowest = Integer.MAX_VALUE; int lowest = Integer.MAX_VALUE;
for (Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces(); for (Enumeration<NetworkInterface> nics = NetworkInterface
nics.hasMoreElements();) { .getNetworkInterfaces(); nics.hasMoreElements();) {
NetworkInterface ifc = nics.nextElement(); NetworkInterface ifc = nics.nextElement();
if (ifc.isUp()) { if (ifc.isUp()) {
log.trace("Testing interface:" + ifc.getDisplayName()); log.trace("Testing interface:" + ifc.getDisplayName());
@ -155,4 +173,5 @@ public class InetIPv6Utils implements Closeable {
hostInfo.setIpAddress(address.getHostAddress()); hostInfo.setIpAddress(address.getHostAddress());
return hostInfo; return hostInfo;
} }
} }

@ -1,3 +1,19 @@
/*
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.cloud.nacos.intetuntil; package com.alibaba.cloud.nacos.intetuntil;
import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled; import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled;
@ -8,7 +24,6 @@ import org.springframework.cloud.commons.util.InetUtilsProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
/** /**
* @author HH * @author HH
*/ */
@ -16,6 +31,7 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnDiscoveryEnabled @ConditionalOnDiscoveryEnabled
@ConditionalOnNacosDiscoveryEnabled @ConditionalOnNacosDiscoveryEnabled
public class UtilIPv6AutoConfiguration { public class UtilIPv6AutoConfiguration {
public UtilIPv6AutoConfiguration() { public UtilIPv6AutoConfiguration() {
} }
@ -24,5 +40,5 @@ public class UtilIPv6AutoConfiguration {
public InetIPv6Utils inetUtils(InetUtilsProperties properties) { public InetIPv6Utils inetUtils(InetUtilsProperties properties) {
return new InetIPv6Utils(properties); return new InetIPv6Utils(properties);
} }
}
}

Loading…
Cancel
Save