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 2019/05/08 18:54:34 UTC

[tinkerpop] 01/02: TINKERPOP-2211 Add API to which allows per-request option for bytecode submission

This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch TINKERPOP-2211
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit 138a4a9b49c696acb8ab2a348e4ccd712dca94b0
Author: Divij Vaidya <di...@amazon.com>
AuthorDate: Mon May 6 21:09:16 2019 -0700

    TINKERPOP-2211 Add API to which allows per-request option for bytecode submission
---
 .../apache/tinkerpop/gremlin/driver/Client.java    | 48 +++++++++++++++++++++-
 1 file changed, 46 insertions(+), 2 deletions(-)

diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
index 1df2d0d..16c3b76 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
@@ -151,6 +151,24 @@ public abstract class Client {
     }
 
     /**
+     * A version of {@link #submit(Bytecode)} which provides the ability to set per-request options.
+     *
+     * @param bytecode request in the form of gremlin {@link Bytecode}
+     * @param options for the request
+     *
+     * @see #submit(Bytecode)
+     */
+    public ResultSet submit(final Bytecode bytecode, final RequestOptions options) {
+        try {
+            return submitAsync(bytecode, options).get();
+        } catch (UnsupportedOperationException uoe) {
+            throw uoe;
+        } catch (Exception ex) {
+            throw new RuntimeException(ex);
+        }
+    }
+
+    /**
      * An asynchronous version of {@link #submit(Traversal)}. Results are returned as {@link Traverser} instances and
      * are therefore bulked, meaning that to properly iterate the contents of the result each {@link Traverser#bulk()}
      * must be examined to determine the number of times that object should be presented in iteration.
@@ -160,6 +178,18 @@ public abstract class Client {
     }
 
     /**
+     * A version of {@link #submit(Bytecode)} which provides the ability to set per-request options.
+     *
+     * @param bytecode request in the form of gremlin {@link Bytecode}
+     * @param options for the request
+     *
+     * @see #submitAsync(Bytecode)
+     */
+    public CompletableFuture<ResultSet> submitAsync(final Bytecode bytecode, final RequestOptions options) {
+        throw new UnsupportedOperationException("This implementation does not support Traversal submission - use a sessionless Client created with from the alias() method");
+    }
+
+    /**
      * Initializes the client which typically means that a connection is established to the server.  Depending on the
      * implementation and configuration this blocking call may take some time.  This method will be called
      * automatically if it is not called directly and multiple calls will not have effect.
@@ -518,9 +548,23 @@ public abstract class Client {
 
         @Override
         public CompletableFuture<ResultSet> submitAsync(final Bytecode bytecode) {
+            return submitAsync(bytecode, RequestOptions.EMPTY);
+        }
+
+        @Override
+        public CompletableFuture<ResultSet> submitAsync(final Bytecode bytecode, final RequestOptions options) {
             try {
-                return submitAsync(buildMessage(RequestMessage.build(Tokens.OPS_BYTECODE)
-                        .processor("traversal").addArg(Tokens.ARGS_GREMLIN, bytecode)).create());
+                // need to call buildMessage() right away to get client specific configurations, that way request specific
+                // ones can override as needed
+                final RequestMessage.Builder request = buildMessage(RequestMessage.build(Tokens.OPS_BYTECODE)
+                                                                                  .processor("traversal")
+                                                                                  .addArg(Tokens.ARGS_GREMLIN, bytecode));
+
+                // apply settings if they were made available
+                options.getBatchSize().ifPresent(batchSize -> request.add(Tokens.ARGS_BATCH_SIZE, batchSize));
+                options.getTimeout().ifPresent(timeout -> request.add(Tokens.ARGS_SCRIPT_EVAL_TIMEOUT, timeout));
+
+                return submitAsync(request.create());
             } catch (Exception ex) {
                 throw new RuntimeException(ex);
             }