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/05 12:37:08 UTC
[07/10] tinkerpop git commit: Changed Client implementation to wrap
DriverRemoteConnection
Changed Client implementation to wrap DriverRemoteConnection
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/12e83508
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/12e83508
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/12e83508
Branch: refs/heads/TINKERPOP-1959
Commit: 12e835086328a1a6ba8bf1f6f6aae24c8037b156
Parents: e464d82
Author: Matthew Allen <ma...@runbox.com>
Authored: Wed Sep 5 20:50:42 2018 +0100
Committer: Matthew Allen <ma...@runbox.com>
Committed: Wed Sep 5 20:50:42 2018 +0100
----------------------------------------------------------------------
.../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(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/12e83508/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/client.js
----------------------------------------------------------------------
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();
+ }
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/12e83508/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/driver/driver-remote-connection.js
----------------------------------------------------------------------
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 0ba5e4f..7300643 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
@@ -131,9 +131,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 }
+ }
});
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/12e83508/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/traversal.js
----------------------------------------------------------------------
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 926f42f..4464097 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++;
}