diff --git a/.gitignore b/.gitignore index f7bcdbf5..05e7e3ad 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 b25153d4..17088ea3 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 @@ private static Configuration loadConfigFile(File configFile) { case "yml": case "yaml": Parameters params = new Parameters(); - FileBasedConfigurationBuilder - builder = new FileBasedConfigurationBuilder( - YAMLConfiguration.class) - .configure(params.fileBased() - .setFile(configFile)); + FileBasedConfigurationBuilder 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 8676702a..0e795ff1 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.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 d84c26f3..0e5fbb46 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 { +public interface TriFunction { 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 39cface3..36b5c051 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 @@ 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 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 String toECharts() { }; BiConsumer, List> fillChildrenTotal = - (itemsOfLn, itemsOfLnParent) -> { - for (Stopwatch parent : itemsOfLnParent) { - List children = itemsOfLn.stream().filter(c -> { - return c.parent().equals(parent.id()); - }).collect(Collectors.toList()); + (itemsOfLn, itemsOfLnParent) -> { + for (Stopwatch parent : itemsOfLnParent) { + List children = itemsOfLn.stream().filter(c -> { + return c.parent().equals(parent.id()); + }).collect(Collectors.toList()); - parent.fillChildrenTotal(children); - } - }; + parent.fillChildrenTotal(children); + } + }; BiConsumer, List> fillOther = - (itemsOfLn, itemsOfLnParent) -> { - for (Stopwatch parent : itemsOfLnParent) { - Stream 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 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 items = this.stopwatches; Map> 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 9d095c92..15f7a234 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 @@ 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 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 Path(Path parent, String name) { 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 0ccf1ad6..e6708c5c 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.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.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 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 @@ private Pair> buildRequest( /** * parse user custom content-type, returns MediaType.APPLICATION_JSON_TYPE default. - * @param headers - * @return + * @param headers custom http header */ - public static MediaType parseCustomContentType(MultivaluedMap headers) { + private static MediaType parseCustomContentType(MultivaluedMap 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 @@ private static class ConfigBuilder { 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 519d2053..5e09cb83 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 @@ private static class NumberMatcher extends BaseMatcher { private final Number expected; private final Function cmp; - public NumberMatcher(Number expected, Function cmp, - String symbol) { + NumberMatcher(Number expected, Function 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 cc98fa1c..8d633f02 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 static String getImplementationVersion(Class clazz) { 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 782643ea..e4c9730f 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 static synchronized RpcOptions instance() { "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 b17191a6..826c013a 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 RpcClientProvider(HugeConfig config) { 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 f2c9b920..796f8fbe 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> 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 @@ private static class FanoutCluster extends AbstractCluster { 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 b10167e0..ad7e3a4c 100644 --- a/pom.xml +++ b/pom.xml @@ -92,7 +92,6 @@ maven-compiler-plugin - 3.1 ${compiler.source} ${compiler.target} @@ -136,7 +135,6 @@ org.apache.maven.plugins maven-jar-plugin - 2.6 true @@ -222,7 +220,7 @@ org.codehaus.mojo flatten-maven-plugin - 1.2.7 + 1.3.0 true resolveCiFriendliesOnly @@ -255,7 +253,6 @@ org.apache.maven.plugins maven-source-plugin - 2.2.1 attach-sources @@ -268,7 +265,6 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.10.1 attach-javadocs @@ -286,7 +282,6 @@ org.apache.maven.plugins maven-gpg-plugin - 1.5 sign-artifacts