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 2016/03/01 16:46:20 UTC

incubator-tinkerpop git commit: Added reference docs on Considering State for Gremlin Server.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/tp31 7b40632c8 -> b2145cb64


Added reference docs on Considering State for Gremlin Server.

A minor addition - CTR


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

Branch: refs/heads/tp31
Commit: b2145cb641a99a296162cdc74b55959242661dbc
Parents: 7b40632
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Mar 1 10:45:38 2016 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Mar 1 10:46:02 2016 -0500

----------------------------------------------------------------------
 .../src/reference/gremlin-applications.asciidoc | 71 ++++++++++++++++++++
 1 file changed, 71 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b2145cb6/docs/src/reference/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-applications.asciidoc b/docs/src/reference/gremlin-applications.asciidoc
index 87fe1fb..b7c8ac0 100644
--- a/docs/src/reference/gremlin-applications.asciidoc
+++ b/docs/src/reference/gremlin-applications.asciidoc
@@ -1162,6 +1162,16 @@ all scripts that are passed to it.  The cache is keyed based on the a hash of th
 where `x` is passed as a parameter from the client, there will be no additional compilation cost for future requests
 on that script.  Compilation of a script should be considered "expensive" and avoided when possible.
 
+[source,java]
+----
+Cluster cluster = Cluster.open();
+Client client = cluster.connect();
+
+Map<String,Object> params = new HashMap<>();
+params.put("x",4);
+client.submit("[1,2,3,x]", params);
+----
+
 Cache Management
 ^^^^^^^^^^^^^^^^
 
@@ -1278,6 +1288,67 @@ Gremlin Server in this configuration should be more efficient when there are mul
 Gremlin Server will only close transactions on the graphs specified by the `aliases`. Keeping this setting `false`,
 will simply have Gremlin Server close transactions on all graphs for every request.
 
+[[considering-state]]
+Considering State
+^^^^^^^^^^^^^^^^^
+
+With REST and any sessionless requests, there is no variable state maintained between requests.  Therefore,
+when <<connecting-via-console,connecting with the console>>, for example, it is not possible to create a variable in
+one command and then expect to access it in the next:
+
+[source,groovy]
+----
+gremlin> :remote connect tinkerpop.server conf/remote.yaml
+==>Connected - localhost/127.0.0.1:8182
+gremlin> :> x = 2
+==>2
+gremlin> :> 2 + x
+No such property: x for class: Script4
+Display stack trace? [yN] n
+----
+
+The same behavior would be seen with REST or when using sessionless requests through one of the Gremlin Server drivers.
+If having this behavior is desireable, then <<considering-sessions,consider sessions>>.
+
+There is an exception to this notion of state not existing between requests and that is globally defined functions.
+All functions created via scripts are global to the server.
+
+[source,groovy]
+----
+gremlin> :> def subtractIt(int x, int y) { x - y }
+==>null
+gremlin> :> subtractIt(8,7)
+==>1
+----
+
+If this behavior is not desirable there are several options.  A first option would be to consider using sessions. Each
+session gets its own `ScriptEngine`, which maintains its own isolated cache of global functions, whereas sessionless
+requests uses a single function cache. A second option would be to define functions as closures:
+
+[source,groovy]
+----
+gremlin> :> multiplyIt = { int x, int y -> x * y }
+==>Script7$_run_closure1@6b24f3ab
+gremlin> :> multiplyIt(7, 8)
+No signature of method: org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.multiplyIt() is applicable for argument types: (java.lang.Integer, java.lang.Integer) values: [7, 8]
+Display stack trace? [yN]
+----
+
+When the function is declared this way, the function is viewed by the `ScriptEngine` as a variable rather than a global
+function and since sessionless requests don't maintain state, the function is forgotten for the next request. A final
+option would be to manage the `ScriptEngine` cache manually:
+
+[source,bourne]
+----
+$ curl -X POST -d "{\"gremlin\":\"def divideIt(int x, int y){ x / y }\",\"bindings\":{\"#jsr223.groovy.engine.keep.globals\":\"phantom\"}}" "http://localhost:8182"
+{"requestId":"97fe1467-a943-45ea-8fd6-9e889a6c9381","status":{"message":"","code":200,"attributes":{}},"result":{"data":[null],"meta":{}}}
+$ curl -X POST -d "{\"gremlin\":\"divideIt(8, 2)\"}" "http://localhost:8182"
+{"message":"Error encountered evaluating script: divideIt(8, 2)"}
+----
+
+In the above REST-based requests, the bindings contain a special parameter that tells the `ScriptEngine` cache to
+immediately forget the script after execution. In this way, the function does not end up being globally available.
+
 [[gremlin-plugins]]
 Gremlin Plugins
 ---------------