Skip to content

Commit

Permalink
fix: format and clean code in core module (#2440)
Browse files Browse the repository at this point in the history
  • Loading branch information
msgui authored and VGalaxies committed Feb 20, 2024
1 parent 721111d commit 960b733
Show file tree
Hide file tree
Showing 247 changed files with 1,551 additions and 1,536 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ public static void shutdown(long timeout) {

/**
* Stop all the daemon threads
* @param timeout wait in seconds
*
* @param timeout wait in seconds
* @param ignoreException don't throw exception if true
*/
public static void shutdown(long timeout, boolean ignoreException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public interface HugeGraph extends Graph {
<K, V> V option(TypedOption<K, V> option);

void registerRpcServices(RpcServiceConfig4Server serverConfig,
RpcServiceConfig4Client clientConfig);
RpcServiceConfig4Client clientConfig);

default List<String> mapPkId2Name(Collection<Id> ids) {
List<String> names = new ArrayList<>(ids.size());
Expand Down Expand Up @@ -316,8 +316,8 @@ default Id[] mapVlName2Id(String[] vertexLabels) {

static void registerTraversalStrategies(Class<?> clazz) {
TraversalStrategies strategies = TraversalStrategies.GlobalCache
.getStrategies(Graph.class)
.clone();
.getStrategies(Graph.class)
.clone();
strategies.addStrategies(HugeVertexStepStrategy.instance(),
HugeGraphStepStrategy.instance(),
HugeCountStepStrategy.instance(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@

package org.apache.hugegraph;

import org.apache.hugegraph.analyzer.Analyzer;
import org.apache.hugegraph.backend.LocalCounter;
import org.apache.hugegraph.backend.serializer.AbstractSerializer;
import org.apache.hugegraph.backend.store.BackendFeatures;
import org.apache.hugegraph.backend.store.BackendStore;
import org.apache.hugegraph.backend.store.ram.RamTable;
import org.apache.hugegraph.backend.tx.GraphTransaction;
import org.apache.hugegraph.backend.tx.ISchemaTransaction;
import org.apache.hugegraph.backend.tx.SchemaTransaction;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.event.EventHub;
import org.apache.hugegraph.job.EphemeralJob;
import org.apache.hugegraph.task.ServerInfoManager;
import org.apache.hugegraph.type.define.GraphMode;
import org.apache.hugegraph.type.define.GraphReadMode;
import org.apache.hugegraph.analyzer.Analyzer;
import org.apache.hugegraph.backend.serializer.AbstractSerializer;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.event.EventHub;

import com.google.common.util.concurrent.RateLimiter;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,26 @@
public class StandardHugeGraph implements HugeGraph {

public static final Class<?>[] PROTECT_CLASSES = {
StandardHugeGraph.class,
StandardHugeGraph.StandardHugeGraphParams.class,
TinkerPopTransaction.class,
StandardHugeGraph.Txs.class,
StandardHugeGraph.SysTransaction.class
StandardHugeGraph.class,
StandardHugeGraph.StandardHugeGraphParams.class,
TinkerPopTransaction.class,
StandardHugeGraph.Txs.class,
StandardHugeGraph.SysTransaction.class
};

public static final Set<TypedOption<?, ?>> ALLOWED_CONFIGS = ImmutableSet.of(
CoreOptions.TASK_WAIT_TIMEOUT,
CoreOptions.TASK_SYNC_DELETION,
CoreOptions.TASK_TTL_DELETE_BATCH,
CoreOptions.TASK_INPUT_SIZE_LIMIT,
CoreOptions.TASK_RESULT_SIZE_LIMIT,
CoreOptions.OLTP_CONCURRENT_THREADS,
CoreOptions.OLTP_CONCURRENT_DEPTH,
CoreOptions.OLTP_COLLECTION_TYPE,
CoreOptions.VERTEX_DEFAULT_LABEL,
CoreOptions.VERTEX_ENCODE_PK_NUMBER,
CoreOptions.STORE_GRAPH,
CoreOptions.STORE
CoreOptions.TASK_WAIT_TIMEOUT,
CoreOptions.TASK_SYNC_DELETION,
CoreOptions.TASK_TTL_DELETE_BATCH,
CoreOptions.TASK_INPUT_SIZE_LIMIT,
CoreOptions.TASK_RESULT_SIZE_LIMIT,
CoreOptions.OLTP_CONCURRENT_THREADS,
CoreOptions.OLTP_CONCURRENT_DEPTH,
CoreOptions.OLTP_COLLECTION_TYPE,
CoreOptions.VERTEX_DEFAULT_LABEL,
CoreOptions.VERTEX_ENCODE_PK_NUMBER,
CoreOptions.STORE_GRAPH,
CoreOptions.STORE
);

private static final Logger LOG = Log.logger(StandardHugeGraph.class);
Expand Down Expand Up @@ -306,14 +306,17 @@ public void serverStarted(GlobalMasterInfo nodeInfo) {
private void initRoleStateMachine(Id serverId) {
HugeConfig conf = this.configuration;
Config roleConfig = new RoleElectionConfig(serverId.toString(),
conf.get(RoleElectionOptions.NODE_EXTERNAL_URL),
conf.get(RoleElectionOptions.EXCEEDS_FAIL_COUNT),
conf.get(RoleElectionOptions.RANDOM_TIMEOUT_MILLISECOND),
conf.get(RoleElectionOptions.HEARTBEAT_INTERVAL_SECOND),
conf.get(RoleElectionOptions.MASTER_DEAD_TIMES),
conf.get(RoleElectionOptions.BASE_TIMEOUT_MILLISECOND));
conf.get(RoleElectionOptions.NODE_EXTERNAL_URL),
conf.get(RoleElectionOptions.EXCEEDS_FAIL_COUNT),
conf.get(
RoleElectionOptions.RANDOM_TIMEOUT_MILLISECOND),
conf.get(
RoleElectionOptions.HEARTBEAT_INTERVAL_SECOND),
conf.get(RoleElectionOptions.MASTER_DEAD_TIMES),
conf.get(
RoleElectionOptions.BASE_TIMEOUT_MILLISECOND));
ClusterRoleStore roleStore = new StandardClusterRoleStore(this.params);
this.roleElectionStateMachine = new StandardRoleElectionStateMachine(roleConfig,
this.roleElectionStateMachine = new StandardRoleElectionStateMachine(roleConfig,
roleStore);
}

Expand Down Expand Up @@ -596,7 +599,7 @@ protected void reloadRamtable(boolean loadFromFile) {

@Override
public <C extends GraphComputer> C compute(Class<C> clazz)
throws IllegalArgumentException {
throws IllegalArgumentException {
throw Graph.Exceptions.graphComputerNotSupported();
}

Expand All @@ -605,11 +608,12 @@ public GraphComputer compute() throws IllegalArgumentException {
throw Graph.Exceptions.graphComputerNotSupported();
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public <I extends Io> I io(final Io.Builder<I> builder) {
return (I) builder.graph(this).onMapper(mapper ->
mapper.addRegistry(HugeGraphIoRegistry.instance())
mapper.addRegistry(
HugeGraphIoRegistry.instance())
).create();
}

Expand Down Expand Up @@ -1159,12 +1163,12 @@ public void registerRpcServices(RpcServiceConfig4Server serverConfig,
// The proxy is sometimes unavailable (issue #664)
CacheNotifier proxy = clientConfig.serviceProxy(this.name, clazz1);
serverConfig.addService(this.name, clazz1, new HugeGraphCacheNotifier(
this.graphEventHub, proxy));
this.graphEventHub, proxy));

Class<SchemaCacheNotifier> clazz2 = SchemaCacheNotifier.class;
proxy = clientConfig.serviceProxy(this.name, clazz2);
serverConfig.addService(this.name, clazz2, new HugeSchemaCacheNotifier(
this.schemaEventHub, proxy));
this.schemaEventHub, proxy));
}

private void closeTx() {
Expand Down Expand Up @@ -1522,7 +1526,7 @@ private Txs getOrNewTransaction() {
private void destroyTransaction() {
if (this.isOpen()) {
throw new HugeException(
"Transaction should be closed before destroying");
"Transaction should be closed before destroying");
}

// Do close if needed, then remove the reference
Expand Down Expand Up @@ -1663,17 +1667,17 @@ public void reload() {
}

private static class HugeSchemaCacheNotifier
extends AbstractCacheNotifier
implements SchemaCacheNotifier {
extends AbstractCacheNotifier
implements SchemaCacheNotifier {

public HugeSchemaCacheNotifier(EventHub hub, CacheNotifier proxy) {
super(hub, proxy);
}
}

private static class HugeGraphCacheNotifier
extends AbstractCacheNotifier
implements GraphCacheNotifier {
extends AbstractCacheNotifier
implements GraphCacheNotifier {

public HugeGraphCacheNotifier(EventHub hub, CacheNotifier proxy) {
super(hub, proxy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ private static Analyzer customizedAnalyzer(String name, String mode) {
return clazz.getConstructor(String.class).newInstance(mode);
} catch (Exception e) {
throw new HugeException(
"Failed to construct analyzer '%s' with mode '%s'",
e, name, mode);
"Failed to construct analyzer '%s' with mode '%s'",
e, name, mode);
}
}

@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public static void register(String name, String classPath) {
ClassLoader classLoader = SerializerFactory.class.getClassLoader();
Class<?> clazz;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import org.ansj.splitWord.analysis.IndexAnalysis;
import org.ansj.splitWord.analysis.NlpAnalysis;
import org.ansj.splitWord.analysis.ToAnalysis;

import org.apache.hugegraph.config.ConfigException;
import org.apache.hugegraph.util.InsertionOrderUtil;

import com.google.common.collect.ImmutableList;

/**
Expand All @@ -48,8 +48,8 @@ public class AnsjAnalyzer implements Analyzer {
public AnsjAnalyzer(String mode) {
if (!SUPPORT_MODES.contains(mode)) {
throw new ConfigException(
"Unsupported segment mode '%s' for ansj analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
"Unsupported segment mode '%s' for ansj analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
}
this.analysis = mode;
}
Expand All @@ -72,7 +72,7 @@ public Set<String> segment(String text) {
break;
default:
throw new AssertionError(String.format(
"Unsupported segment mode '%s'", this.analysis));
"Unsupported segment mode '%s'", this.analysis));
}

assert terms != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.apache.hugegraph.config.ConfigException;
import org.apache.hugegraph.util.InsertionOrderUtil;

import com.google.common.collect.ImmutableList;
import com.hankcs.hanlp.seg.Dijkstra.DijkstraSegment;
import com.hankcs.hanlp.seg.NShort.NShortSegment;
Expand All @@ -38,14 +39,14 @@
public class HanLPAnalyzer implements Analyzer {

public static final List<String> SUPPORT_MODES =
ImmutableList.<String>builder()
.add("standard")
.add("nlp")
.add("index")
.add("nShort")
.add("shortest")
.add("speed")
.build();
ImmutableList.<String>builder()
.add("standard")
.add("nlp")
.add("index")
.add("nShort")
.add("shortest")
.add("speed")
.build();

private static final Segment N_SHORT_SEGMENT =
new NShortSegment().enableCustomDictionary(false)
Expand All @@ -61,8 +62,8 @@ public class HanLPAnalyzer implements Analyzer {
public HanLPAnalyzer(String mode) {
if (!SUPPORT_MODES.contains(mode)) {
throw new ConfigException(
"Unsupported segment mode '%s' for hanlp analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
"Unsupported segment mode '%s' for hanlp analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
}
this.tokenizer = mode;
}
Expand Down Expand Up @@ -91,7 +92,7 @@ public Set<String> segment(String text) {
break;
default:
throw new AssertionError(String.format(
"Unsupported segment mode '%s'", this.tokenizer));
"Unsupported segment mode '%s'", this.tokenizer));
}

assert terms != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import java.util.Set;

import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.config.ConfigException;
import org.apache.hugegraph.util.InsertionOrderUtil;
import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import org.apache.hugegraph.config.ConfigException;
import org.apache.hugegraph.util.InsertionOrderUtil;
import com.google.common.collect.ImmutableList;

/**
Expand All @@ -44,8 +44,8 @@ public class IKAnalyzer implements Analyzer {
public IKAnalyzer(String mode) {
if (!SUPPORT_MODES.contains(mode)) {
throw new ConfigException(
"Unsupported segment mode '%s' for ikanalyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
"Unsupported segment mode '%s' for ikanalyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
}
this.smartSegMode = SUPPORT_MODES.get(0).equals(mode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
import java.util.Set;

import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.config.ConfigException;
import org.apache.hugegraph.util.InsertionOrderUtil;
import org.lionsoul.jcseg.ISegment;
import org.lionsoul.jcseg.IWord;
import org.lionsoul.jcseg.dic.ADictionary;
import org.lionsoul.jcseg.dic.DictionaryFactory;
import org.lionsoul.jcseg.segmenter.SegmenterConfig;

import org.apache.hugegraph.config.ConfigException;
import org.apache.hugegraph.util.InsertionOrderUtil;
import com.google.common.collect.ImmutableList;

/**
Expand All @@ -50,8 +50,8 @@ public class JcsegAnalyzer implements Analyzer {
public JcsegAnalyzer(String mode) {
if (!SUPPORT_MODES.contains(mode)) {
throw new ConfigException(
"Unsupported segment mode '%s' for jcseg analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
"Unsupported segment mode '%s' for jcseg analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
}

if ("Simple".equals(mode)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import org.apache.hugegraph.config.ConfigException;
import org.apache.hugegraph.util.InsertionOrderUtil;

import com.google.common.collect.ImmutableList;
import com.huaban.analysis.jieba.JiebaSegmenter;
import com.huaban.analysis.jieba.SegToken;
Expand All @@ -43,8 +44,8 @@ public class JiebaAnalyzer implements Analyzer {
public JiebaAnalyzer(String mode) {
if (!SUPPORT_MODES.contains(mode)) {
throw new ConfigException(
"Unsupported segment mode '%s' for jieba analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
"Unsupported segment mode '%s' for jieba analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
}
this.segMode = JiebaSegmenter.SegMode.valueOf(mode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.config.ConfigException;
import org.apache.hugegraph.util.InsertionOrderUtil;

import com.chenlb.mmseg4j.ComplexSeg;
import com.chenlb.mmseg4j.Dictionary;
import com.chenlb.mmseg4j.MMSeg;
Expand Down Expand Up @@ -51,8 +52,8 @@ public class MMSeg4JAnalyzer implements Analyzer {
public MMSeg4JAnalyzer(String mode) {
if (!SUPPORT_MODES.contains(mode)) {
throw new ConfigException(
"Unsupported segment mode '%s' for mmseg4j analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
"Unsupported segment mode '%s' for mmseg4j analyzer, " +
"the available values are %s", mode, SUPPORT_MODES);
}
int index = SUPPORT_MODES.indexOf(mode);
switch (index) {
Expand All @@ -67,7 +68,7 @@ public MMSeg4JAnalyzer(String mode) {
break;
default:
throw new AssertionError(String.format(
"Unsupported segment mode '%s'", mode));
"Unsupported segment mode '%s'", mode));
}
}

Expand Down
Loading

0 comments on commit 960b733

Please sign in to comment.