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/11/13 15:55:29 UTC

[tinkerpop] 08/17: TINKERPOP-2002 Clean up docs based on AnonymousTraversalSource

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

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

commit ea9e826b0e9bd4ff51b5f4704336c4f0371f71f6
Author: Stephen Mallette <sp...@genoprime.com>
AuthorDate: Fri Nov 9 13:59:31 2018 -0500

    TINKERPOP-2002 Clean up docs based on AnonymousTraversalSource
    
    Lots of the revised docs on 3.4.0 were using the old EmptyGraph style - removed that in favor of the new sytle.
---
 docs/src/dev/provider/index.asciidoc             |  2 +-
 docs/src/reference/gremlin-applications.asciidoc | 25 +++++++---------
 docs/src/reference/gremlin-variants.asciidoc     | 36 +++++++++++++-----------
 docs/src/reference/intro.asciidoc                | 35 ++++++++++++++---------
 4 files changed, 52 insertions(+), 46 deletions(-)

diff --git a/docs/src/dev/provider/index.asciidoc b/docs/src/dev/provider/index.asciidoc
index 06bc962..beb7641 100644
--- a/docs/src/dev/provider/index.asciidoc
+++ b/docs/src/dev/provider/index.asciidoc
@@ -1098,7 +1098,7 @@ To demonstrate consider this example:
 cluster = Cluster.open()
 client = cluster.connect()
 aliased = client.alias("g")
-g = org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph.INSTANCE.traversal()       <1>
+g = org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph.instance().traversal()     <1>
 rs = aliased.submit(g.V().both().barrier().both().barrier()).all().get()                    <2>
 aliased.submit(g.V().both().barrier().both().barrier().count()).all().get().get(0).getInt() <3>
 rs.collect{[value: it.getObject().get(), bulk: it.getObject().bulk()]}                      <4>
diff --git a/docs/src/reference/gremlin-applications.asciidoc b/docs/src/reference/gremlin-applications.asciidoc
index 81add43..ac56fc0 100644
--- a/docs/src/reference/gremlin-applications.asciidoc
+++ b/docs/src/reference/gremlin-applications.asciidoc
@@ -520,7 +520,7 @@ executing.  It is up to the script to properly commit or rollback transactions i
 [[connecting-via-drivers]]
 === Connecting via Drivers
 
-TinkerPop offers drivers for the Gremlin Server websocket subprotocol in a variety of languages:
+TinkerPop offers client-side drivers for the Gremlin Server websocket subprotocol in a variety of languages:
 
 * C#
 * Java
@@ -542,21 +542,19 @@ params.put("name","marko");
 List<Result> list = client.submit("g.V().has('person','name',name).out('knows')", params).all().get();
 
 // bytecode
-Graph graph = EmptyGraph.instance();
-GraphTraversalSource g = graph.traversal().withRemote('conf/remote-graph.properties');
+GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using("localhost",8182,"g"));
 List<Vertex> list = g.V().has("person","name","marko").out("knows").toList();
 ----
 [source,groovy]
 ----
 // script
-cluster = Cluster.open()
-client = cluster.connect()
-list = client.submit("g.V().has('person','name',name).out('knows')", [name: "marko"]).all().get();
+def cluster = Cluster.open()
+def client = cluster.connect()
+def list = client.submit("g.V().has('person','name',name).out('knows')", [name: "marko"]).all().get();
 
 // bytecode
-graph = EmptyGraph.instance()
-g = graph.traversal().withRemote('conf/remote-graph.properties')
-list = g.V().has('person','name','marko').out('knows').toList()
+def g = traversal().withRemote(DriverRemoteConnection.using("localhost",8182,"g"))
+def list = g.V().has('person','name','marko').out('knows').toList()
 ----
 [source,csharp]
 ----
@@ -574,8 +572,7 @@ using (var gremlinClient = new GremlinClient(gremlinServer))
 }
 
 // bytecode
-var graph = new Graph();
-var g = graph.Traversal().WithRemote(new DriverRemoteConnection(new GremlinClient(new GremlinServer("localhost", 8182))));
+var g = Traversal().WithRemote(new DriverRemoteConnection(new GremlinClient(new GremlinServer("localhost", 8182))));
 var list = g.V().Has("person","name","marko").Out("knows").toList();
 ----
 [source,javascript]
