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 2018/10/08 19:02:11 UTC

[tinkerpop] 07/12: Changed Client implementation to wrap DriverRemoteConnection

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

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

commit 20b7687592b62926d4e820734652fb321d3131d9
Author: Matthew Allen <ma...@runbox.com>
AuthorDate: Wed Sep 5 20:50:42 2018 +0100

    Changed Client implementation to wrap DriverRemoteConnection
---
 .../gremlin-javascript/lib/driver/client.js        | 34 ++++++++++++++++++----
 .../lib/driver/driver-remote-connection.js         |  6 ++--
 .../gremlin-javascript/lib/process/traversal.js    |  4 +--
 3 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/client.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/client.js
index 89d9347..91a4dfb 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/client.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/client.js
@@ -21,7 +21,7 @@
 const DriverRemoteConnection = require('./driver-remote-connection');
 const Bytecode = require('../process/bytecode');
 
-class Client extends DriverRemoteConnection {
+class Client {
   /**
    * Creates a new instance of DriverRemoteConnection.
    * @param {String} url The resource uri.
@@ -38,10 +38,24 @@ class Client extends DriverRemoteConnection {
    * @constructor
    */
   constructor(url, options) {
-    super(url, options);
+    this._options = options;
+    this._connection = new DriverRemoteConnection(url, options);
   }
 
-  /** override */
+  /**
+   * Opens the underlying connection to the Gremlin Server, if it's not already opened.
+   * @returns {Promise}
+   */
+  open() {
+    return this._connection.open();
+  }
+
+  /**
+   * Send a request to the Gremlin Server, can send a script or bytecode steps.
+   * @param {Bytecode|string} message The bytecode or script to send
+   * @param {Object} bindings The script bindings, if any.
+   * @returns {Promise}
+   */
   submit(message, bindings) {
     if (typeof message === 'string' || message instanceof String) {
       const args = {
@@ -49,16 +63,24 @@ class Client extends DriverRemoteConnection {
         'bindings': bindings,
         'language': 'gremlin-groovy',
         'accept': 'application/json',
-        'aliases': { 'g': this.traversalSource }
+        'aliases': { 'g': this._options.traversalSource || 'g' }
       };
 
-      return super.submit(null, 'eval', args, null, '');
+      return this._connection.submit(null, 'eval', args, null, '');
     }
 
     if (message instanceof Bytecode) {
-      return super.submit(message);
+      return this._connection.submit(message);
     }
   }
+
+  /**
+   * Closes the underlying connection
+   * @returns {Promise}
+   */
+  close() {
+    return this._connection.close();
+  }
   
 }
 
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js
index 81d5124..d8bb8dc 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js
@@ -133,9 +133,9 @@ class DriverRemoteConnection extends RemoteConnection {
       // if using op eval need to ensure processor stays unset if caller didn't set it.
       'processor': (!processor && op !== 'eval') ? 'traversal' : processor,
       'args': args || {
-          'gremlin': this._writer.adaptObject(bytecode),
-          'aliases': { 'g': this.traversalSource }
-        }
+        'gremlin': this._writer.adaptObject(bytecode),
+        'aliases': { 'g': this.traversalSource }
+      }
     });
   }
 
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/traversal.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/traversal.js
index 5ec2db5..d39ccf0 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/traversal.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/traversal.js
@@ -85,11 +85,9 @@ class Traversal {
   _getNext() {
     while (this.traversers && this._traversersIteratorIndex < this.traversers.length) {
       let traverser = this.traversers[this._traversersIteratorIndex];
-      if (traverser.bulk && traverser.bulk > 0) {
+      if (traverser.bulk > 0) {
         traverser.bulk--;
         return { value: traverser.object, done: false };
-      } else if (traverser.bulk === undefined) {
-        return { value: traverser, done: true }
       }
       this._traversersIteratorIndex++;
     }