resolve the conflicts

pull/379/head
wulingxiao 3 years ago
parent 66664e5ed9
commit 7a87d7c55c

@ -18,7 +18,9 @@
package com.tencent.cloud.polaris.loadbalancer; package com.tencent.cloud.polaris.loadbalancer;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.tencent.cloud.common.metadata.MetadataContext; import com.tencent.cloud.common.metadata.MetadataContext;
@ -48,18 +50,19 @@ public class LoadBalancerUtils {
* @return ServiceInstances * @return ServiceInstances
*/ */
public static ServiceInstances transferServersToServiceInstances(Flux<List<ServiceInstance>> servers) { public static ServiceInstances transferServersToServiceInstances(Flux<List<ServiceInstance>> servers) {
List<Instance> instances = servers.toStream() AtomicReference<List<Instance>> instances = new AtomicReference<>();
.flatMap(List::stream) servers.subscribe(serviceInstances -> instances.set(serviceInstances.stream()
.map(LoadBalancerUtils::transferServerToServiceInstance) .map(LoadBalancerUtils::transferServerToServiceInstance)
.collect(Collectors.toList()); .collect(Collectors.toList())));
String serviceName = null; String serviceName = null;
if (!CollectionUtils.isEmpty(instances)) { if (CollectionUtils.isEmpty(instances.get())) {
serviceName = instances.get(0).getService(); instances.set(Collections.emptyList());
}
else {
serviceName = instances.get().get(0).getService();
} }
ServiceKey serviceKey = new ServiceKey(MetadataContext.LOCAL_NAMESPACE, serviceName); ServiceKey serviceKey = new ServiceKey(MetadataContext.LOCAL_NAMESPACE, serviceName);
return new DefaultServiceInstances(serviceKey, instances.get());
return new DefaultServiceInstances(serviceKey, instances);
} }
/** /**

Loading…
Cancel
Save