@@ -586,8 +583,7 @@ const conn = client.open();
 const list = conn.submit("g.V().has('person','name',name).out('knows')",{name: 'marko'}).then(function (response) { ... });
 
 // bytecode
-const graph = new Graph();
-const g = graph.traversal().withRemote(new DriverRemoteConnection('ws://localhost:8182/gremlin'));
+const g = gtraversal().withRemote(new DriverRemoteConnection('ws://localhost:8182/gremlin'));
 const list = g.V().has("person","name","marko").out("knows").toList();
 ----
 [source,python]
@@ -597,8 +593,7 @@ client = Client('ws://localhost:8182/gremlin', 'g')
 list = client.submit("g.V().has('person','name',name).out('knows')",{'name': 'marko'}).all()
 
 # bytecode
-graph = Graph()
-g = graph.traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
+g = traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
 list = g.V().has("person","name","marko").out("knows").toList()
 ----
 
diff --git a/docs/src/reference/gremlin-variants.asciidoc b/docs/src/reference/gremlin-variants.asciidoc
index 697cdb9..762e223 100644
--- a/docs/src/reference/gremlin-variants.asciidoc
+++ b/docs/src/reference/gremlin-variants.asciidoc
@@ -97,6 +97,7 @@ utilizing Gremlin Java are:
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
 import org.apache.tinkerpop.gremlin.process.traversal.Bindings;
 import org.apache.tinkerpop.gremlin.process.traversal.IO;
+import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
 import static org.apache.tinkerpop.gremlin.process.traversal.Operator.*;
 import static org.apache.tinkerpop.gremlin.process.traversal.Order.*;
 import static org.apache.tinkerpop.gremlin.process.traversal.P.*;
@@ -113,7 +114,8 @@ import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.*;
 === Connecting
 
 The pattern for connecting is described in <<connecting-gremlin,Connecting Gremlin>> and it basically distills down to
-creating a `Graph` instance and then spawning a `GraphTraversalSource`.
+creating a `GraphTraversalSource`. For <<connecting-embedded,embedded>> mode, this involves first creating a `Graph`
+and then spawning the `GraphTraversalSource`:
 
 [source,java]
 ----
@@ -126,13 +128,20 @@ which affect traversal execution. The <<traversal, Traversal>> Section describes
 only suitable with <<connecting-embedded,embedded>> style usage. For remote options however there are some added
 setup and configurations to consider and this section looks to address those.
 
-The most basic way to connect to <<connecting-gremlin-server,Gremlin Server>> or
-<<connecting-rgp,Remote Gremlin Providers>> uses the following two lines of code:
+When connecting to <<connecting-gremlin-server,Gremlin Server>> or <<connecting-rgp,Remote Gremlin Providers>>  it
+is possible to configure the `DriverRemoteConnection` manually as shown in earlier examples where the host and port
+are provided as follows:
 
 [source,java]
 ----
-Graph graph = EmptyGraph.instance();
-GraphTraversalSource g = graph.traversal().withRemote('conf/remote-graph.properties');
+GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using("localhost",8182,"g"));
+----
+
+It is also possible to create it from a configuration. The most basic way to do so involves the following line of code:
+
+[source,java]
+----
+GraphTraversalSource g = traversal().withRemote('conf/remote-graph.properties');
 ----
 
 The `remote-graph.properties` file simply provides connection information to the `GraphTraversalSource` which is used
@@ -162,25 +171,22 @@ the command shown above could be re-written using programmatic construction as f
 [source,java]
 ----
 Cluster cluster = Cluster.open();
-Graph graph = EmptyGraph.instance();
-GraphTraversalSource g = graph.traversal().withRemote(DriverRemoteConnection.using(cluster, "g"));
+GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(cluster, "g"));
 ----
 
 Please consider the following example:
 
 [gremlin-groovy]
 ----
-graph = EmptyGraph.instance()
-g = graph.traversal().withRemote('conf/remote-graph.properties')
+def g = traversal().withRemote('conf/remote-graph.properties')
 g.V().valueMap(true)
 g.close()
 ----
 [source,java]
 ----
