From aa7989940b556c4f2a5b68cc5f52ca6b87213a57 Mon Sep 17 00:00:00 2001 From: Jermy Li Date: Thu, 8 Mar 2018 19:10:48 +0800 Subject: [PATCH] Support construct a GremlinServer instance from gremlin executor service 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. --- .../tinkerpop/gremlin/server/GremlinServer.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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 5b04ebe61f5..55a1d8487ee 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 @@ -81,6 +81,15 @@ public class GremlinServer { * Construct a Gremlin Server instance from {@link Settings}. */ public GremlinServer(final Settings settings) { + this(settings, null); + } + + /** + * Construct a Gremlin Server instance from {@link Settings} and {@link ExecutorService}. + * 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. + */ + public GremlinServer(final Settings settings, final ExecutorService gremlinExecutorService) { settings.optionalMetrics().ifPresent(GremlinServer::configureMetrics); this.settings = settings; provideDefaultForGremlinPoolSize(settings); @@ -108,8 +117,8 @@ public GremlinServer(final Settings settings) { workerGroup = new NioEventLoopGroup(settings.threadPoolWorker, threadFactoryWorker); } - serverGremlinExecutor = new ServerGremlinExecutor(settings, null, workerGroup); - gremlinExecutorService = serverGremlinExecutor.getGremlinExecutorService(); + serverGremlinExecutor = new ServerGremlinExecutor(settings, gremlinExecutorService, workerGroup); + this.gremlinExecutorService = serverGremlinExecutor.getGremlinExecutorService(); // initialize the OpLoader with configurations being passed to each OpProcessor implementation loaded OpLoader.init(settings);