Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
IanCao committed Jun 13, 2019
1 parent dbbb456 commit a98db44
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public class UtilAndComs {

public static final String VERSION = "Nacos-Java-Client:v1.0.1";

public static String WEB_CONTEXT = "/nacos";
public static final String WEB_CONTEXT = "/nacos";

public static String NACOS_URL_BASE = WEB_CONTEXT + "/v1/ns";
public static final String NACOS_URL_BASE = WEB_CONTEXT + "/v1/ns";

public static String NACOS_URL_INSTANCE = NACOS_URL_BASE + "/instance";
public static final String NACOS_URL_INSTANCE = NACOS_URL_BASE + "/instance";

public static String NACOS_URL_SERVICE = NACOS_URL_BASE + "/service";
public static final String NACOS_URL_SERVICE = NACOS_URL_BASE + "/service";

public static final String ENCODING = "UTF-8";

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

private Set<String> entityTypeSet = new HashSet<>();

private List<EntityEvent> eventList = new ArrayList<>();

private long eventTimestamp = System.currentTimeMillis();

public CmdbProvider() throws NacosException {
Expand Down
20 changes: 12 additions & 8 deletions common/src/main/java/com/alibaba/nacos/common/util/IoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,29 @@
public class IoUtils {

public static byte[] tryDecompress(InputStream raw) throws Exception {

GZIPInputStream gis = null;
ByteArrayOutputStream out = null;
try {
GZIPInputStream gis
= new GZIPInputStream(raw);
ByteArrayOutputStream out
= new ByteArrayOutputStream();

gis = new GZIPInputStream(raw);
out = new ByteArrayOutputStream();
IOUtils.copy(gis, out);

return out.toByteArray();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (out != null) {
out.close();
}
if (gis != null) {
gis.close();
}
}

return null;
}

static private BufferedReader toBufferedReader(Reader reader) {
return reader instanceof BufferedReader ? (BufferedReader)reader : new BufferedReader(
return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(
reader);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ public void run() {

class NotifyTaskQueueMonitorTask implements Runnable {
final private AsyncNotifyService notifySingleService;
private AtomicInteger notifyTask = new AtomicInteger();


NotifyTaskQueueMonitorTask(AsyncNotifyService notifySingleService) {
this.notifySingleService = notifySingleService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public class DiskServiceUnitTest {

private DiskUtil diskService;

private ServletContext servletContext;

private File tempFile;

private String path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ public static InetAddress findFirstNonLoopbackAddress() {
log.info("Testing interface: " + ifc.getDisplayName());
if (ifc.getIndex() < lowest || result == null) {
lowest = ifc.getIndex();
}
else if (result != null) {
} else if (result != null) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public class SystemUtils {
/**
* Standalone mode or not
*/
public static boolean STANDALONE_MODE = Boolean.getBoolean(STANDALONE_MODE_PROPERTY_NAME);
public static final boolean STANDALONE_MODE = Boolean.getBoolean(STANDALONE_MODE_PROPERTY_NAME);

public static final String STANDALONE_MODE_ALONE = "standalone";
public static final String STANDALONE_MODE_CLUSTER = "cluster";

/**
* server
*/
public static String FUNCTION_MODE = System.getProperty(FUNCTION_MODE_PROPERTY_NAME);
public static final String FUNCTION_MODE = System.getProperty(FUNCTION_MODE_PROPERTY_NAME);

public static final String FUNCTION_MODE_CONFIG = "config";
public static final String FUNCTION_MODE_NAMING = "naming";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class ServerListManager {

private Set<String> liveSites = new HashSet<>();

public final String LOCALHOST_SITE = UtilsAndCommons.UNKNOWN_SITE;
private final static String LOCALHOST_SITE = UtilsAndCommons.UNKNOWN_SITE;

private long lastHealthServerMillis = 0L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.util.HashMap;
import java.util.Map;

import static org.apache.commons.lang3.CharEncoding.UTF_8;

/**
* Use FastJSON to serialize data
*
Expand All @@ -44,7 +46,7 @@ public <T> byte[] serialize(T data) {
@Override
public <T> T deserialize(byte[] data, Class<T> clazz) {
try {
return JSON.parseObject(new String(data, "UTF-8"), clazz);
return JSON.parseObject(new String(data, UTF_8), clazz);
} catch (UnsupportedEncodingException e) {
return null;
}
Expand All @@ -53,7 +55,7 @@ public <T> T deserialize(byte[] data, Class<T> clazz) {
@Override
public <T> T deserialize(byte[] data, TypeReference<T> clazz) {
try {
String dataString = new String(data, "UTF-8");
String dataString = new String(data, UTF_8);
return JSON.parseObject(dataString, clazz);
} catch (Exception e) {
Loggers.SRV_LOG.error("deserialize data failed.", e);
Expand All @@ -64,7 +66,7 @@ public <T> T deserialize(byte[] data, TypeReference<T> clazz) {
@Override
public <T extends Record> Map<String, Datum<T>> deserializeMap(byte[] data, Class<T> clazz) {
try {
String dataString = new String(data, "UTF-8");
String dataString = new String(data, UTF_8);
Map<String, JSONObject> dataMap = JSON.parseObject(dataString, new TypeReference<Map<String, JSONObject>>() {
});

Expand Down
12 changes: 6 additions & 6 deletions naming/src/main/java/com/alibaba/nacos/naming/core/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public class Instance extends com.alibaba.nacos.api.naming.pojo.Instance implements Comparable {

private static final double MAX_WEIGHT_VALUE = 10000.0D;
private static final double MIN_POSTIVE_WEIGHT_VALUE = 0.01D;
private static final double MIN_POSITIVE_WEIGHT_VALUE = 0.01D;
private static final double MIN_WEIGHT_VALUE = 0.00D;

private volatile long lastBeat = System.currentTimeMillis();
Expand All @@ -48,13 +48,13 @@ public class Instance extends com.alibaba.nacos.api.naming.pojo.Instance impleme

private String app;

public static final Pattern IP_PATTERN
private static final Pattern IP_PATTERN
= Pattern.compile("(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}):?(\\d{1,5})?");

public static final Pattern ONLY_DIGIT_AND_DOT
private static final Pattern ONLY_DIGIT_AND_DOT
= Pattern.compile("(\\d|\\.)+");

public static final String SPLITER = "_";
private static final String SPLITER = "_";

public Instance() {
}
Expand Down Expand Up @@ -191,8 +191,8 @@ public static Instance fromJSON(String json) {
ip.setWeight(MAX_WEIGHT_VALUE);
}

if (ip.getWeight() < MIN_POSTIVE_WEIGHT_VALUE && ip.getWeight() > MIN_WEIGHT_VALUE) {
ip.setWeight(MIN_POSTIVE_WEIGHT_VALUE);
if (ip.getWeight() < MIN_POSITIVE_WEIGHT_VALUE && ip.getWeight() > MIN_WEIGHT_VALUE) {
ip.setWeight(MIN_POSITIVE_WEIGHT_VALUE);
} else if (ip.getWeight() < MIN_WEIGHT_VALUE) {
ip.setWeight(0.0D);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class HttpHealthCheckProcessor implements HealthCheckProcessor {

private static AsyncHttpClient asyncHttpClient;

public static final int CONNECT_TIMEOUT_MS = 500;
private static final int CONNECT_TIMEOUT_MS = 500;

static {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public void process(HealthCheckTask task) {
if (CollectionUtils.isEmpty(ips)) {
return;
}
Service service = task.getCluster().getService();

for (Instance ip : ips) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ public class HttpClient {

private static CloseableHttpClient postClient;

private static PoolingHttpClientConnectionManager connectionManager;

static {
AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder();
builder.setMaximumConnectionsTotal(-1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ public void run() {
try {
int serviceCount = serviceManager.getServiceCount();
int ipCount = serviceManager.getInstanceCount();
long maxPushMaxCost = getMaxPushCost();
long maxPushCost = getMaxPushCost();
long avgPushCost = getAvgPushCost();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class PushService {
@Autowired
private SwitchDomain switchDomain;

public static final long ACK_TIMEOUT_NANOS = TimeUnit.SECONDS.toNanos(10L);
private static final long ACK_TIMEOUT_NANOS = TimeUnit.SECONDS.toNanos(10L);

private static final int MAX_RETRY_TIMES = 1;

Expand Down

0 comments on commit a98db44

Please sign in to comment.