[ISSUE #7220] replace with lambda (#7222)

* replace with lambda

* replace with lambda
This commit is contained in:
李晓双 Li Xiao Shuang 2021-11-12 10:20:54 +08:00 committed by GitHub
parent 0719200c38
commit 80874749bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,10 +44,8 @@ import java.util.List;
import java.util.Properties;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.concurrent.Callable;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
/**
@ -65,14 +63,11 @@ public class ServerListManager implements Closeable {
private final NacosRestTemplate nacosRestTemplate = ConfigHttpClientManager.getInstance().getNacosRestTemplate();
private final ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1, new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setName("com.alibaba.nacos.client.ServerListManager");
t.setDaemon(true);
return t;
}
private final ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1, r -> {
Thread t = new Thread(r);
t.setName("com.alibaba.nacos.client.ServerListManager");
t.setDaemon(true);
return t;
});
/**
@ -109,7 +104,7 @@ public class ServerListManager implements Closeable {
private String serverListName = ParamUtil.getDefaultNodesPath();
volatile List<String> serverUrls = new ArrayList<String>();
volatile List<String> serverUrls = new ArrayList<>();
private volatile String currentServerAddr;
@ -134,7 +129,7 @@ public class ServerListManager implements Closeable {
public ServerListManager(List<String> fixed, String namespace) {
this.isFixed = true;
this.isStarted = true;
List<String> serverAddrs = new ArrayList<String>();
List<String> serverAddrs = new ArrayList<>();
for (String serverAddr : fixed) {
String[] serverAddrArr = InternetAddressUtil.splitIPPortStr(serverAddr);
if (serverAddrArr.length == 1) {
@ -143,7 +138,7 @@ public class ServerListManager implements Closeable {
serverAddrs.add(serverAddr);
}
}
this.serverUrls = new ArrayList<String>(serverAddrs);
this.serverUrls = new ArrayList<>(serverAddrs);
if (StringUtils.isBlank(namespace)) {
this.name = FIXED_NAME + "-" + getFixedNameSuffix(serverAddrs.toArray(new String[serverAddrs.size()]));
} else {
@ -200,7 +195,7 @@ public class ServerListManager implements Closeable {
if (StringUtils.isNotEmpty(serverAddrsStr)) {
this.isFixed = true;
List<String> serverAddrs = new ArrayList<String>();
List<String> serverAddrs = new ArrayList<>();
StringTokenizer serverAddrsTokens = new StringTokenizer(this.serverAddrsStr, ",;");
while (serverAddrsTokens.hasMoreTokens()) {
String serverAddr = serverAddrsTokens.nextToken().trim();
@ -263,12 +258,7 @@ public class ServerListManager implements Closeable {
String endpointPortTmp = TemplateUtils
.stringEmptyAndThenExecute(System.getenv(PropertyKeyConst.SystemEnv.ALIBABA_ALIWARE_ENDPOINT_PORT),
new Callable<String>() {
@Override
public String call() {
return properties.getProperty(PropertyKeyConst.ENDPOINT_PORT);
}
});
() -> properties.getProperty(PropertyKeyConst.ENDPOINT_PORT));
if (StringUtils.isNotBlank(endpointPortTmp)) {
this.endpointPort = Integer.parseInt(endpointPortTmp);
@ -370,7 +360,7 @@ public class ServerListManager implements Closeable {
return;
}
List<String> newServerAddrList = new ArrayList<String>();
List<String> newServerAddrList = new ArrayList<>();
for (String server : newList) {
if (server.startsWith(HTTP) || server.startsWith(HTTPS)) {
newServerAddrList.add(server);
@ -385,7 +375,7 @@ public class ServerListManager implements Closeable {
if (newServerAddrList.equals(serverUrls)) {
return;
}
serverUrls = new ArrayList<String>(newServerAddrList);
serverUrls = new ArrayList<>(newServerAddrList);
iterator = iterator();
currentServerAddr = iterator.next();
@ -403,7 +393,7 @@ public class ServerListManager implements Closeable {
EnvUtil.setSelfEnv(httpResult.getHeader().getOriginalResponseHeader());
}
List<String> lines = IoUtils.readLines(new StringReader(httpResult.getData()));
List<String> result = new ArrayList<String>(lines.size());
List<String> result = new ArrayList<>(lines.size());
for (String serverAddr : lines) {
if (StringUtils.isNotBlank(serverAddr)) {
String[] ipPort = InternetAddressUtil.splitIPPortStr(serverAddr.trim());
@ -543,7 +533,7 @@ public class ServerListManager implements Closeable {
}
public ServerAddressIterator(List<String> source) {
sorted = new ArrayList<RandomizedServerAddress>();
sorted = new ArrayList<>();
for (String address : source) {
sorted.add(new RandomizedServerAddress(address));
}