Skip to content

Commit

Permalink
optimize some code style (#4006)
Browse files Browse the repository at this point in the history
* optimize constant naming style
* optimize some code style
Signed-off-by: jimin.jm <[email protected]>
  • Loading branch information
slievrly authored and ralf0131 committed May 12, 2019
1 parent 8e3675e commit a1e5c8e
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public static boolean matchIpRange(String pattern, String host, int port) throws

host = inetAddress.getHostAddress();

String[] ip_address = host.split(splitCharacter);
String[] ipAddress = host.split(splitCharacter);
if (pattern.equals(host)) {
return true;
}
Expand All @@ -442,7 +442,7 @@ public static boolean matchIpRange(String pattern, String host, int port) throws
}
}
for (int i = 0; i < mask.length; i++) {
if (mask[i].equals("*") || mask[i].equals(ip_address[i])) {
if (mask[i].equals("*") || mask[i].equals(ipAddress[i])) {
continue;
} else if (mask[i].contains("-")) {
String[] rangeNumStrs = mask[i].split("-");
Expand All @@ -451,13 +451,13 @@ public static boolean matchIpRange(String pattern, String host, int port) throws
}
Integer min = getNumOfIpSegment(rangeNumStrs[0], isIpv4);
Integer max = getNumOfIpSegment(rangeNumStrs[1], isIpv4);
Integer ip = getNumOfIpSegment(ip_address[i], isIpv4);
Integer ip = getNumOfIpSegment(ipAddress[i], isIpv4);
if (ip < min || ip > max) {
return false;
}
} else if ("0".equals(ip_address[i]) && ("0".equals(mask[i]) || "00".equals(mask[i]) || "000".equals(mask[i]) || "0000".equals(mask[i]))) {
} else if ("0".equals(ipAddress[i]) && ("0".equals(mask[i]) || "00".equals(mask[i]) || "000".equals(mask[i]) || "0000".equals(mask[i]))) {
continue;
} else if (!mask[i].equals(ip_address[i])) {
} else if (!mask[i].equals(ipAddress[i])) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public abstract class AbstractMetadataReport implements MetadataReport {
boolean syncReport;
// Local disk cache file
File file;
private AtomicBoolean INIT = new AtomicBoolean(false);
private AtomicBoolean initialized = new AtomicBoolean(false);
public MetadataReportRetry metadataReportRetry;

public AbstractMetadataReport(URL reportServerURL) {
Expand All @@ -90,7 +90,7 @@ public AbstractMetadataReport(URL reportServerURL) {
}
}
// if this file exist, firstly delete it.
if (!INIT.getAndSet(true) && file.exists()) {
if (!initialized.getAndSet(true) && file.exists()) {
file.delete();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ private List<MetricObject> getThreadPoolMessage() {
}

private MetricObject value2MetricObject(String metric, Integer value, MetricLevel level) {
if (metric == null || value == null || level == null)
if (metric == null || value == null || level == null) {
return null;
}

return new MetricObject
.Builder(metric)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public String execute(CommandContext commandContext, String[] args) {
public String listProvider() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("As Provider side:" + System.lineSeparator());
Collection<ProviderModel> ProviderModelList = ApplicationModel.allProviderModels();
Collection<ProviderModel> providerModelList = ApplicationModel.allProviderModels();

TTable tTable = new TTable(new TTable.ColumnDefine[]{
new TTable.ColumnDefine(TTable.Align.MIDDLE),
Expand All @@ -56,7 +56,7 @@ public String listProvider() {
tTable.addRow("Provider Service Name", "PUB");

//Content
for (ProviderModel providerModel : ProviderModelList) {
for (ProviderModel providerModel : providerModelList) {
tTable.addRow(providerModel.getServiceName(), isRegistered(providerModel.getServiceName()) ? "Y" : "N");
}
stringBuilder.append(tTable.rendering());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,18 +295,18 @@ private URL getRegisteredProviderUrl(final URL providerUrl, final URL registryUr
MONITOR_KEY, BIND_IP_KEY, BIND_PORT_KEY, QOS_ENABLE, QOS_PORT, ACCEPT_FOREIGN_IP, VALIDATION_KEY,
INTERFACES);
} else {
String extra_keys = registryUrl.getParameter(EXTRA_KEYS_KEY, "");
String extraKeys = registryUrl.getParameter(EXTRA_KEYS_KEY, "");
// if path is not the same as interface name then we should keep INTERFACE_KEY,
// otherwise, the registry structure of zookeeper would be '/dubbo/path/providers',
// but what we expect is '/dubbo/interface/providers'
if (!providerUrl.getPath().equals(providerUrl.getParameter(Constants.INTERFACE_KEY))) {
if (StringUtils.isNotEmpty(extra_keys)) {
extra_keys += ",";
if (StringUtils.isNotEmpty(extraKeys)) {
extraKeys += ",";
}
extra_keys += Constants.INTERFACE_KEY;
extraKeys += Constants.INTERFACE_KEY;
}
String[] paramsToRegistry = getParamsToRegistry(DEFAULT_REGISTER_PROVIDER_KEYS
, Constants.COMMA_SPLIT_PATTERN.split(extra_keys));
, Constants.COMMA_SPLIT_PATTERN.split(extraKeys));
return URL.valueOf(providerUrl, paramsToRegistry, providerUrl.getParameter(METHODS_KEY, (String[]) null));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class NacosRegistryFactory extends AbstractRegistryFactory {

private final Logger logger = LoggerFactory.getLogger(getClass());

@Override
protected Registry createRegistry(URL url) {
return new NacosRegistry(url, buildNamingService(url));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ public List<String> getChildren(String path) {
int index = len, count = 0;
if (key.length() > len) {
for (; (index = key.indexOf(Constants.PATH_SEPARATOR, index)) != -1; ++index) {
if (count++ > 1) break;
if (count++ > 1) {
break;
}
}
}
return count == 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept
String methodName = invocation.getMethodName();
int max = invoker.getUrl().getMethodParameter(methodName, Constants.ACTIVES_KEY, 0);
RpcStatus count = RpcStatus.getStatus(invoker.getUrl(), invocation.getMethodName());
if (!count.beginCount(url, methodName, max)) {
if (!RpcStatus.beginCount(url, methodName, max)) {
long timeout = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, 0);
long start = System.currentTimeMillis();
long remain = timeout;
synchronized (count) {
while (!count.beginCount(url, methodName, max)) {
while (!RpcStatus.beginCount(url, methodName, max)) {
try {
count.wait(remain);
} catch (InterruptedException e) {
Expand All @@ -79,7 +79,7 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept
isSuccess = false;
throw t;
} finally {
count.endCount(url, methodName, System.currentTimeMillis() - begin, isSuccess);
RpcStatus.endCount(url, methodName, System.currentTimeMillis() - begin, isSuccess);
if (max > 0) {
synchronized (count) {
count.notifyAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ public <T> T readObject(Class<T> cls, Type type) throws IOException, ClassNotFou

private String readLine() throws IOException {
String line = reader.readLine();
if (line == null || line.trim().length() == 0) throw new EOFException();
if (line == null || line.trim().length() == 0) {
throw new EOFException();
}
return line;
}

Expand Down

0 comments on commit a1e5c8e

Please sign in to comment.