forked from hugegraph/hugegraph-sync
refact: address some code alert (#115)
This commit is contained in:
parent
952975a3c7
commit
caa4b26a98
|
|
@ -81,3 +81,4 @@ hs_err_pid*
|
|||
.mtj.tmp/
|
||||
# blueJ files
|
||||
*.ctxt
|
||||
.flattened-pom.xml
|
||||
|
|
|
|||
|
|
@ -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":
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<>();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ public class RpcClientProvider {
|
|||
this.consumerConfig = StringUtils.isNotBlank(rpcUrl) ?
|
||||
new RpcConsumerConfig(config, rpcUrl) : null;
|
||||
}
|
||||
|
||||
public boolean enabled() {
|
||||
return this.consumerConfig != null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
7
pom.xml
7
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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue