style fix

pull/3686/head
karsonto 10 months ago
parent bbff4b1afd
commit 0a1726f0c9

@ -22,8 +22,6 @@ import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.springframework.cloud.client.ServiceInstance;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.cloud.nacos.NacosServiceInstance;
import com.alibaba.cloud.nacos.loadbalancer.NacosLoadBalancer;
@ -31,6 +29,9 @@ import com.alibaba.cloud.nacos.util.NacosServiceInstanceConverter;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.client.naming.core.Balancer;
import org.springframework.cloud.client.ServiceInstance;
/**
* @author itmuch.com XuDaojie
* @since 2021.1
@ -43,6 +44,7 @@ public class NacosBalancer extends Balancer {
/**
* Choose instance by weight.
*
* @param instances Instance List
* @return the chosen instance
*/
@ -52,11 +54,11 @@ public class NacosBalancer extends Balancer {
/**
* Spring Cloud LoadBalancer Choose instance by weight.
*
* @param serviceInstances Instance List
* @return the chosen instance
*/
public static ServiceInstance getHostByRandomWeight3(
List<ServiceInstance> serviceInstances) {
public static ServiceInstance getHostByRandomWeight3(List<ServiceInstance> serviceInstances) {
Map<Instance, ServiceInstance> instanceMap = new HashMap<>();
List<Instance> nacosInstance = serviceInstances.stream().map(serviceInstance -> {
Instance instance = NacosServiceInstanceConverter.fromServiceInstance(serviceInstance);
@ -74,8 +76,7 @@ public class NacosBalancer extends Balancer {
}
/**
* There is two type Ip,using IPv6 should use IPv6 in metadata to replace IPv4 in IP
* field.
* There is two type Ip,using IPv6 should use IPv6 in metadata to replace IPv4 in IP field.
*/
private static void convertIPv4ToIPv6(NacosServiceInstance instance) {
if (Pattern.matches(IPV4_REGEX, instance.getHost())) {

@ -19,8 +19,6 @@ package com.alibaba.cloud.nacos.discovery;
import java.util.ArrayList;
import java.util.List;
import org.springframework.cloud.client.ServiceInstance;
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.cloud.nacos.NacosServiceManager;
import com.alibaba.cloud.nacos.util.NacosServiceInstanceConverter;
@ -29,6 +27,7 @@ import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView;
import org.springframework.cloud.client.ServiceInstance;
/**
* @author <a href="mailto:echooy.mxq@gmail.com">echooymxq</a>
* @author changjin wei()
@ -39,8 +38,7 @@ public class NacosServiceDiscovery {
private NacosServiceManager nacosServiceManager;
public NacosServiceDiscovery(NacosDiscoveryProperties discoveryProperties,
NacosServiceManager nacosServiceManager) {
public NacosServiceDiscovery(NacosDiscoveryProperties discoveryProperties, NacosServiceManager nacosServiceManager) {
this.discoveryProperties = discoveryProperties;
this.nacosServiceManager = nacosServiceManager;
}
@ -54,8 +52,7 @@ public class NacosServiceDiscovery {
*/
public List<ServiceInstance> getInstances(String serviceId) throws NacosException {
String group = discoveryProperties.getGroup();
List<Instance> instances = namingService().selectInstances(serviceId, group,
true);
List<Instance> instances = namingService().selectInstances(serviceId, group, true);
return hostToServiceInstanceList(instances, serviceId);
}
@ -67,13 +64,11 @@ public class NacosServiceDiscovery {
*/
public List<String> getServices() throws NacosException {
String group = discoveryProperties.getGroup();
ListView<String> services = namingService().getServicesOfServer(1,
Integer.MAX_VALUE, group);
ListView<String> services = namingService().getServicesOfServer(1, Integer.MAX_VALUE, group);
return services.getData();
}
public static List<ServiceInstance> hostToServiceInstanceList(
List<Instance> instances, String serviceId) {
public static List<ServiceInstance> hostToServiceInstanceList(List<Instance> instances, String serviceId) {
List<ServiceInstance> result = new ArrayList<>(instances.size());
for (Instance instance : instances) {
ServiceInstance serviceInstance = NacosServiceInstanceConverter.fromInstanceAndServiceId(instance, serviceId);

@ -19,19 +19,23 @@ package com.alibaba.cloud.nacos.util;
import java.util.HashMap;
import java.util.Map;
import org.springframework.cloud.client.ServiceInstance;
import com.alibaba.cloud.nacos.NacosServiceInstance;
import com.alibaba.nacos.api.naming.pojo.Instance;
import org.springframework.cloud.client.ServiceInstance;
/**
* @author Karson
*/
public class NacosServiceInstanceConverter {
final public class NacosServiceInstanceConverter {
private static final String WEIGHT = "nacos.weight";
public static final String WEIGHT = "nacos.weight";
private static final String HEALTHY = "nacos.healthy";
public static final String HEALTHY = "nacos.healthy";
private NacosServiceInstanceConverter() { }
public static ServiceInstance fromInstanceAndServiceId(Instance instance, String serviceId) {
return ServiceInstanceBuilder.fromInstanceAndServiceId(instance, serviceId).build();
@ -46,7 +50,7 @@ public class NacosServiceInstanceConverter {
T build();
}
static class InstanceServiceBuilder implements Builder<Instance> {
final static class InstanceServiceBuilder implements Builder<Instance> {
private ServiceInstance serviceInstance;
@ -76,8 +80,7 @@ public class NacosServiceInstanceConverter {
}
}
static class ServiceInstanceBuilder implements Builder<ServiceInstance> {
final static class ServiceInstanceBuilder implements Builder<ServiceInstance> {
private Instance instance;
private String serviceId;
@ -92,7 +95,6 @@ public class NacosServiceInstanceConverter {
return nacosServiceInstanceBuilder;
}
private void setInstance(Instance instance) {
this.instance = instance;
}

Loading…
Cancel
Save