tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [18/50] incubator-tinkerpop git commit: Improved method for constructing DriverServerConnection.
Date Wed, 16 Mar 2016 14:40:00 GMT
Improved method for constructing DriverServerConnection.


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

Branch: refs/heads/TINKERPOP-575
Commit: b4f6c7799f7ff0ed882956f297bf22bd6993ab92
Parents: c76d8e0
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Fri Mar 11 06:43:59 2016 -0500
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Wed Mar 16 09:50:01 2016 -0400

----------------------------------------------------------------------
 .../gremlin/process/server/ServerGraph.java     |  8 ++++
 .../apache/tinkerpop/gremlin/driver/Client.java |  1 -
 .../driver/strategy/DriverServerConnection.java | 49 ++++++++++++++++++--
 3 files changed, 52 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b4f6c779/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/server/ServerGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/server/ServerGraph.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/server/ServerGraph.java
index dfe8ae9..1873e53 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/server/ServerGraph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/server/ServerGraph.java
@@ -26,6 +26,7 @@ import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Transaction;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
 import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
 
 import java.util.Collections;
@@ -50,6 +51,10 @@ public class ServerGraph implements Graph {
                 ServerGraph.class, TraversalStrategies.GlobalCache.getStrategies(EmptyGraph.class).clone().addStrategies(ServerStrategy.instance()));
     }
 
+    /**
+     * Creates a new {@link ServerGraph} instance using the specified configuration, which
allows {@link ServerGraph}
+     * to be compliant with {@link GraphFactory}.
+     */
     public static ServerGraph open(final Configuration conf) {
         return null;
     }
@@ -74,6 +79,9 @@ public class ServerGraph implements Graph {
         return graphClass;
     }
 
+    /**
+     * Closes the underlying {@link ServerConnection}.
+     */
     @Override
     public void close() throws Exception {
         connection.close();

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b4f6c779/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
index b3f0c9f..ac8d5d8 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/Client.java
@@ -312,7 +312,6 @@ public abstract class Client {
 
     /**
      * Gets the {@link Cluster} that spawned this {@code Client}.
-     * @return
      */
     public Cluster getCluster() {
         return cluster;

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b4f6c779/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/strategy/DriverServerConnection.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/strategy/DriverServerConnection.java
b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/strategy/DriverServerConnection.java
index c373e38..e7cab0d 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/strategy/DriverServerConnection.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/strategy/DriverServerConnection.java
@@ -18,36 +18,70 @@
  */
 package org.apache.tinkerpop.gremlin.driver.strategy;
 
+import org.apache.commons.configuration.Configuration;
 import org.apache.tinkerpop.gremlin.driver.Client;
 import org.apache.tinkerpop.gremlin.driver.Cluster;
 import org.apache.tinkerpop.gremlin.driver.Result;
 import org.apache.tinkerpop.gremlin.process.server.ServerConnection;
 import org.apache.tinkerpop.gremlin.process.server.ServerConnectionException;
+import org.apache.tinkerpop.gremlin.process.server.ServerGraph;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
 
 import java.util.Iterator;
 
 /**
+ * A {@link ServerConnection} implementation for Gremlin Server. Each {@code DriverServerConnection}
is bound to one
+ * graph instance hosted in Gremlin Server.
+ *
  * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public class DriverServerConnection implements ServerConnection {
 
     private final Client client;
     private final boolean tryCloseCluster;
+    private final String connectionGraphName;
 
-    private DriverServerConnection(final Cluster cluster, final boolean tryCloseCluster){
-        client = cluster.connect(Client.Settings.build().unrollTraversers(false).create()).alias("graph");
+    private DriverServerConnection(final Cluster cluster, final boolean tryCloseCluster,
final String connectionGraphName){
+        client = cluster.connect(Client.Settings.build().unrollTraversers(false).create()).alias(connectionGraphName);
+        this.connectionGraphName = connectionGraphName;
         this.tryCloseCluster = tryCloseCluster;
     }
 
+    /**
+     * Creates a {@link DriverServerConnection} from an existing {@link Cluster} instance.
When {@link #close()} is
+     * called, the {@link Cluster} is left open for the caller to close. By default, this
method will bind the
+     * {@link ServerConnection} to a graph on the server named "graph".
+     */
     public static DriverServerConnection using(final Cluster cluster) {
-        return new DriverServerConnection(cluster, false);
+        return using(cluster, "graph");
+    }
+
+    /**
+     * Creates a {@link DriverServerConnection} from an existing {@link Cluster} instance.
When {@link #close()} is
+     * called, the {@link Cluster} is left open for the caller to close.
+     */
+    public static DriverServerConnection using(final Cluster cluster, final String connectionGraphName)
{
+        return new DriverServerConnection(cluster, false, connectionGraphName);
+    }
+
+    /**
+     * Creates a {@link DriverServerConnection} using a new {@link Cluster} instance created
from the supplied
+     * configuration file. When {@link #close()} is called, this new {@link Cluster} is also
closed. By default,
+     * this method will bind the {@link ServerConnection} to a graph on the server named
"graph".
+     */
+    public static DriverServerConnection using(final String clusterConfFile) {
+        return using(clusterConfFile, "graph");
     }
 
-    public static DriverServerConnection using(final String conf) {
+    /**
+     * Creates a {@link DriverServerConnection} using a new {@link Cluster} instance created
from the supplied
+     * configuration file. When {@link #close()} is called, this new {@link Cluster} is also
closed.
+     */
+    public static DriverServerConnection using(final String clusterConfFile, final String
connectionGraphName) {
         try {
-            return new DriverServerConnection(Cluster.open(conf), true);
+            return new DriverServerConnection(Cluster.open(clusterConfFile), true, connectionGraphName);
         } catch (Exception ex) {
             throw new IllegalStateException(ex);
         }
@@ -74,6 +108,11 @@ public class DriverServerConnection implements ServerConnection {
         }
     }
 
+    @Override
+    public String toString() {
+        return "DriverServerConnection-" + client.getCluster() + " [graph='" + connectionGraphName
+ "]";
+    }
+
     static class TraverserIterator implements Iterator<Traverser> {
 
         private Iterator<Result> inner;


Mime
View raw message