Merge pull request #2142 from easyhaloo/code_optimization
refactor #2134 optimization code
This commit is contained in:
commit
264f686d1c
@ -65,7 +65,7 @@ public class AddressServerGeneratorManager {
|
||||
String[] ipAndPort = generateIpAndPort(ip);
|
||||
Instance instance = new Instance();
|
||||
instance.setIp(ipAndPort[0]);
|
||||
instance.setPort(Integer.valueOf(ipAndPort[1]));
|
||||
instance.setPort(Integer.parseInt(ipAndPort[1]));
|
||||
instance.setClusterName(clusterName);
|
||||
instance.setServiceName(serviceName);
|
||||
instance.setTenant(Constants.DEFAULT_NAMESPACE_ID);
|
||||
|
@ -222,7 +222,7 @@ public class Instance {
|
||||
}
|
||||
String value = getMetadata().get(key);
|
||||
if (!StringUtils.isEmpty(value) && value.matches(NUMBER_PATTERN)) {
|
||||
return Long.valueOf(value);
|
||||
return Long.parseLong(value);
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
@ -53,9 +53,9 @@ public class HistoryController {
|
||||
@RequestParam(value = "pageSize", required = false)
|
||||
Integer pageSize, //
|
||||
ModelMap modelMap) {
|
||||
pageNo = null == pageNo ? Integer.valueOf(1) : pageNo;
|
||||
pageSize = null == pageSize ? Integer.valueOf(100) : pageSize;
|
||||
pageSize = pageSize > 500 ? Integer.valueOf(500) : pageSize;
|
||||
pageNo = null == pageNo ? 1 : pageNo;
|
||||
pageSize = null == pageSize ? 100 : pageSize;
|
||||
pageSize = Math.min(500,pageSize);
|
||||
// configInfoBase没有appName字段
|
||||
return persistService.findConfigHistory(dataId, group, tenant, pageNo, pageSize);
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ public class BasicDataSourceServiceImpl implements DataSourceService {
|
||||
if (result == null) {
|
||||
return false;
|
||||
} else {
|
||||
return result.intValue() == 0 ? true : false;
|
||||
return result == 0;
|
||||
}
|
||||
} catch (CannotGetJdbcConnectionException e) {
|
||||
fatalLog.error("[db-error] " + e.toString(), e);
|
||||
|
@ -865,7 +865,7 @@ public class PersistService {
|
||||
ps.setString(index++, dataId);
|
||||
ps.setString(index++, group);
|
||||
ps.setString(index++, tenantTmp);
|
||||
ps.setString(index++, datumId);
|
||||
ps.setString(index, datumId);
|
||||
}
|
||||
});
|
||||
} catch (CannotGetJdbcConnectionException e) {
|
||||
@ -888,7 +888,7 @@ public class PersistService {
|
||||
int index = 1;
|
||||
ps.setString(index++, dataId);
|
||||
ps.setString(index++, group);
|
||||
ps.setString(index++, tenantTmp);
|
||||
ps.setString(index, tenantTmp);
|
||||
}
|
||||
});
|
||||
} catch (CannotGetJdbcConnectionException e) {
|
||||
@ -993,7 +993,7 @@ public class PersistService {
|
||||
if (isPublishOk == null) {
|
||||
return false;
|
||||
}
|
||||
return isPublishOk.booleanValue();
|
||||
return isPublishOk;
|
||||
} catch (TransactionException e) {
|
||||
fatalLog.error("[db-error] " + e.toString(), e);
|
||||
return false;
|
||||
@ -1035,7 +1035,7 @@ public class PersistService {
|
||||
if (isReplaceOk == null) {
|
||||
return false;
|
||||
}
|
||||
return isReplaceOk.booleanValue();
|
||||
return isReplaceOk;
|
||||
} catch (TransactionException e) {
|
||||
fatalLog.error("[db-error] " + e.toString(), e);
|
||||
return false;
|
||||
@ -2848,7 +2848,7 @@ public class PersistService {
|
||||
sql.append(", ");
|
||||
}
|
||||
sql.append("?");
|
||||
paramList.add(Long.valueOf(tagArr[i]));
|
||||
paramList.add(Long.parseLong(tagArr[i]));
|
||||
}
|
||||
sql.append(") ");
|
||||
try {
|
||||
@ -2957,7 +2957,7 @@ public class PersistService {
|
||||
sql.append(", ");
|
||||
}
|
||||
sql.append("?");
|
||||
paramList.add(Long.valueOf(tagArr[i]));
|
||||
paramList.add(Long.parseLong(tagArr[i]));
|
||||
}
|
||||
sql.append(") ");
|
||||
try {
|
||||
|
@ -356,20 +356,19 @@ public class ServerListService implements ApplicationListener<WebServerInitializ
|
||||
@Override
|
||||
public void completed(HttpResponse response) {
|
||||
if (response.getStatusLine().getStatusCode() == HttpServletResponse.SC_OK) {
|
||||
serverIp2unhealthCount.put(serverIp, 0);
|
||||
if (serverListUnhealth.contains(serverIp)) {
|
||||
serverListUnhealth.remove(serverIp);
|
||||
}
|
||||
serverListUnhealth.remove(serverIp);
|
||||
HttpClientUtils.closeQuietly(response);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Exception ex) {
|
||||
Integer failCount = serverIp2unhealthCount.get(serverIp);
|
||||
failCount = failCount == null ? Integer.valueOf(0) : failCount;
|
||||
failCount++;
|
||||
serverIp2unhealthCount.put(serverIp, failCount);
|
||||
int failCount = serverIp2unhealthCount.compute(serverIp,(key,oldValue)->{
|
||||
if(oldValue == null){
|
||||
return 1;
|
||||
}
|
||||
return oldValue+1;
|
||||
});
|
||||
if (failCount > maxFailCount) {
|
||||
if (!serverListUnhealth.contains(serverIp)) {
|
||||
serverListUnhealth.add(serverIp);
|
||||
@ -381,10 +380,12 @@ public class ServerListService implements ApplicationListener<WebServerInitializ
|
||||
|
||||
@Override
|
||||
public void cancelled() {
|
||||
Integer failCount = serverIp2unhealthCount.get(serverIp);
|
||||
failCount = failCount == null ? Integer.valueOf(0) : failCount;
|
||||
failCount++;
|
||||
serverIp2unhealthCount.put(serverIp, failCount);
|
||||
int failCount = serverIp2unhealthCount.compute(serverIp,(key,oldValue)->{
|
||||
if(oldValue == null){
|
||||
return 1;
|
||||
}
|
||||
return oldValue+1;
|
||||
});
|
||||
if (failCount > maxFailCount) {
|
||||
if (!serverListUnhealth.contains(serverIp)) {
|
||||
serverListUnhealth.add(serverIp);
|
||||
|
@ -145,8 +145,8 @@ public class MD5 {
|
||||
byte[] data = new byte[16];
|
||||
char[] chs = str.toCharArray();
|
||||
for (int i = 0; i < DIGITS_COUNT; ++i) {
|
||||
int h = rDigits.get(chs[i * 2]).intValue();
|
||||
int l = rDigits.get(chs[i * 2 + 1]).intValue();
|
||||
int h = rDigits.get(chs[i * 2]);
|
||||
int l = rDigits.get(chs[i * 2 + 1]);
|
||||
data[i] = (byte)((h & 0x0F) << 4 | (l & 0x0F));
|
||||
}
|
||||
return data;
|
||||
|
@ -62,11 +62,10 @@ public class PaginationHelper<E> {
|
||||
if (rowCountInt == null) {
|
||||
throw new IllegalArgumentException("fetchPageLimit error");
|
||||
}
|
||||
final int rowCount = rowCountInt.intValue();
|
||||
|
||||
// 计算页数
|
||||
int pageCount = rowCount / pageSize;
|
||||
if (rowCount > pageSize * pageCount) {
|
||||
int pageCount = rowCountInt / pageSize;
|
||||
if (rowCountInt > pageSize * pageCount) {
|
||||
pageCount++;
|
||||
}
|
||||
|
||||
@ -74,7 +73,7 @@ public class PaginationHelper<E> {
|
||||
final Page<E> page = new Page<E>();
|
||||
page.setPageNumber(pageNo);
|
||||
page.setPagesAvailable(pageCount);
|
||||
page.setTotalCount(rowCount);
|
||||
page.setTotalCount(rowCountInt);
|
||||
|
||||
if (pageNo > pageCount) {
|
||||
return null;
|
||||
@ -108,11 +107,10 @@ public class PaginationHelper<E> {
|
||||
if (rowCountInt == null) {
|
||||
throw new IllegalArgumentException("fetchPageLimit error");
|
||||
}
|
||||
final int rowCount = rowCountInt.intValue();
|
||||
|
||||
// 计算页数
|
||||
int pageCount = rowCount / pageSize;
|
||||
if (rowCount > pageSize * pageCount) {
|
||||
int pageCount = rowCountInt / pageSize;
|
||||
if (rowCountInt > pageSize * pageCount) {
|
||||
pageCount++;
|
||||
}
|
||||
|
||||
@ -120,7 +118,7 @@ public class PaginationHelper<E> {
|
||||
final Page<E> page = new Page<E>();
|
||||
page.setPageNumber(pageNo);
|
||||
page.setPagesAvailable(pageCount);
|
||||
page.setTotalCount(rowCount);
|
||||
page.setTotalCount(rowCountInt);
|
||||
|
||||
if (pageNo > pageCount) {
|
||||
return null;
|
||||
@ -150,11 +148,10 @@ public class PaginationHelper<E> {
|
||||
if (rowCountInt == null) {
|
||||
throw new IllegalArgumentException("fetchPageLimit error");
|
||||
}
|
||||
final int rowCount = rowCountInt.intValue();
|
||||
|
||||
// 计算页数
|
||||
int pageCount = rowCount / pageSize;
|
||||
if (rowCount > pageSize * pageCount) {
|
||||
int pageCount = rowCountInt / pageSize;
|
||||
if (rowCountInt > pageSize * pageCount) {
|
||||
pageCount++;
|
||||
}
|
||||
|
||||
@ -162,7 +159,7 @@ public class PaginationHelper<E> {
|
||||
final Page<E> page = new Page<E>();
|
||||
page.setPageNumber(pageNo);
|
||||
page.setPagesAvailable(pageCount);
|
||||
page.setTotalCount(rowCount);
|
||||
page.setTotalCount(rowCountInt);
|
||||
|
||||
if (pageNo > pageCount) {
|
||||
return null;
|
||||
|
@ -322,8 +322,9 @@ public class Instance extends com.alibaba.nacos.api.naming.pojo.Instance impleme
|
||||
while (currentInstanceIds.contains(String.valueOf(id))) {
|
||||
id++;
|
||||
}
|
||||
currentInstanceIds.add(String.valueOf(id));
|
||||
return String.valueOf(id);
|
||||
String idStr = String.valueOf(id);
|
||||
currentInstanceIds.add(idStr);
|
||||
return idStr;
|
||||
}
|
||||
|
||||
public void validate() throws NacosException {
|
||||
|
Loading…
Reference in New Issue
Block a user