-Graph graph = EmptyGraph.instance();
-GraphTraversalSource g = graph.traversal().withRemote("conf/remote-graph.properties");
+GraphTraversalSource g = traversal().withRemote("conf/remote-graph.properties");
 List<Map> list = g.V().valueMap(true);
-g.close()
+g.close();
 ----
 
 Note the call to `close()` above. The call to `withRemote()` internally instantiates a connection via the driver that
@@ -193,8 +199,7 @@ then re-use it.
 [gremlin-groovy]
 ----
 cluster = Cluster.open('conf/remote-objects.yaml')
-graph = EmptyGraph.instance()
-g = graph.traversal().withRemote(DriverRemoteConnection.using(cluster, "g"))
+g = traversal().withRemote(DriverRemoteConnection.using(cluster, "g"))
 g.V().valueMap(true)
 g.close()
 cluster.close()
@@ -271,8 +276,7 @@ MessageSerializer serializer = new GryoMessageSerializerV3d0(kryo);
 Cluster cluster = Cluster.build().
                           serializer(serializer).
                           create();
-Graph graph = EmptyGraph.instance();
-GraphTraversalSource g = graph.traversal().withRemote(DriverRemoteConnection.using(cluster, "g"));
+GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(cluster, "g"));
 ----
 
 The `IoRegistry` tells the serializer what classes from the graph provider to auto-register during serialization.
diff --git a/docs/src/reference/intro.asciidoc b/docs/src/reference/intro.asciidoc
index 40b2226..394ad18 100644
--- a/docs/src/reference/intro.asciidoc
+++ b/docs/src/reference/intro.asciidoc
@@ -365,37 +365,44 @@ multiple methods for clients to interface with it:
 * HTTP for string-based scripts
 
 Users are encouraged to use the bytecode based approach with websockets because it allows them to write Gremlin
-in the language of their choice, which looks quite similar to the <<connecting-embedded, embedded>> approach in style
-and function. As with the embedded approach, the means of connection is based on some form of `Graph` creation
-followed by construction of a `GraphTraversalSource` with some "remote" options that describe the location of the
-Gremlin Server they wish to connect to:
+in the language of their choice, which looks somewhat similar to the <<connecting-embedded, embedded>> approach in that
+there is a need to create a `GraphTraversalSource`. In the embedded approach, the means for that object's creation is
+derived from a `Graph` object which spawns it. In this case, however, the `Graph` instance exists only on the server
+which means that there is no `Graph` instance to create locally. The approach is to instead create a
+`GraphTraversalSource` anonymously with `AnonymousTraversalSource` and then apply some "remote" options that describe
+the location of the Gremlin Server to connect to:
 
 [source,java,tab]
 ----
-Graph graph = EmptyGraph.instance();
-GraphTraversalSource g = graph.traversal().withRemote('conf/remote-graph.properties');
+import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
+
+GraphTraversalSource g = traversal().withRemote('conf/remote-graph.properties');
 ----
 [source,groovy]
 ----
-graph = EmptyGraph.instance()
-g = graph.traversal().withRemote('conf/remote-graph.properties')
+import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
+
+def g = traversal().withRemote('conf/remote-graph.properties')
 ----
 [source,csharp]
 ----
-var graph = new Graph();
-var g = graph.Traversal().WithRemote(
+using static Gremlin.Net.Process.Traversal.AnonymousTraversalSource;
+
+var g = Traversal().WithRemote(
               new DriverRemoteConnection(new GremlinClient(new GremlinServer("localhost", 8182))));
 ----
 [source,javascript]
 ----
-const graph = new Graph();
-const g = graph.traversal().withRemote(
+const traversal = gremlin.process.AnonymousTraversalSource.traversal;
+
+const g = traversal().withRemote(
                 new DriverRemoteConnection('ws://localhost:8182/gremlin'));
 ----
 [source,python]
 ----
-graph = Graph()
-g = graph.traversal().withRemote(
+from gremlin_python.process.anonymous_traversal_source import traversal
+
+g = traversal().withRemote(
           DriverRemoteConnection('ws://localhost:8182/gremlin','g'))
 ----