Merge pull request #1832 from xianlaioy/develop
style: Modifiers should be declared in the correct order;Map init 设置大小
This commit is contained in:
commit
06530aaa54
@ -24,16 +24,17 @@ import java.util.concurrent.Executor;
|
||||
*/
|
||||
@SuppressWarnings("PMD.AbstractClassShouldStartWithAbstractNamingRule")
|
||||
public abstract class AbstractSharedListener implements Listener {
|
||||
|
||||
private volatile String dataId;
|
||||
private volatile String group;
|
||||
|
||||
final public void fillContext(String dataId, String group) {
|
||||
public final void fillContext(String dataId, String group) {
|
||||
this.dataId = dataId;
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
@Override
|
||||
final public void receiveConfigInfo(String configInfo) {
|
||||
public final void receiveConfigInfo(String configInfo) {
|
||||
innerReceive(dataId, group, configInfo);
|
||||
}
|
||||
|
||||
|
@ -24,33 +24,28 @@ import com.alibaba.nacos.client.utils.StringUtils;
|
||||
*/
|
||||
public class GroupKey {
|
||||
|
||||
static public String getKey(String dataId, String group) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
urlEncode(dataId, sb);
|
||||
sb.append('+');
|
||||
urlEncode(group, sb);
|
||||
return sb.toString();
|
||||
public static String getKey(String dataId, String group) {
|
||||
return doGetKey(dataId, group, "");
|
||||
}
|
||||
|
||||
static public String getKeyTenant(String dataId, String group, String tenant) {
|
||||
public static String getKeyTenant(String dataId, String group, String tenant) {
|
||||
return doGetKey(dataId, group, tenant);
|
||||
}
|
||||
|
||||
public static String getKey(String dataId, String group, String datumStr) {
|
||||
return doGetKey(dataId, group, datumStr);
|
||||
}
|
||||
|
||||
private static String doGetKey(String dataId, String group, String datumStr) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
urlEncode(dataId, sb);
|
||||
sb.append('+');
|
||||
urlEncode(group, sb);
|
||||
if (StringUtils.isNotEmpty(tenant)) {
|
||||
if (StringUtils.isNotEmpty(datumStr)) {
|
||||
sb.append('+');
|
||||
urlEncode(tenant, sb);
|
||||
urlEncode(datumStr, sb);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
static public String getKey(String dataId, String group, String datumStr) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
urlEncode(dataId, sb);
|
||||
sb.append('+');
|
||||
urlEncode(group, sb);
|
||||
sb.append('+');
|
||||
urlEncode(datumStr, sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,8 @@ import static com.alibaba.nacos.core.utils.SystemUtils.LOCAL_IP;
|
||||
*/
|
||||
public class ApplicationInfo {
|
||||
|
||||
private static final long LOCK_EXPIRE_DURATION = 30 * 1000;
|
||||
private static final long RECENTLY_DURATION = 24 * 60 * 60 * 1000;
|
||||
private static final long LOCK_EXPIRE_DURATION = 30 * 1000L;
|
||||
private static final long RECENTLY_DURATION = 24 * 60 * 60 * 1000L;
|
||||
|
||||
private String appName;
|
||||
|
||||
|
@ -37,10 +37,12 @@ import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
@Service
|
||||
public class AggrWhitelist {
|
||||
|
||||
public static final String AGGRIDS_METADATA = "com.alibaba.nacos.metadata.aggrIDs";
|
||||
|
||||
/**
|
||||
* 判断指定的dataId是否在聚合dataId白名单。
|
||||
*/
|
||||
static public boolean isAggrDataId(String dataId) {
|
||||
public static boolean isAggrDataId(String dataId) {
|
||||
if (null == dataId) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
@ -56,7 +58,7 @@ public class AggrWhitelist {
|
||||
/**
|
||||
* 传入内容,重新加载聚合白名单
|
||||
*/
|
||||
static public void load(String content) {
|
||||
public static void load(String content) {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
fatalLog.error("aggr dataId whitelist is blank.");
|
||||
return;
|
||||
@ -83,14 +85,12 @@ public class AggrWhitelist {
|
||||
AGGR_DATAID_WHITELIST.set(list);
|
||||
}
|
||||
|
||||
static public List<Pattern> getWhiteList() {
|
||||
public static List<Pattern> getWhiteList() {
|
||||
return AGGR_DATAID_WHITELIST.get();
|
||||
}
|
||||
|
||||
// =======================
|
||||
|
||||
static public final String AGGRIDS_METADATA = "com.alibaba.nacos.metadata.aggrIDs";
|
||||
|
||||
static final AtomicReference<List<Pattern>> AGGR_DATAID_WHITELIST = new AtomicReference<List<Pattern>>(
|
||||
new ArrayList<Pattern>());
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
|
||||
sqlFileIn = new FileInputStream(file);
|
||||
}
|
||||
|
||||
StringBuffer sqlSb = new StringBuffer();
|
||||
StringBuilder sqlSb = new StringBuilder();
|
||||
byte[] buff = new byte[1024];
|
||||
int byteRead = 0;
|
||||
while ((byteRead = sqlFileIn.read(buff)) != -1) {
|
||||
|
@ -22,37 +22,32 @@ package com.alibaba.nacos.config.server.utils;
|
||||
*/
|
||||
public class GroupKey {
|
||||
|
||||
static public String getKey(String dataId, String group) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
urlEncode(dataId, sb);
|
||||
sb.append('+');
|
||||
urlEncode(group, sb);
|
||||
return sb.toString();
|
||||
public static String getKey(String dataId, String group) {
|
||||
return doGetKey(dataId, group, "");
|
||||
}
|
||||
|
||||
static public String getKeyTenant(String dataId, String group, String tenant) {
|
||||
public static String getKeyTenant(String dataId, String group, String tenant) {
|
||||
return doGetKey(dataId, group, tenant);
|
||||
}
|
||||
|
||||
public static String getKey(String dataId, String group, String datumStr) {
|
||||
return doGetKey(dataId, group, datumStr);
|
||||
}
|
||||
|
||||
private static String doGetKey(String dataId, String group, String datumStr) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
urlEncode(dataId, sb);
|
||||
sb.append('+');
|
||||
urlEncode(group, sb);
|
||||
if (StringUtils.isNotEmpty(tenant)) {
|
||||
if (StringUtils.isNotEmpty(datumStr)) {
|
||||
sb.append('+');
|
||||
urlEncode(tenant, sb);
|
||||
urlEncode(datumStr, sb);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
static public String getKey(String dataId, String group, String datumStr) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
urlEncode(dataId, sb);
|
||||
sb.append('+');
|
||||
urlEncode(group, sb);
|
||||
sb.append('+');
|
||||
urlEncode(datumStr, sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
static public String[] parseKey(String groupKey) {
|
||||
public static String[] parseKey(String groupKey) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String dataId = null;
|
||||
String group = null;
|
||||
@ -97,7 +92,7 @@ public class GroupKey {
|
||||
}
|
||||
}
|
||||
|
||||
return new String[] {dataId, group, tenant};
|
||||
return new String[]{dataId, group, tenant};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,10 +16,9 @@
|
||||
package com.alibaba.nacos.config.server.utils;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@ -31,10 +30,10 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
@SuppressWarnings("PMD.ClassNamingShouldBeCamelRule")
|
||||
public class MD5 {
|
||||
private static char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
private final static int DIGITS_COUNT = 16;
|
||||
private final static int DIGITS_CHAR_SIZE = 32;
|
||||
private static final int DIGITS_COUNT = 16;
|
||||
private static final int DIGITS_CHAR_SIZE = 32;
|
||||
|
||||
private static Map<Character, Integer> rDigits = new HashMap<Character, Integer>(16);
|
||||
private static Map<Character, Integer> rDigits = Maps.newHashMapWithExpectedSize(16);
|
||||
|
||||
static {
|
||||
for (int i = 0; i < digits.length; ++i) {
|
||||
|
@ -37,7 +37,7 @@ public class RegexParser {
|
||||
if (regex == null) {
|
||||
throw new NullPointerException("regex string can't be null");
|
||||
}
|
||||
StringBuffer result = new StringBuffer();
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("^");
|
||||
for (int i = 0; i < regex.length(); i++) {
|
||||
char ch = regex.charAt(i);
|
||||
|
@ -33,7 +33,7 @@ public class TimeUtils {
|
||||
return new Timestamp(date.getTime());
|
||||
}
|
||||
|
||||
static public String getCurrentTimeStr() {
|
||||
public static String getCurrentTimeStr() {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(new Date());
|
||||
FastDateFormat format = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");
|
||||
|
@ -59,7 +59,7 @@ public class TimeoutUtils {
|
||||
/**
|
||||
* 累计总的时间
|
||||
*
|
||||
* @param timeout
|
||||
* @param time
|
||||
*/
|
||||
public void addTotalTime(long time) {
|
||||
totalTime.addAndGet(time);
|
||||
|
@ -27,7 +27,7 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public class UrlAnalysisUtils {
|
||||
|
||||
private static Pattern urlPattern = Pattern.compile("^(\\w+://)?([\\w\\.]+:)(\\d*)?(\\??.*)");
|
||||
private static final Pattern URL_PATTERN = Pattern.compile("^(\\w+://)?([\\w\\.]+:)(\\d*)?(\\??.*)");
|
||||
|
||||
public static String getContentIdentity(String content) {
|
||||
|
||||
@ -35,7 +35,7 @@ public class UrlAnalysisUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
Matcher matcher = urlPattern.matcher(content);
|
||||
Matcher matcher = URL_PATTERN.matcher(content);
|
||||
StringBuilder buf = new StringBuilder();
|
||||
if (matcher.find()) {
|
||||
String scheme = matcher.group(1);
|
||||
|
@ -121,11 +121,8 @@ public class SystemUtils {
|
||||
|
||||
public static List<String> readClusterConf() throws IOException {
|
||||
List<String> instanceList = new ArrayList<String>();
|
||||
Reader reader = null;
|
||||
|
||||
try {
|
||||
reader = new InputStreamReader(new FileInputStream(new File(CLUSTER_CONF_FILE_PATH)),
|
||||
StandardCharsets.UTF_8);
|
||||
try(Reader reader = new InputStreamReader(new FileInputStream(new File(CLUSTER_CONF_FILE_PATH)),
|
||||
StandardCharsets.UTF_8)) {
|
||||
List<String> lines = IoUtils.readLines(reader);
|
||||
String comment = "#";
|
||||
for (String line : lines) {
|
||||
@ -142,19 +139,13 @@ public class SystemUtils {
|
||||
int multiIndex = instance.indexOf(Constants.COMMA_DIVISION);
|
||||
if (multiIndex > 0) {
|
||||
// support the format: ip1:port,ip2:port # multi inline
|
||||
for (String ins : instance.split(Constants.COMMA_DIVISION)) {
|
||||
instanceList.add(ins);
|
||||
}
|
||||
instanceList.addAll(Arrays.asList(instance.split(Constants.COMMA_DIVISION)));
|
||||
} else {
|
||||
//support the format: 192.168.71.52:8848
|
||||
instanceList.add(instance);
|
||||
}
|
||||
}
|
||||
return instanceList;
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ public class RandomUtils {
|
||||
private static Random rd = new Random();
|
||||
private static int UNICODE_START = 19968;
|
||||
private static int UNICODE_END = 40864;
|
||||
private static final String STRING_POOL = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
private RandomUtils() {
|
||||
}
|
||||
@ -132,13 +133,12 @@ public class RandomUtils {
|
||||
}
|
||||
|
||||
public static String getRandomString(int length) {
|
||||
StringBuffer buffer = new StringBuffer("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Random random = new Random();
|
||||
int range = buffer.length();
|
||||
int range = STRING_POOL.length();
|
||||
|
||||
for(int i = 0; i < length; ++i) {
|
||||
sb.append(buffer.charAt(random.nextInt(range)));
|
||||
sb.append(STRING_POOL.charAt(random.nextInt(range)));
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
|
Loading…
Reference in New Issue
Block a user