Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nkorange committed Jun 28, 2019
2 parents fbb9ec8 + 6312a32 commit 88e1139
Show file tree
Hide file tree
Showing 20 changed files with 56 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class NacosConfigService implements ConfigService {

private static final Logger LOGGER = LogUtils.logger(NacosConfigService.class);

private final long POST_TIMEOUT = 3000L;
private static final long POST_TIMEOUT = 3000L;

private static final String EMPTY = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class Limiter {

private static final Logger LOGGER = LogUtils.logger(Limiter.class);

private static int CAPACITY_SIZE = 1000;
private static int LIMIT_TIME = 1000;
private static final int CAPACITY_SIZE = 1000;
private static final int LIMIT_TIME = 1000;
private static Cache<String, RateLimiter> cache = CacheBuilder.newBuilder()
.initialCapacity(CAPACITY_SIZE).expireAfterAccess(1, TimeUnit.MINUTES)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ public static String signWithhmacSHA1Encrypt(String encryptText, String encryptK
}
}

private static String GROUP_KEY = "group";
private static String TENANT_KEY = "tenant";
private static final String GROUP_KEY = "group";
private static final String TENANT_KEY = "tenant";
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static Boolean isMultiInstance() {
}

private static Boolean isMultiInstance = false;
private static String TRUE = "true";
private static final String TRUE = "true";
private static final Logger LOGGER = LogUtils.logger(JVMUtil.class);

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public class BeatReactor {

private ScheduledExecutorService executorService;

private volatile long clientBeatInterval = 5 * 1000;

private NamingProxy serverProxy;

public final Map<String, BeatInfo> dom2Beat = new ConcurrentHashMap<String, BeatInfo>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public ServiceInfo processServiceJSON(String json) {
return serviceInfo;
}

private ServiceInfo getSerivceInfo0(String serviceName, String clusters) {
private ServiceInfo getServiceInfo0(String serviceName, String clusters) {

String key = ServiceInfo.getKey(serviceName, clusters);

Expand All @@ -218,7 +218,7 @@ public ServiceInfo getServiceInfo(final String serviceName, final String cluster
return failoverReactor.getService(key);
}

ServiceInfo serviceObj = getSerivceInfo0(serviceName, clusters);
ServiceInfo serviceObj = getServiceInfo0(serviceName, clusters);

if (null == serviceObj) {
serviceObj = new ServiceInfo(serviceName, clusters);
Expand Down Expand Up @@ -264,7 +264,7 @@ public void scheduleUpdateIfAbsent(String serviceName, String clusters) {
}

public void updateServiceNow(String serviceName, String clusters) {
ServiceInfo oldService = getSerivceInfo0(serviceName, clusters);
ServiceInfo oldService = getServiceInfo0(serviceName, clusters);
try {

String result = serverProxy.queryList(serviceName, clusters, pushReceiver.getUDPPort(), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ public Ref(List<Pair<T>> itemsWithWeight) {
}

public void refresh() {
Double originWeightSum = (double)0;
Double originWeightSum = (double) 0;

for (Pair<T> item : itemsWithWeight) {

double weight = item.weight();
//ignore item which weight is zero.see test_randomWithWeight_weight0 in ChooserTest
if (!(weight > 0)) {
if (weight <= 0) {
continue;
}

Expand All @@ -124,7 +124,7 @@ public void refresh() {
for (Pair<T> item : itemsWithWeight) {
double singleWeight = item.weight();
//ignore item which weight is zero.see test_randomWithWeight_weight0 in ChooserTest
if (!(singleWeight > 0)) {
if (singleWeight <= 0) {
continue;
}
exactWeights[index++] = singleWeight / originWeightSum;
Expand All @@ -138,10 +138,10 @@ public void refresh() {
}

double doublePrecisionDelta = 0.0001;
if (index != 0 && !(Math.abs(weights[index - 1] - 1) < doublePrecisionDelta)) {
throw new IllegalStateException(
"Cumulative Weight caculate wrong , the sum of probabilities does not equals 1.");
if (index == 0 || (Math.abs(weights[index - 1] - 1) < doublePrecisionDelta)) {
return;
}
throw new IllegalStateException("Cumulative Weight caculate wrong , the sum of probabilities does not equals 1.");
}

@Override
Expand All @@ -164,7 +164,7 @@ public boolean equals(Object other) {
if (!(other.getClass().getGenericInterfaces()[0].equals(this.getClass().getGenericInterfaces()[0]))) {
return false;
}
Ref<T> otherRef = (Ref<T>)other;
Ref<T> otherRef = (Ref<T>) other;
if (itemsWithWeight == null) {
if (otherRef.itemsWithWeight != null) {
return false;
Expand Down Expand Up @@ -197,7 +197,7 @@ public boolean equals(Object other) {
return false;
}

Chooser otherChooser = (Chooser)other;
Chooser otherChooser = (Chooser) other;
if (this.uniqueKey == null) {
if (otherChooser.getUniqueKey() != null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class CollectionUtils {
/**
* Constant to avoid repeated object creation
*/
private static Integer INTEGER_ONE = 1;
private static final Integer INTEGER_ONE = 1;

/**
* <code>CollectionUtils</code> should not normally be instantiated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.zip.GZIPInputStream;

import static com.alibaba.nacos.client.utils.LogUtils.NAMING_LOGGER;
import static org.apache.commons.lang3.CharEncoding.UTF_8;

/**
* @author nkorange
Expand All @@ -34,7 +35,7 @@ public class IoUtils {
static public String toString(InputStream input, String encoding) {

try {
return (null == encoding) ? toString(new InputStreamReader(input, "UTF-8"))
return (null == encoding) ? toString(new InputStreamReader(input, UTF_8))
: toString(new InputStreamReader(input, encoding));
} catch (Exception e) {
NAMING_LOGGER.error("NA", "read input failed.", e);
Expand Down Expand Up @@ -178,15 +179,22 @@ public static byte[] tryDecompress(byte[] raw) throws Exception {
if (!isGzipStream(raw)) {
return raw;
}
GZIPInputStream gis = null;
ByteArrayOutputStream out = null;

GZIPInputStream gis
= new GZIPInputStream(new ByteArrayInputStream(raw));
ByteArrayOutputStream out
= new ByteArrayOutputStream();

IoUtils.copy(gis, out);

return out.toByteArray();
try {
gis = new GZIPInputStream(new ByteArrayInputStream(raw));
out = new ByteArrayOutputStream();
IoUtils.copy(gis, out);
return out.toByteArray();
} finally {
if (out != null) {
out.close();
}
if (gis != null) {
gis.close();
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class RandomUtils {
/**
* An instance of {@link JvmRandom}.
*/
public static final Random JVM_RANDOM = new JvmRandom();
private static final Random JVM_RANDOM = new JvmRandom();

// should be possible for JVM_RANDOM?
// public static void nextBytes(byte[]) {
Expand Down
31 changes: 11 additions & 20 deletions client/src/main/java/com/alibaba/nacos/client/utils/IPUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,22 @@
@SuppressWarnings("PMD.ClassNamingShouldBeCamelRule")
public class IPUtil {

public static boolean isIPV4(String addr) {
if (null == addr) {
return false;
}
String rexp = "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$";
private static final Pattern IPV4_PATTERN = Pattern.compile("^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$");
private static final Pattern IPV6_PATTERN = Pattern.compile("^([\\da-fA-F]{1,4}:){7}[\\da-fA-F]{1,4}$");

Pattern pat = Pattern.compile(rexp);

Matcher mat = pat.matcher(addr);

boolean ipAddress = mat.find();
return ipAddress;
public static boolean isIPV4(String addr) {
return isMatch(addr, IPV4_PATTERN);
}

public static boolean isIPV6(String addr) {
if (null == addr) {
return isMatch(addr, IPV6_PATTERN);
}

private static boolean isMatch(String data, Pattern pattern) {
if (StringUtils.isBlank(data)) {
return false;
}
String rexp = "^([\\da-fA-F]{1,4}:){7}[\\da-fA-F]{1,4}$";

Pattern pat = Pattern.compile(rexp);

Matcher mat = pat.matcher(addr);

boolean ipAddress = mat.find();
return ipAddress;
Matcher mat = pattern.matcher(data);
return mat.find();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@SuppressWarnings("PMD.ClassNamingShouldBeCamelRule")
public class JSONUtils {

static ObjectMapper mapper = new ObjectMapper();
private static ObjectMapper mapper = new ObjectMapper();

static {
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
public class StringUtils {

public static final int INDEX_NOT_FOUND = -1;
private static final int INDEX_NOT_FOUND = -1;

public static final String EMPTY = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class CmdbProvider implements CmdbReader, CmdbWriter {

private CmdbService cmdbService;

ServiceLoader<CmdbService> serviceLoader = ServiceLoader.load(CmdbService.class);
private ServiceLoader<CmdbService> serviceLoader = ServiceLoader.load(CmdbService.class);

private Map<String, Map<String, Entity>> entityMap = new ConcurrentHashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
public class UtilsAndCommons {

public static final String NACOS_SERVER_VERSION = "/v1";
private static final String NACOS_SERVER_VERSION = "/v1";

public static final String NACOS_CMDB_CONTEXT = NACOS_SERVER_VERSION + "/cmdb";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
* @author Nacos
*/
public class ResponseMonitor {
static AtomicLong[] getConfigCountDetail = new AtomicLong[8];
static AtomicLong getConfigCount = new AtomicLong();
private static AtomicLong[] getConfigCountDetail = new AtomicLong[8];
private static AtomicLong getConfigCount = new AtomicLong();
private static final int MS_50 = 50;
private static final int MS_100 = 100;
private static final int MS_200 = 200;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void run() {
if (NetUtils.localServer().equals(member.getKey())) {
continue;
}
NamingProxy.syncChecksums(keyChecksums, member.getKey());
NamingProxy.syncCheckSums(keyChecksums, member.getKey());
}
} catch (Exception e) {
Loggers.EPHEMERAL.error("timed sync task failed.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public class HttpClient {
builder2.setMaxConnPerRoute(-1);
builder2.setMaxConnTotal(-1);
builder2.disableAutomaticRetries();
// builder2.disableConnectionState()

postClient = builder2.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class NamingProxy {

private static final String TIMESTAMP_SYNC_URL = "/distro/checksum";

public static void syncChecksums(Map<String, String> checksumMap, String server) {
public static void syncCheckSums(Map<String, String> checksumMap, String server) {

try {
Map<String, String> headers = new HashMap<>(128);
Expand Down Expand Up @@ -235,12 +235,4 @@ public String toUrl() {
return sb.toString();
}
}

public static void main(String[] args) throws Exception {

String key = "com.alibaba.nacos.naming.iplist.ephemeral.public##DEFAULT_GROUP@@test.10";
List<String> keys = new ArrayList<>();
keys.add(key);
getData(keys, "11.239.112.161:8848");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void refreshMetrics() {
}

@Scheduled(cron = "0/15 * * * * ?")
public void collectmetrics() {
public void collectMetrics() {
int serviceCount = serviceManager.getServiceCount();
MetricsMonitor.getDomCountMonitor().set(serviceCount);

Expand Down

0 comments on commit 88e1139

Please sign in to comment.