You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/11/27 16:03:12 UTC
[5/5] incubator-tinkerpop git commit: GremlinServerExecutor includes
"hostOptions"
GremlinServerExecutor includes "hostOptions"
Added some deprecation to a GremlinServer constructor - opens a bad usage of GremlinServerExecutor. Added a way to get the internally constructed GremlinServerExecutor from GremlinServer. Included a hostOptions Map in GremlinServerExecutor that will make it possible for embedding applications to include objects that can be used by the Channelizer.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/d4cd1dd2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/d4cd1dd2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/d4cd1dd2
Branch: refs/heads/TINKERPOP3-912
Commit: d4cd1dd2868190b539a74741d17c59e6a0a0ada3
Parents: b007e83
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Nov 27 09:58:24 2015 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Nov 27 09:58:24 2015 -0500
----------------------------------------------------------------------
.../tinkerpop/gremlin/server/GremlinServer.java | 9 +++++-
.../server/util/ServerGremlinExecutor.java | 32 +++++++++++++++++---
2 files changed, 35 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d4cd1dd2/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/GremlinServer.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/GremlinServer.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/GremlinServer.java
index 2104e2f..c2c18b7 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/GremlinServer.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/GremlinServer.java
@@ -86,7 +86,6 @@ public class GremlinServer {
logger.warn("cannot use epoll in non-linux env, falling back to NIO");
}
-
Runtime.getRuntime().addShutdownHook(new Thread(() -> this.stop().join(), SERVER_THREAD_PREFIX + "shutdown"));
final ThreadFactory threadFactoryBoss = ThreadFactoryUtil.create("boss-%d");
@@ -114,7 +113,11 @@ public class GremlinServer {
* pre-constructed objects used by the server as well as the {@link Settings} object itself. This constructor
* is useful when Gremlin Server is being used in an embedded style and there is a need to share thread pools
* with the hosting application.
+ *
+ * @deprecated As of release 3.1.1-incubating, not replaced.
+ * @see <a href="https://issues.apache.org/jira/browse/TINKERPOP3-912">TINKERPOP3-912</a>
*/
+ @Deprecated
public GremlinServer(final ServerGremlinExecutor<EventLoopGroup> serverGremlinExecutor) {
this.serverGremlinExecutor = serverGremlinExecutor;
this.settings = serverGremlinExecutor.getSettings();
@@ -310,6 +313,10 @@ public class GremlinServer {
return serverStopped;
}
+ public ServerGremlinExecutor<EventLoopGroup> getServerGremlinExecutor() {
+ return serverGremlinExecutor;
+ }
+
public static void main(final String[] args) throws Exception {
// add to vm options: -Dlog4j.configuration=file:conf/log4j.properties
printHeader();
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d4cd1dd2/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
index fe3c9a5..3fa568c 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/util/ServerGremlinExecutor.java
@@ -20,6 +20,7 @@ package org.apache.tinkerpop.gremlin.server.util;
import org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
+import org.apache.tinkerpop.gremlin.server.Channelizer;
import org.apache.tinkerpop.gremlin.server.GraphManager;
import org.apache.tinkerpop.gremlin.server.GremlinServer;
import org.apache.tinkerpop.gremlin.server.Settings;
@@ -27,8 +28,11 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -37,11 +41,11 @@ import java.util.stream.Collectors;
/**
* The core of script execution in Gremlin Server. Given {@link Settings} and optionally other arguments, this
- * class will construct a {@link GremlinExecutor} to be used by Gremlin Server. Those expecting to build their
- * own version of Gremlin Server might consider coring their implementation with this class as it provides some
- * basic infrastructure required for most of Gremlin Server script processing features. Those embedding Gremlin
- * Server in another application might consider using this class to initialize the {@link GremlinServer} class
- * as it will allow sharing of thread pool resources.
+ * class will construct a {@link GremlinExecutor} to be used by Gremlin Server. A typical usage would be to
+ * instantiate the {@link GremlinServer} and then immediately call {@link GremlinServer#getServerGremlinExecutor()}
+ * which would allow the opportunity to assign "host options" which could be used by a custom {@link Channelizer}.
+ * Add these options before calling {@link GremlinServer#start()} to be sure the {@link Channelizer} gets access to
+ * those.
*
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
@@ -56,6 +60,8 @@ public class ServerGremlinExecutor<T extends ScheduledExecutorService> {
private final ExecutorService gremlinExecutorService;
private final GremlinExecutor gremlinExecutor;
+ private final Map<String,Object> hostOptions = new ConcurrentHashMap<>();
+
/**
* Create a new object from {@link Settings} where thread pools are internally created. Note that the
* {@code scheduleExecutorServiceClass} will be created via
@@ -138,6 +144,22 @@ public class ServerGremlinExecutor<T extends ScheduledExecutorService> {
.collect(Collectors.toList());
}
+ public void addHostOption(final String key, final Object value) {
+ hostOptions.put(key, value);
+ }
+
+ public Map<String,Object> getHostOptions() {
+ return Collections.unmodifiableMap(hostOptions);
+ }
+
+ public Object removeHostOption(final String key) {
+ return hostOptions.remove(key);
+ }
+
+ public void clearHostOptions() {
+ hostOptions.clear();
+ }
+
public T getScheduledExecutorService() {
return scheduledExecutorService;
}