diff --git a/hugegraph-api/pom.xml b/hugegraph-api/pom.xml
index b687b64ac2..b6e14c864a 100644
--- a/hugegraph-api/pom.xml
+++ b/hugegraph-api/pom.xml
@@ -17,6 +17,33 @@
hugegraph-core
${project.version}
+
+
+ com.baidu.hugegraph
+ hugegraph-rpc
+ 1.0.0
+
+
+
+ com.alipay.sofa
+ bolt
+
+
+ com.alipay.sofa.common
+ sofa-common-tools
+
+
+ com.alipay.sofa
+ hessian
+
+
+
+ io.netty
+ netty-all
+
+
+
+
org.apache.tinkerpop
gremlin-server
@@ -27,6 +54,7 @@
+
org.glassfish.jersey.core
jersey-server
@@ -62,11 +90,6 @@
-
- io.dropwizard.metrics
- metrics-jersey2
-
-
org.glassfish.grizzly
grizzly-http
@@ -88,50 +111,9 @@
2.4.4
-
- com.lmax
- disruptor
- 3.3.7
-
-
- com.alipay.sofa
- sofa-rpc-all
- 5.7.6
-
-
- io.netty
- netty-all
-
-
- org.jboss.resteasy
- resteasy-client
-
-
- com.alipay.sofa
- bolt
-
-
- org.apache.httpcomponents
- httpcore
-
-
- org.apache.httpcomponents
- httpmime
-
-
- com.alipay.sofa.common
- sofa-common-tools
-
-
- org.jboss.logging
- jboss-logging
-
-
- com.alipay.sofa
- hessian
-
-
+ io.dropwizard.metrics
+ metrics-jersey2
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java
index 6f2f8f7507..02dd7f4b49 100644
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/auth/StandardAuthenticator.java
@@ -31,7 +31,7 @@
import com.baidu.hugegraph.config.CoreOptions;
import com.baidu.hugegraph.config.HugeConfig;
import com.baidu.hugegraph.config.ServerOptions;
-import com.baidu.hugegraph.rpc.RpcClientProvider;
+import com.baidu.hugegraph.rpc.RpcClientProviderWithAuth;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.StringEncoding;
@@ -94,7 +94,8 @@ public void setup(HugeConfig config) {
String remoteUrl = config.get(ServerOptions.AUTH_REMOTE_URL);
if (StringUtils.isNotEmpty(remoteUrl)) {
- RpcClientProvider clientProvider = new RpcClientProvider(config);
+ RpcClientProviderWithAuth clientProvider =
+ new RpcClientProviderWithAuth(config);
this.graph.switchAuthManager(clientProvider.authManager());
}
}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java
index 8b41ea3345..0a928cc535 100644
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/config/ServerOptions.java
@@ -233,113 +233,6 @@ public static synchronized ServerOptions instance() {
""
);
- public static final ConfigOption RPC_SERVER_PORT =
- new ConfigOption<>(
- "rpc.server_port",
- "The port bound by rpc server to provide services.",
- rangeInt(1, Integer.MAX_VALUE),
- 8090
- );
-
- public static final ConfigOption RPC_SERVER_HOST =
- new ConfigOption<>(
- "rpc.server_host",
- "The hosts/ips bound by rpc server to provide " +
- "services.",
- disallowEmpty(),
- "127.0.0.1"
- );
-
- public static final ConfigOption RPC_SERVER_TIMEOUT =
- new ConfigOption<>(
- "rpc.server_timeout",
- "The timeout(in seconds) of rpc server execution.",
- rangeInt(1, Integer.MAX_VALUE),
- 30
- );
-
- public static final ConfigOption RPC_REMOTE_URL =
- new ConfigOption<>(
- "rpc.remote_url",
- "The remote urls of rpc peers, it can be set to " +
- "multiple addresses, which are concat by ','.",
- disallowEmpty(),
- "127.0.0.1:8090"
- );
-
- public static final ConfigOption RPC_CLIENT_CONNECT_TIMEOUT =
- new ConfigOption<>(
- "rpc.client_connect_timeout",
- "The timeout(in seconds) of rpc client connect to rpc " +
- "server.",
- rangeInt(1, Integer.MAX_VALUE),
- 20
- );
-
- public static final ConfigOption RPC_CLIENT_RECONNECT_PERIOD =
- new ConfigOption<>(
- "rpc.client_reconnect_period",
- "The period(in seconds) of rpc client reconnect to rpc " +
- "server.",
- rangeInt(1, Integer.MAX_VALUE),
- 10
- );
-
- public static final ConfigOption RPC_CLIENT_READ_TIMEOUT =
- new ConfigOption<>(
- "rpc.client_read_timeout",
- "The timeout(in seconds) of rpc client read from rpc " +
- "server.",
- rangeInt(1, Integer.MAX_VALUE),
- 40
- );
-
- public static final ConfigOption RPC_CLIENT_RETRIES =
- new ConfigOption<>(
- "rpc.client_retries",
- "Failed retry number of rpc client calls to rpc server.",
- rangeInt(0, Integer.MAX_VALUE),
- 3
- );
-
- public static final ConfigOption RPC_CLIENT_LOAD_BALANCER =
- new ConfigOption<>(
- "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 " +
- "parameters.",
- allowValues("random", "localPref", "roundRobin",
- "consistentHash", "weightRoundRobin"),
- "consistentHash"
- );
-
- public static final ConfigOption RPC_PROTOCOL =
- new ConfigOption<>(
- "rpc.protocol",
- "Rpc communication protocol, client and server need to " +
- "be specified the same value.",
- allowValues("bolt", "rest", "dubbo", "h2c", "http"),
- "bolt"
- );
-
- public static final ConfigOption RPC_CONFIG_ORDER =
- new ConfigOption<>(
- "rpc.config_order",
- "Sofa rpc configuration file loading order, the larger " +
- "the more later loading.",
- rangeInt(1, Integer.MAX_VALUE),
- 999
- );
-
- public static final ConfigOption RPC_LOGGER_IMPL =
- new ConfigOption<>(
- "rpc.logger_impl",
- "Sofa rpc log implementation class.",
- disallowEmpty(),
- "com.alipay.sofa.rpc.log.SLF4JLoggerImpl"
- );
-
public static final ConfigOption SSL_KEYSTORE_FILE =
new ConfigOption<>(
"ssl.keystore_file",
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java
index b5075e4ae2..a30f05a2e3 100644
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/core/GraphManager.java
@@ -36,10 +36,10 @@
import com.baidu.hugegraph.HugeFactory;
import com.baidu.hugegraph.HugeGraph;
+import com.baidu.hugegraph.auth.AuthManager;
import com.baidu.hugegraph.auth.HugeAuthenticator;
import com.baidu.hugegraph.auth.HugeFactoryAuthProxy;
import com.baidu.hugegraph.auth.HugeGraphAuthProxy;
-import com.baidu.hugegraph.auth.AuthManager;
import com.baidu.hugegraph.backend.BackendException;
import com.baidu.hugegraph.backend.cache.Cache;
import com.baidu.hugegraph.backend.cache.CacheManager;
@@ -173,13 +173,20 @@ public void close() {
}
private void startRpcServer() {
+ if (!this.rpcServer.enabled()) {
+ LOG.info("RpcServer is not enabled, skip starting rpc service");
+ return;
+ }
+
RpcProviderConfig serverConfig = this.rpcServer.config();
+ // Start auth rpc service if authenticator enabled
if (this.authenticator != null) {
serverConfig.addService(AuthManager.class,
this.authenticator.authManager());
}
+ // Start graph rpc service if RPC_REMOTE_URL enabled
if (this.rpcClient.enabled()) {
RpcConsumerConfig clientConfig = this.rpcClient.config();
@@ -198,7 +205,11 @@ private void startRpcServer() {
}
private void destroyRpcServer() {
- this.rpcServer.destroy();
+ try {
+ this.rpcClient.destroy();
+ } finally {
+ this.rpcServer.destroy();
+ }
}
private HugeAuthenticator authenticator() {
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcClientProvider.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcClientProvider.java
deleted file mode 100644
index 93deb941e1..0000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcClientProvider.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2017 HugeGraph Authors
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- */
-
-package com.baidu.hugegraph.rpc;
-
-import java.util.Arrays;
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-import com.alipay.sofa.rpc.common.utils.StringUtils;
-import com.baidu.hugegraph.auth.AuthManager;
-import com.baidu.hugegraph.config.HugeConfig;
-import com.baidu.hugegraph.config.ServerOptions;
-import com.baidu.hugegraph.util.E;
-
-public class RpcClientProvider {
-
- public final RpcConsumerConfig consumerConfig;
- public final RpcConsumerConfig authConsumerConfig;
-
- public RpcClientProvider(HugeConfig conf) {
- // TODO: fetch from registry server
- String rpcUrl = conf.get(ServerOptions.RPC_REMOTE_URL);
- String selfUrl = conf.get(ServerOptions.RPC_SERVER_HOST) + ":" +
- conf.get(ServerOptions.RPC_SERVER_PORT);
- rpcUrl = excludeSelfUrl(rpcUrl, selfUrl);
- this.consumerConfig = StringUtils.isNotBlank(rpcUrl) ?
- new RpcConsumerConfig(conf, rpcUrl) : null;
-
- String authUrl = conf.get(ServerOptions.AUTH_REMOTE_URL);
- this.authConsumerConfig = StringUtils.isNotBlank(authUrl) ?
- new RpcConsumerConfig(conf, authUrl) : null;
- }
-
- public boolean enabled() {
- return this.consumerConfig != null;
- }
-
- public RpcConsumerConfig config() {
- E.checkArgument(this.consumerConfig != null,
- "RpcClient is not enabled, please config option '%s'",
- ServerOptions.RPC_REMOTE_URL.name());
- return this.consumerConfig;
- }
-
- public AuthManager authManager() {
- E.checkArgument(this.authConsumerConfig != null,
- "RpcClient is not enabled, please config option '%s'",
- ServerOptions.AUTH_REMOTE_URL.name());
- return this.authConsumerConfig.serviceProxy(AuthManager.class);
- }
-
- private static String excludeSelfUrl(String rpcUrl, String selfUrl) {
- String[] urls = StringUtils.splitWithCommaOrSemicolon(rpcUrl);
- // Keep urls order via LinkedHashSet
- Set urlSet = new LinkedHashSet<>(Arrays.asList(urls));
- urlSet.remove(selfUrl);
- return String.join(",", urlSet);
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcCommonConfig.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcClientProviderWithAuth.java
similarity index 53%
rename from hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcCommonConfig.java
rename to hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcClientProviderWithAuth.java
index d3ad769d10..59376d0b82 100644
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcCommonConfig.java
+++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcClientProviderWithAuth.java
@@ -19,28 +19,28 @@
package com.baidu.hugegraph.rpc;
-import java.util.Map;
-
-import com.alipay.sofa.rpc.common.RpcConfigs;
+import com.alipay.sofa.rpc.common.utils.StringUtils;
+import com.baidu.hugegraph.auth.AuthManager;
import com.baidu.hugegraph.config.HugeConfig;
import com.baidu.hugegraph.config.ServerOptions;
+import com.baidu.hugegraph.util.E;
-public class RpcCommonConfig {
+public class RpcClientProviderWithAuth extends RpcClientProvider {
- public static void initRpcConfigs(HugeConfig conf) {
- RpcConfigs.putValue("rpc.config.order",
- conf.get(ServerOptions.RPC_CONFIG_ORDER));
- RpcConfigs.putValue("logger.impl",
- conf.get(ServerOptions.RPC_LOGGER_IMPL));
- }
+ private final RpcConsumerConfig authConsumerConfig;
+
+ public RpcClientProviderWithAuth(HugeConfig config) {
+ super(config);
- public static void initRpcConfigs(String key, Object value) {
- RpcConfigs.putValue(key, value);
+ String authUrl = config.get(ServerOptions.AUTH_REMOTE_URL);
+ this.authConsumerConfig = StringUtils.isNotBlank(authUrl) ?
+ new RpcConsumerConfig(config, authUrl) : null;
}
- public static void initRpcConfigs(Map conf) {
- for(Map.Entry entry : conf.entrySet()) {
- RpcConfigs.putValue(entry.getKey(), entry.getValue());
- }
+ public AuthManager authManager() {
+ E.checkArgument(this.authConsumerConfig != null,
+ "RpcClient is not enabled, please config option '%s'",
+ ServerOptions.AUTH_REMOTE_URL.name());
+ return this.authConsumerConfig.serviceProxy(AuthManager.class);
}
}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcConsumerConfig.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcConsumerConfig.java
deleted file mode 100644
index 698a53269d..0000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcConsumerConfig.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Copyright 2017 HugeGraph Authors
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- */
-
-package com.baidu.hugegraph.rpc;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.slf4j.Logger;
-
-import com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap;
-import com.alipay.sofa.rpc.client.AbstractCluster;
-import com.alipay.sofa.rpc.client.Cluster;
-import com.alipay.sofa.rpc.client.ProviderInfo;
-import com.alipay.sofa.rpc.config.ConsumerConfig;
-import com.alipay.sofa.rpc.core.exception.RpcErrorType;
-import com.alipay.sofa.rpc.core.exception.SofaRpcException;
-import com.alipay.sofa.rpc.core.request.SofaRequest;
-import com.alipay.sofa.rpc.core.response.SofaResponse;
-import com.alipay.sofa.rpc.ext.Extension;
-import com.alipay.sofa.rpc.ext.ExtensionLoaderFactory;
-import com.baidu.hugegraph.config.HugeConfig;
-import com.baidu.hugegraph.config.ServerOptions;
-import com.baidu.hugegraph.util.Log;
-import com.google.common.collect.Maps;
-
-public class RpcConsumerConfig implements RpcServiceConfig4Client {
-
- private final HugeConfig conf;
- private final String remoteUrls;
- private final Map> configs;
-
- static {
- ExtensionLoaderFactory.getExtensionLoader(Cluster.class)
- .loadExtension(FanoutCluster.class);
- }
-
- public RpcConsumerConfig(HugeConfig conf, String remoteUrls) {
- RpcCommonConfig.initRpcConfigs(conf);
- this.conf = conf;
- this.remoteUrls = remoteUrls;
- this.configs = Maps.newHashMap();
- }
-
- @Override
- public T serviceProxy(String graph, String interfaceId) {
- ConsumerConfig config = this.consumerConfig(graph, interfaceId);
- return config.refer();
- }
-
- @Override
- public T serviceProxy(String interfaceId) {
- ConsumerConfig config = this.consumerConfig(null, interfaceId);
- return config.refer();
- }
-
- private ConsumerConfig consumerConfig(String graph,
- String interfaceId) {
- String serviceId;
- if (graph != null) {
- serviceId = interfaceId + ":" + graph;
- } else {
- serviceId = interfaceId;
- }
-
- @SuppressWarnings("unchecked")
- ConsumerConfig consumerConfig = (ConsumerConfig)
- this.configs.get(serviceId);
- if (consumerConfig != null) {
- return consumerConfig;
- }
-
- assert consumerConfig == null;
- consumerConfig = new ConsumerConfig<>();
-
- HugeConfig conf = this.conf;
- String protocol = conf.get(ServerOptions.RPC_PROTOCOL);
- int timeout = conf.get(ServerOptions.RPC_CLIENT_READ_TIMEOUT) * 1000;
- int connectTimeout = conf.get(ServerOptions
- .RPC_CLIENT_CONNECT_TIMEOUT) * 1000;
- int reconnectPeriod = conf.get(ServerOptions
- .RPC_CLIENT_RECONNECT_PERIOD) * 1000;
- int retries = conf.get(ServerOptions.RPC_CLIENT_RETRIES);
- String loadBalancer = conf.get(ServerOptions.RPC_CLIENT_LOAD_BALANCER);
-
- if (graph != null) {
- consumerConfig.setId(serviceId).setUniqueId(graph);
- // Default is FailoverCluster, set to FanoutCluster to broadcast
- consumerConfig.setCluster("fanout");
- }
- consumerConfig.setInterfaceId(interfaceId)
- .setProtocol(protocol)
- .setDirectUrl(this.remoteUrls)
- .setTimeout(timeout)
- .setConnectTimeout(connectTimeout)
- .setReconnectPeriod(reconnectPeriod)
- .setRetries(retries)
- .setLoadBalancer(loadBalancer);
-
- this.configs.put(serviceId, consumerConfig);
- return consumerConfig;
- }
-
- @Extension("fanout")
- private static class FanoutCluster extends AbstractCluster {
-
- private static final Logger LOG = Log.logger(FanoutCluster.class);
-
- public FanoutCluster(ConsumerBootstrap> consumerBootstrap) {
- super(consumerBootstrap);
- }
-
- @Override
- protected SofaResponse doInvoke(SofaRequest request)
- throws SofaRpcException {
- List providers = this.getRouterChain()
- .route(request, null);
- List responses = new ArrayList<>(providers.size());
- List excepts = new ArrayList<>(providers.size());
-
- for (ProviderInfo provider : providers) {
- try {
- SofaResponse response = this.doInvoke(request, provider);
- responses.add(response);
- } catch (SofaRpcException e) {
- excepts.add(e);
- LOG.warn("{}.(error {})", e.getMessage(), e.getErrorType());
- }
- }
-
- if (responses.size() > 0) {
- /*
- * Just choose the first one as result to return, ignore others
- * TODO: maybe more strategies should be provided
- */
- return responses.get(0);
- } else if (excepts.size() > 0) {
- throw excepts.get(0);
- } else {
- assert providers.isEmpty();
- String method = methodName(request);
- throw new SofaRpcException(RpcErrorType.CLIENT_ROUTER,
- "No service provider for " + method);
- }
- }
-
- private SofaResponse doInvoke(SofaRequest request,
- ProviderInfo providerInfo) {
- try {
- SofaResponse response = this.filterChain(providerInfo, request);
- if (response != null) {
- return response;
- }
- String method = methodName(request);
- throw new SofaRpcException(RpcErrorType.CLIENT_UNDECLARED_ERROR,
- "Failed to call " + method + " on remote server " +
- providerInfo + ", return null response");
- } catch (SofaRpcException e) {
- throw e;
- } catch (Exception e) {
- String method = methodName(request);
- throw new SofaRpcException(RpcErrorType.CLIENT_UNDECLARED_ERROR,
- "Failed to call " + method + " on remote server " +
- providerInfo + ", cause by exception: " + e);
- }
- }
-
- private static String methodName(SofaRequest request) {
- return request.getInterfaceName() + "." +
- request.getMethodName() + "()";
- }
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcException.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcException.java
deleted file mode 100644
index 4b03f6943a..0000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcException.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2017 HugeGraph Authors
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- */
-
-package com.baidu.hugegraph.rpc;
-
-import com.baidu.hugegraph.HugeException;
-
-public class RpcException extends HugeException {
-
- private static final long serialVersionUID = -6067652498161184537L;
-
- public RpcException(String message) {
- super(message);
- }
-
- public RpcException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public RpcException(String message, Object... args) {
- super(message, args);
- }
-
- public RpcException(String message, Throwable cause, Object... args) {
- super(message, cause, args);
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcProviderConfig.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcProviderConfig.java
deleted file mode 100644
index 7522bff507..0000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcProviderConfig.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2017 HugeGraph Authors
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- */
-
-package com.baidu.hugegraph.rpc;
-
-import java.util.Map;
-
-import com.alipay.sofa.rpc.config.ProviderConfig;
-import com.google.common.collect.Maps;
-
-public class RpcProviderConfig implements RpcServiceConfig4Server {
-
- private final Map> configs = Maps.newHashMap();
-
- @Override
- public void addService(Class clazz, E serviceImpl) {
- this.addService(null, clazz.getName(), serviceImpl);
- }
-
- @Override
- public void addService(String graph, Class clazz,
- E serviceImpl) {
- this.addService(graph, clazz.getName(), serviceImpl);
- }
-
- private void addService(String graph,
- String interfaceId,
- E serviceImpl) {
- ProviderConfig providerConfig = new ProviderConfig<>();
- String serviceId;
- if (graph != null) {
- serviceId = interfaceId + ":" + graph;
- providerConfig.setId(serviceId).setUniqueId(graph);
- } else {
- serviceId = interfaceId;
- }
- providerConfig.setInterfaceId(interfaceId)
- .setRef(serviceImpl);
- this.configs.put(serviceId, providerConfig);
- }
-
- public Map> configs() {
- return this.configs;
- }
-}
diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcServer.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcServer.java
deleted file mode 100644
index d2ee7f17e2..0000000000
--- a/hugegraph-api/src/main/java/com/baidu/hugegraph/rpc/RpcServer.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright 2017 HugeGraph Authors
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- */
-
-package com.baidu.hugegraph.rpc;
-
-import java.util.Map;
-
-import org.apache.commons.collections.MapUtils;
-import org.slf4j.Logger;
-
-import com.alipay.sofa.rpc.config.ProviderConfig;
-import com.alipay.sofa.rpc.config.ServerConfig;
-import com.baidu.hugegraph.config.HugeConfig;
-import com.baidu.hugegraph.config.ServerOptions;
-import com.baidu.hugegraph.util.Log;
-
-public class RpcServer {
-
- private static final Logger LOG = Log.logger(RpcServer.class);
-
- private final HugeConfig conf;
- private final RpcProviderConfig configs;
- private final ServerConfig serverConfig;
-
- public RpcServer(HugeConfig conf) {
- RpcCommonConfig.initRpcConfigs(conf);
- this.conf = conf;
- this.serverConfig = new ServerConfig();
- this.serverConfig.setProtocol(conf.get(ServerOptions.RPC_PROTOCOL))
- .setHost(conf.get(ServerOptions.RPC_SERVER_HOST))
- .setPort(conf.get(ServerOptions.RPC_SERVER_PORT))
- .setDaemon(false);
- this.configs = new RpcProviderConfig();
- }
-
- public RpcProviderConfig config() {
- return this.configs;
- }
-
- public void exportAll() {
- LOG.debug("RpcServer starting on port {}", this.port());
- Map> configs = this.configs.configs();
- if (MapUtils.isEmpty(configs)) {
- LOG.info("RpcServer config is empty, skip starting RpcServer");
- return;
- }
- int timeout = this.conf.get(ServerOptions.RPC_SERVER_TIMEOUT) * 1000;
- for (ProviderConfig> providerConfig : configs.values()) {
- providerConfig.setServer(this.serverConfig)
- .setTimeout(timeout)
- .export();
- }
- LOG.info("RpcServer started success on port {}", this.port());
- }
-
- public void unExport(String serviceName) {
- Map> configs = this.configs.configs();
- if (!configs.containsKey(serviceName)) {
- throw new RpcException("The service name '%s' doesn't exist",
- serviceName);
- }
- configs.get(serviceName).unExport();
- }
-
- public int port() {
- return this.serverConfig.getPort();
- }
-
- public void destroy() {
- LOG.info("RpcServer stop on port {}", this.port());
- for (ProviderConfig> config : this.configs.configs().values()) {
- Object service = config.getRef();
- if (service instanceof AutoCloseable) {
- try {
- ((AutoCloseable) service).close();
- } catch (Exception e) {
- LOG.warn("Failed to close service {}", service, e);
- }
- }
- }
- this.serverConfig.destroy();
- }
-}
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Client.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Client.java
index 9c42ce6ee9..13cfca96f0 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Client.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Client.java
@@ -32,4 +32,6 @@ public default T serviceProxy(Class clazz) {
public default T serviceProxy(String graph, Class clazz) {
return this.serviceProxy(graph, clazz.getName());
}
+
+ public void removeAllServiceProxy();
}
diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Server.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Server.java
index 53ce5a3aaa..7139073cf3 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Server.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/rpc/RpcServiceConfig4Server.java
@@ -21,8 +21,12 @@
public interface RpcServiceConfig4Server {
- public void addService(Class clazz, E serviceImpl);
+ public String addService(Class clazz, S serviceImpl);
- public void addService(String graph, Class clazz,
- E serviceImpl);
+ public String addService(String graph,
+ Class clazz, S serviceImpl);
+
+ public void removeService(String serviceId);
+
+ public void removeAllService();
}
diff --git a/hugegraph-dist/src/assembly/static/conf/rest-server.properties b/hugegraph-dist/src/assembly/static/conf/rest-server.properties
index 30bc288287..621c1c80bf 100644
--- a/hugegraph-dist/src/assembly/static/conf/rest-server.properties
+++ b/hugegraph-dist/src/assembly/static/conf/rest-server.properties
@@ -17,10 +17,10 @@ server.role=master
rpc.server_host=127.0.0.1
rpc.server_port=8090
-rpc.server_timeout=30
+#rpc.server_timeout=30
rpc.remote_url=127.0.0.1:8090
-rpc.client_connect_timeout=20
-rpc.client_reconnect_period=10
-rpc.client_read_timeout=40
-rpc.client_retries=3
-rpc.client_load_balancer=consistentHash
+#rpc.client_connect_timeout=20
+#rpc.client_reconnect_period=10
+#rpc.client_read_timeout=40
+#rpc.client_retries=3
+#rpc.client_load_balancer=consistentHash
diff --git a/hugegraph-dist/src/main/java/com/baidu/hugegraph/dist/RegisterUtil.java b/hugegraph-dist/src/main/java/com/baidu/hugegraph/dist/RegisterUtil.java
index c789fa7c1c..b1e6c8df98 100644
--- a/hugegraph-dist/src/main/java/com/baidu/hugegraph/dist/RegisterUtil.java
+++ b/hugegraph-dist/src/main/java/com/baidu/hugegraph/dist/RegisterUtil.java
@@ -183,7 +183,10 @@ public static void registerPostgresql() {
}
public static void registerServer() {
+ // Register ServerOptions (rest-server)
OptionSpace.register("server", "com.baidu.hugegraph.config.ServerOptions");
+ // Register RpcOptions (rpc-server)
+ OptionSpace.register("rpc", "com.baidu.hugegraph.config.RpcOptions");
}
/**