You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hugegraph.apache.org by ji...@apache.org on 2022/11/09 09:50:36 UTC
[incubator-hugegraph-commons] branch master updated: refact: address some code alert (#115)
This is an automated email from the ASF dual-hosted git repository.
jin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph-commons.git
The following commit(s) were added to refs/heads/master by this push:
new caa4b26 refact: address some code alert (#115)
caa4b26 is described below
commit caa4b26a985fd2c8529673d0865b2cb05ab6ff8f
Author: imbajin <ji...@apache.org>
AuthorDate: Wed Nov 9 17:50:27 2022 +0800
refact: address some code alert (#115)
---
.gitignore | 1 +
.../org/apache/hugegraph/config/HugeConfig.java | 8 ++--
.../org/apache/hugegraph/config/OptionChecker.java | 2 -
.../org/apache/hugegraph/func/TriFunction.java | 2 +-
.../java/org/apache/hugegraph/perf/PerfUtil.java | 52 +++++++++++-----------
.../java/org/apache/hugegraph/perf/Stopwatch.java | 17 ++++---
.../apache/hugegraph/rest/AbstractRestClient.java | 51 +++++++++++----------
.../java/org/apache/hugegraph/testutil/Assert.java | 3 +-
.../org/apache/hugegraph/util/VersionUtil.java | 4 +-
.../org/apache/hugegraph/config/RpcOptions.java | 5 +--
.../apache/hugegraph/rpc/RpcClientProvider.java | 1 +
.../apache/hugegraph/rpc/RpcConsumerConfig.java | 6 +--
pom.xml | 7 +--
13 files changed, 77 insertions(+), 82 deletions(-)
diff --git a/.gitignore b/.gitignore
index f7bcdbf..05e7e3a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -81,3 +81,4 @@ hs_err_pid*
.mtj.tmp/
# blueJ files
*.ctxt
+.flattened-pom.xml
diff --git a/hugegraph-common/src/main/java/org/apache/hugegraph/config/HugeConfig.java b/hugegraph-common/src/main/java/org/apache/hugegraph/config/HugeConfig.java
index b25153d..17088ea 100644
--- a/hugegraph-common/src/main/java/org/apache/hugegraph/config/HugeConfig.java
+++ b/hugegraph-common/src/main/java/org/apache/hugegraph/config/HugeConfig.java
@@ -186,11 +186,9 @@ public class HugeConfig extends PropertiesConfiguration {
case "yml":
case "yaml":
Parameters params = new Parameters();
- FileBasedConfigurationBuilder<FileBasedConfiguration>
- builder = new FileBasedConfigurationBuilder(
- YAMLConfiguration.class)
- .configure(params.fileBased()
- .setFile(configFile));
+ FileBasedConfigurationBuilder<FileBasedConfiguration> builder =
+ new FileBasedConfigurationBuilder(YAMLConfiguration.class)
+ .configure(params.fileBased().setFile(configFile));
config = builder.getConfiguration();
break;
case "xml":
diff --git a/hugegraph-common/src/main/java/org/apache/hugegraph/config/OptionChecker.java b/hugegraph-common/src/main/java/org/apache/hugegraph/config/OptionChecker.java
index 8676702..0e795ff 100644
--- a/hugegraph-common/src/main/java/org/apache/hugegraph/config/OptionChecker.java
+++ b/hugegraph-common/src/main/java/org/apache/hugegraph/config/OptionChecker.java
@@ -24,8 +24,6 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
-import javax.annotation.Nullable;
-
import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Predicate;
diff --git a/hugegraph-common/src/main/java/org/apache/hugegraph/func/TriFunction.java b/hugegraph-common/src/main/java/org/apache/hugegraph/func/TriFunction.java
index d84c26f..0e5fbb4 100644
--- a/hugegraph-common/src/main/java/org/apache/hugegraph/func/TriFunction.java
+++ b/hugegraph-common/src/main/java/org/apache/hugegraph/func/TriFunction.java
@@ -19,7 +19,7 @@
package org.apache.hugegraph.func;
-public interface TriFunction <T1, T2, T3, R> {
+public interface TriFunction<T1, T2, T3, R> {
R apply(T1 v1, T2 v2, T3 v3);
}
diff --git a/hugegraph-common/src/main/java/org/apache/hugegraph/perf/PerfUtil.java b/hugegraph-common/src/main/java/org/apache/hugegraph/perf/PerfUtil.java
index 39cface..36b5c05 100644
--- a/hugegraph-common/src/main/java/org/apache/hugegraph/perf/PerfUtil.java
+++ b/hugegraph-common/src/main/java/org/apache/hugegraph/perf/PerfUtil.java
@@ -55,7 +55,7 @@ import javassist.CtMethod;
public final class PerfUtil {
private static final Logger LOG = Log.logger(PerfUtil.class);
- private static final int DEFAUL_CAPATICY = 1024;
+ private static final int DEFAULT_CAPACITY = 1024;
private static final ThreadLocal<PerfUtil> INSTANCE = new ThreadLocal<>();
@@ -69,8 +69,8 @@ public final class PerfUtil {
private final Stopwatch root;
private PerfUtil() {
- this.stopwatches = new HashMap<>(DEFAUL_CAPATICY);
- this.callStack = new LocalStack<>(DEFAUL_CAPATICY);
+ this.stopwatches = new HashMap<>(DEFAULT_CAPACITY);
+ this.callStack = new LocalStack<>(DEFAULT_CAPACITY);
this.root = newStopwatch(Path.ROOT_NAME, Path.EMPTY);
}
@@ -403,32 +403,32 @@ public final class PerfUtil {
};
BiConsumer<List<Stopwatch>, List<Stopwatch>> fillChildrenTotal =
- (itemsOfLn, itemsOfLnParent) -> {
- for (Stopwatch parent : itemsOfLnParent) {
- List<Stopwatch> children = itemsOfLn.stream().filter(c -> {
- return c.parent().equals(parent.id());
- }).collect(Collectors.toList());
+ (itemsOfLn, itemsOfLnParent) -> {
+ for (Stopwatch parent : itemsOfLnParent) {
+ List<Stopwatch> children = itemsOfLn.stream().filter(c -> {
+ return c.parent().equals(parent.id());
+ }).collect(Collectors.toList());
- parent.fillChildrenTotal(children);
- }
- };
+ parent.fillChildrenTotal(children);
+ }
+ };
BiConsumer<List<Stopwatch>, List<Stopwatch>> fillOther =
- (itemsOfLn, itemsOfLnParent) -> {
- for (Stopwatch parent : itemsOfLnParent) {
- Stream<Stopwatch> children = itemsOfLn.stream().filter(c -> {
- return c.parent().equals(parent.id());
- });
- // Fill other cost
- long sumCost = children.mapToLong(Stopwatch::totalCost).sum();
- long otherCost = parent.totalCost() - sumCost;
- if (otherCost > 0L) {
- Stopwatch other = newStopwatch("~", parent.id());
- other.totalCost(otherCost);
- itemsOfLn.add(other);
- }
- }
- };
+ (itemsOfLn, itemsOfLnParent) -> {
+ for (Stopwatch parent : itemsOfLnParent) {
+ Stream<Stopwatch> children = itemsOfLn.stream().filter(c -> {
+ return c.parent().equals(parent.id());
+ });
+ // Fill other cost
+ long sumCost = children.mapToLong(Stopwatch::totalCost).sum();
+ long otherCost = parent.totalCost() - sumCost;
+ if (otherCost > 0L) {
+ Stopwatch other = newStopwatch("~", parent.id());
+ other.totalCost(otherCost);
+ itemsOfLn.add(other);
+ }
+ }
+ };
Map<Path, Stopwatch> items = this.stopwatches;
Map<Integer, List<Stopwatch>> levelItems = new HashMap<>();
diff --git a/hugegraph-common/src/main/java/org/apache/hugegraph/perf/Stopwatch.java b/hugegraph-common/src/main/java/org/apache/hugegraph/perf/Stopwatch.java
index 9d095c9..15f7a23 100644
--- a/hugegraph-common/src/main/java/org/apache/hugegraph/perf/Stopwatch.java
+++ b/hugegraph-common/src/main/java/org/apache/hugegraph/perf/Stopwatch.java
@@ -24,26 +24,35 @@ import java.util.List;
public interface Stopwatch extends Cloneable {
Path id();
+
String name();
+
Path parent();
void startTime(long startTime);
+
void endTime(long startTime);
void lastStartTime(long startTime);
long times();
+
long totalTimes();
+
long totalChildrenTimes();
long totalCost();
+
void totalCost(long otherCost);
long minCost();
+
long maxCost();
long totalWasted();
+
long totalSelfWasted();
+
long totalChildrenWasted();
void fillChildrenTotal(List<Stopwatch> children);
@@ -51,9 +60,11 @@ public interface Stopwatch extends Cloneable {
Stopwatch copy();
Stopwatch child(String name);
+
Stopwatch child(String name, Stopwatch watch);
boolean empty();
+
void clear();
default String toJson() {
@@ -97,11 +108,7 @@ public interface Stopwatch extends Cloneable {
if (parent == EMPTY) {
this.path = name;
} else {
- int len = parent.length() + 1 + name.length();
- StringBuilder sb = new StringBuilder(len);
- sb.append(parent.path).append('/').append(name);
-
- this.path = sb.toString();
+ this.path = parent.path + '/' + name;
}
}
diff --git a/hugegraph-common/src/main/java/org/apache/hugegraph/rest/AbstractRestClient.java b/hugegraph-common/src/main/java/org/apache/hugegraph/rest/AbstractRestClient.java
index 0ccf1ad..e6708c5 100644
--- a/hugegraph-common/src/main/java/org/apache/hugegraph/rest/AbstractRestClient.java
+++ b/hugegraph-common/src/main/java/org/apache/hugegraph/rest/AbstractRestClient.java
@@ -19,7 +19,6 @@
package org.apache.hugegraph.rest;
-import java.io.IOException;
import java.net.URI;
import java.security.KeyManagementException;
import java.security.SecureRandom;
@@ -32,19 +31,14 @@ import java.util.concurrent.Callable;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+
import org.apache.commons.collections.MapUtils;
-import org.apache.hugegraph.util.E;
-import org.apache.hugegraph.util.ExecutorUtil;
-import jakarta.ws.rs.client.Client;
-import jakarta.ws.rs.client.ClientRequestContext;
-import jakarta.ws.rs.client.ClientRequestFilter;
-import jakarta.ws.rs.client.Entity;
-import jakarta.ws.rs.client.Invocation.Builder;
-import jakarta.ws.rs.client.WebTarget;
-import jakarta.ws.rs.core.MediaType;
-import jakarta.ws.rs.core.MultivaluedMap;
-import jakarta.ws.rs.core.Response;
-import jakarta.ws.rs.core.Variant;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.http.HttpHeaders;
@@ -55,6 +49,8 @@ import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.pool.PoolStats;
+import org.apache.hugegraph.util.E;
+import org.apache.hugegraph.util.ExecutorUtil;
import org.glassfish.jersey.SslConfigurator;
import org.glassfish.jersey.apache.connector.ApacheClientProperties;
import org.glassfish.jersey.apache.connector.ApacheConnectorProvider;
@@ -69,12 +65,16 @@ import org.glassfish.jersey.uri.UriComponent;
import com.google.common.collect.ImmutableMap;
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
+import jakarta.ws.rs.client.Client;
+import jakarta.ws.rs.client.ClientRequestContext;
+import jakarta.ws.rs.client.ClientRequestFilter;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.client.Invocation.Builder;
+import jakarta.ws.rs.client.WebTarget;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.MultivaluedMap;
+import jakarta.ws.rs.core.Response;
+import jakarta.ws.rs.core.Variant;
public abstract class AbstractRestClient implements RestClient {
@@ -412,15 +412,14 @@ public abstract class AbstractRestClient implements RestClient {
/**
* parse user custom content-type, returns MediaType.APPLICATION_JSON_TYPE default.
- * @param headers
- * @return
+ * @param headers custom http header
*/
- public static MediaType parseCustomContentType(MultivaluedMap<String, Object> headers) {
+ private static MediaType parseCustomContentType(MultivaluedMap<String, Object> headers) {
String customContentType = null;
if (MapUtils.isNotEmpty(headers) && headers.get("Content-Type") != null) {
- Object contentTypeObj = headers.get("Content-Type");
- if (contentTypeObj instanceof List) {
- customContentType = ((List<?>) contentTypeObj).get(0).toString();
+ List<?> contentTypeObj = headers.get("Content-Type");
+ if (contentTypeObj != null && !contentTypeObj.isEmpty()) {
+ customContentType = contentTypeObj.get(0).toString();
}
return MediaType.valueOf(customContentType);
}
@@ -546,7 +545,7 @@ public abstract class AbstractRestClient implements RestClient {
private final ClientConfig config;
- public ConfigBuilder() {
+ ConfigBuilder() {
this.config = new ClientConfig();
}
diff --git a/hugegraph-common/src/main/java/org/apache/hugegraph/testutil/Assert.java b/hugegraph-common/src/main/java/org/apache/hugegraph/testutil/Assert.java
index 519d205..5e09cb8 100644
--- a/hugegraph-common/src/main/java/org/apache/hugegraph/testutil/Assert.java
+++ b/hugegraph-common/src/main/java/org/apache/hugegraph/testutil/Assert.java
@@ -144,8 +144,7 @@ public class Assert extends org.junit.Assert {
private final Number expected;
private final Function<Integer, Boolean> cmp;
- public NumberMatcher(Number expected, Function<Integer, Boolean> cmp,
- String symbol) {
+ NumberMatcher(Number expected, Function<Integer, Boolean> cmp, String symbol) {
this.expected = expected;
this.cmp = cmp;
this.symbol = symbol;
diff --git a/hugegraph-common/src/main/java/org/apache/hugegraph/util/VersionUtil.java b/hugegraph-common/src/main/java/org/apache/hugegraph/util/VersionUtil.java
index cc98fa1..8d633f0 100644
--- a/hugegraph-common/src/main/java/org/apache/hugegraph/util/VersionUtil.java
+++ b/hugegraph-common/src/main/java/org/apache/hugegraph/util/VersionUtil.java
@@ -82,8 +82,8 @@ public final class VersionUtil {
String className = clazz.getSimpleName() + ".class";
String classPath = Objects.requireNonNull(clazz.getResource(className)).toString();
if (!classPath.startsWith("jar:file:")) {
- // Class not from JAR
- return null;
+ // Class not from JAR
+ return null;
}
int offset = classPath.lastIndexOf("!");
assert offset > 0;
diff --git a/hugegraph-rpc/src/main/java/org/apache/hugegraph/config/RpcOptions.java b/hugegraph-rpc/src/main/java/org/apache/hugegraph/config/RpcOptions.java
index 782643e..e4c9730 100644
--- a/hugegraph-rpc/src/main/java/org/apache/hugegraph/config/RpcOptions.java
+++ b/hugegraph-rpc/src/main/java/org/apache/hugegraph/config/RpcOptions.java
@@ -19,9 +19,6 @@
package org.apache.hugegraph.config;
-import org.apache.hugegraph.config.ConfigOption;
-import org.apache.hugegraph.config.OptionHolder;
-
import static org.apache.hugegraph.config.OptionChecker.allowValues;
import static org.apache.hugegraph.config.OptionChecker.disallowEmpty;
import static org.apache.hugegraph.config.OptionChecker.rangeInt;
@@ -128,7 +125,7 @@ public class RpcOptions extends OptionHolder {
"rpc.client_load_balancer",
"The rpc client uses a load-balancing algorithm to " +
"access multiple rpc servers in one cluster. Default " +
- "value is 'consistentHash', means forwording by request " +
+ "value is 'consistentHash', means forwarding by request " +
"parameters.",
allowValues("random", "localPref", "roundRobin",
"consistentHash", "weightRoundRobin"),
diff --git a/hugegraph-rpc/src/main/java/org/apache/hugegraph/rpc/RpcClientProvider.java b/hugegraph-rpc/src/main/java/org/apache/hugegraph/rpc/RpcClientProvider.java
index b17191a..826c013 100644
--- a/hugegraph-rpc/src/main/java/org/apache/hugegraph/rpc/RpcClientProvider.java
+++ b/hugegraph-rpc/src/main/java/org/apache/hugegraph/rpc/RpcClientProvider.java
@@ -41,6 +41,7 @@ public class RpcClientProvider {
this.consumerConfig = StringUtils.isNotBlank(rpcUrl) ?
new RpcConsumerConfig(config, rpcUrl) : null;
}
+
public boolean enabled() {
return this.consumerConfig != null;
}
diff --git a/hugegraph-rpc/src/main/java/org/apache/hugegraph/rpc/RpcConsumerConfig.java b/hugegraph-rpc/src/main/java/org/apache/hugegraph/rpc/RpcConsumerConfig.java
index f2c9b92..796f8fb 100644
--- a/hugegraph-rpc/src/main/java/org/apache/hugegraph/rpc/RpcConsumerConfig.java
+++ b/hugegraph-rpc/src/main/java/org/apache/hugegraph/rpc/RpcConsumerConfig.java
@@ -53,8 +53,8 @@ public class RpcConsumerConfig implements RpcServiceConfig4Client {
private final List<ConsumerBootstrap<?>> bootstraps;
static {
- ExtensionLoaderFactory.getExtensionLoader(Cluster.class)
- .loadExtension(FanoutCluster.class);
+ ExtensionLoaderFactory.getExtensionLoader(Cluster.class)
+ .loadExtension(FanoutCluster.class);
}
public RpcConsumerConfig(HugeConfig config, String remoteUrls) {
@@ -148,7 +148,7 @@ public class RpcConsumerConfig implements RpcServiceConfig4Client {
private static final Logger LOG = Log.logger(FanoutCluster.class);
- public FanoutCluster(ConsumerBootstrap<?> consumerBootstrap) {
+ FanoutCluster(ConsumerBootstrap<?> consumerBootstrap) {
super(consumerBootstrap);
}
diff --git a/pom.xml b/pom.xml
index b10167e..ad7e3a4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -92,7 +92,6 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
- <version>3.1</version>
<configuration>
<source>${compiler.source}</source>
<target>${compiler.target}</target>
@@ -136,7 +135,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
- <version>2.6</version>
<configuration>
<archive>
<index>true</index>
@@ -222,7 +220,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
- <version>1.2.7</version>
+ <version>1.3.0</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
@@ -255,7 +253,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
- <version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
@@ -268,7 +265,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
- <version>2.10.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
@@ -286,7 +282,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
- <version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>