This is an automated email from the ASF dual-hosted git repository. jin pushed a commit to branch fix-style in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph-commons.git
commit 242cfc374226ba4e31b074fddffde5ee5e6e4893 Author: imbajin <[email protected]> AuthorDate: Fri Nov 4 20:29:37 2022 +0800 refact: address some code alert --- .../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 | 40 ++++++++--------- .../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 | 25 +++++++++++ 12 files changed, 95 insertions(+), 70 deletions(-) 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..e159238 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 { @@ -546,7 +546,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 0f405cf..668d724 100644 --- a/pom.xml +++ b/pom.xml @@ -256,6 +256,31 @@ </additionalOptions> </configuration> </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>flatten-maven-plugin</artifactId> + <version>1.2.7</version> + <configuration> + <updatePomFile>true</updatePomFile> + <flattenMode>resolveCiFriendliesOnly</flattenMode> + </configuration> + <executions> + <execution> + <id>flatten</id> + <phase>process-resources</phase> + <goals> + <goal>flatten</goal> + </goals> + </execution> + <execution> + <id>flatten.clean</id> + <phase>clean</phase> + <goals> + <goal>clean</goal> + </goals> + </execution> + </executions> + </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-gpg-plugin</artifactId>
