tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [40/50] incubator-tinkerpop git commit: Make the GraphManager instance injectable into ServerGremlinExecutor
Date Tue, 08 Mar 2016 19:37:43 GMT
Make the GraphManager instance injectable into ServerGremlinExecutor

This refers to a discussion from the gremlin-users mailing list:
https://groups.google.com/forum/#!topic/gremlin-users/xYzCAQExvvM

It is currently not possible to use a standard way to inject a
fully configured graph. The way presented in this gist is only
a hack and should not be takes as the default way.
https://gist.github.com/xenji/e469abde2e0b80aadc4e

Adding a new constructor parameter is, from my point of view,
the most flexible and compatible change to enable the injection
without breaking old code.

I've run the whole test suite of the server before pushing without
failures.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/164b88ae
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/164b88ae
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/164b88ae

Branch: refs/heads/TINKERPOP-1096
Commit: 164b88ae1c139a2541c28b21795836318ed82246
Parents: 8a2d797
Author: Mario Mueller <mario.mueller@trivago.com>
Authored: Mon Feb 29 21:16:14 2016 +0100
Committer: Mario Mueller <mario.mueller@trivago.com>
Committed: Thu Mar 3 07:31:59 2016 +0100

----------------------------------------------------------------------
 .../server/util/ServerGremlinExecutor.java      | 26 +++++++++++++-------
 1 file changed, 17 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/164b88ae/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 3fa568c..b5d9f46 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
@@ -70,7 +70,14 @@ public class ServerGremlinExecutor<T extends ScheduledExecutorService>
{
     public ServerGremlinExecutor(final Settings settings, final Class<T> scheduleExecutorServiceClass)
{
         this(settings, null, null, scheduleExecutorServiceClass);
     }
-
+    public ServerGremlinExecutor(final Settings settings, final ExecutorService gremlinExecutorService,
+                                 final T scheduledExecutorService, final Class<T> scheduleExecutorServiceClass)
{
+        this(settings,
+             gremlinExecutorService,
+             scheduledExecutorService,
+             scheduleExecutorServiceClass,
+             new GraphManager(settings));
+    }
     /**
      * Create a new object from {@link Settings} where thread pools are externally assigned.
Note that if the
      * {@code scheduleExecutorServiceClass} is set to {@code null} it will be created via
@@ -78,7 +85,8 @@ public class ServerGremlinExecutor<T extends ScheduledExecutorService>
{
      * instances are supplied, the {@link Settings#gremlinPool} value will be ignored for
the pool size.
      */
     public ServerGremlinExecutor(final Settings settings, final ExecutorService gremlinExecutorService,
-                                 final T scheduledExecutorService, final Class<T> scheduleExecutorServiceClass)
{
+                                 final T scheduledExecutorService, final Class<T> scheduleExecutorServiceClass,
+                                 final GraphManager graphManager) {
         this.settings = settings;
 
         if (null == gremlinExecutorService) {
@@ -97,17 +105,17 @@ public class ServerGremlinExecutor<T extends ScheduledExecutorService>
{
         }
 
         // initialize graphs from configuration
-        graphManager = new GraphManager(settings);
+        this.graphManager = graphManager;
 
         logger.info("Initialized Gremlin thread pool.  Threads in pool named with pattern
gremlin-*");
 
         final GremlinExecutor.Builder gremlinExecutorBuilder = GremlinExecutor.build()
                 .scriptEvaluationTimeout(settings.scriptEvaluationTimeout)
-                .afterFailure((b, e) -> graphManager.rollbackAll())
-                .beforeEval(b -> graphManager.rollbackAll())
-                .afterTimeout(b -> graphManager.rollbackAll())
+                .afterFailure((b, e) -> this.graphManager.rollbackAll())
+                .beforeEval(b -> this.graphManager.rollbackAll())
+                .afterTimeout(b -> this.graphManager.rollbackAll())
                 .enabledPlugins(new HashSet<>(settings.plugins))
-                .globalBindings(graphManager.getAsBindings())
+                .globalBindings(this.graphManager.getAsBindings())
                 .executorService(this.gremlinExecutorService)
                 .scheduledExecutorService(this.scheduledExecutorService);
 
@@ -126,14 +134,14 @@ public class ServerGremlinExecutor<T extends ScheduledExecutorService>
{
         // re-apply those references back
         gremlinExecutor.getGlobalBindings().entrySet().stream()
                 .filter(kv -> kv.getValue() instanceof Graph)
-                .forEach(kv -> graphManager.getGraphs().put(kv.getKey(), (Graph) kv.getValue()));
+                .forEach(kv -> this.graphManager.getGraphs().put(kv.getKey(), (Graph)
kv.getValue()));
 
         // script engine init may have constructed the TraversalSource bindings - store them
in Graphs object
         gremlinExecutor.getGlobalBindings().entrySet().stream()
                 .filter(kv -> kv.getValue() instanceof TraversalSource)
                 .forEach(kv -> {
                     logger.info("A {} is now bound to [{}] with {}", kv.getValue().getClass().getSimpleName(),
kv.getKey(), kv.getValue());
-                    graphManager.getTraversalSources().put(kv.getKey(), (TraversalSource)
kv.getValue());
+                    this.graphManager.getTraversalSources().put(kv.getKey(), (TraversalSource)
kv.getValue());
                 });
 
         // determine if the initialization scripts introduced LifeCycleHook objects - if
so we need to gather them


Mime
View raw message