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 2015/07/27 19:08:45 UTC

incubator-tinkerpop git commit: Update docs for new method of handling global bindings in init scripts.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/tp30 97a9d00a8 -> a05a4443a


Update docs for new method of handling global bindings in init scripts.


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

Branch: refs/heads/tp30
Commit: a05a4443a7198cf6293c553f55ec7d0310798b2f
Parents: 97a9d00
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Jul 27 13:08:16 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Jul 27 13:08:16 2015 -0400

----------------------------------------------------------------------
 docs/src/gremlin-applications.asciidoc        | 4 +++-
 gremlin-server/scripts/generate-modern.groovy | 8 ++++----
 2 files changed, 7 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a05a4443/docs/src/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/gremlin-applications.asciidoc b/docs/src/gremlin-applications.asciidoc
index c4de1b0..c4ea18e 100644
--- a/docs/src/gremlin-applications.asciidoc
+++ b/docs/src/gremlin-applications.asciidoc
@@ -245,7 +245,9 @@ The log messages that printed above show a number of things, but most importantl
 include::{basedir}/gremlin-server/scripts/generate-modern.groovy[]
 ----
 
-There are two important aspects to the above script.  First, it defines a `LifeCycleHook` for Gremlin Server.  The "hook" provides a way to tie script code into the Gremlin Server startup and shutdown sequences.  The `LifeCycleHook` has two methods that can be implemented `onStartUp` and `onShutDown`.  These events are called once at Gremlin Server start and once at Gremlin Server stop.  Code outside of the "hook" is executed for each `ScriptEngine` creation (multiple may be created when "sessions" are enabled). In this case, the startup hook loads the "modern" graph into the empty TinkerGraph instance, preparing it for use.  Outside of the "hook", the script then creates a `TraversalSource` variable `g` from `graph`. This variable `g` will be made available on future remote script executions. Note that `Graph` and `TraversalSource` objects that are created or modified in the initialization script will become globally bound to the server. It is not possible to bind variables of othe
 r types. Any functions that are defined will be cached for future use.
+The script above initializes a `Map` and assigns two key/values to it.  The first, assigned to "hook", defines a `LifeCycleHook` for Gremlin Server.  The "hook" provides a way to tie script code into the Gremlin Server startup and shutdown sequences.  The `LifeCycleHook` has two methods that can be implemented: `onStartUp` and `onShutDown`.  These events are called once at Gremlin Server start and once at Gremlin Server stop.  This is an important point because code outside of the "hook" is executed for each `ScriptEngine` creation (multiple may be created when "sessions" are enabled) and therefore the `LifeCycleHook` provides a way to ensure that a script is only executed a single time. In this case, the startup hook loads the "modern" graph into the empty TinkerGraph instance, preparing it for use.  The second key/value pair assigned to the `Map`, named "g", defines a `TraversalSource` from the `Graph` bound to the "graph" variable in the YAML configuration file.  This variable `g
 `, as well as any other variable assigned to the `Map`, will be made available as variables for future remote script executions.  In more general terms, any key/value pairs assigned to a `Map` returned from the init script will become variables that are global to all requests. In addition, any functions that are defined will be cached for future use.
+
+IMPORTANT: The approach to global bindings described above was introduced with 3.0.1.  In 3.0.0, initialization scripts that simply created `Graph` and/or `TraversalSource` objects became globally bound to the server and it was not possible to bind variables of other types. This less flexible feature is expected to be removed from Gremlin Server in 3.1.0 but remains present in the 3.0.x line of releases for backward compatibility with existing scripts.
 
 With Gremlin Server running it is now possible to issue some scripts to it for processing.  Start Gremlin Console as follows:
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a05a4443/gremlin-server/scripts/generate-modern.groovy
----------------------------------------------------------------------
diff --git a/gremlin-server/scripts/generate-modern.groovy b/gremlin-server/scripts/generate-modern.groovy
index d0f5489..8f39860 100644
--- a/gremlin-server/scripts/generate-modern.groovy
+++ b/gremlin-server/scripts/generate-modern.groovy
@@ -23,10 +23,10 @@ def globals = [:]
 // Generates the modern graph into an "empty" TinkerGraph via LifeCycleHook.
 // Note that the name of the key in the "global" map is unimportant.
 globals << [hook : [
-        onStartUp: { ctx ->
-          ctx.logger.info("Loading 'modern' graph data.")
-          TinkerFactory.generateClassic(graph)
-        }
+  onStartUp: { ctx ->
+    ctx.logger.info("Loading 'modern' graph data.")
+    TinkerFactory.generateClassic(graph)
+  }
 ] as LifeCycleHook]
 
 // define the default TraversalSource to bind queries to - this one will be named "g".