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/11 15:14:26 UTC
[4/5] incubator-tinkerpop git commit: Improved method for
constructing DriverServerConnection.
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/e19c1d58
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/e19c1d58
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/e19c1d58
Branch: refs/heads/TINKERPOP-575
Commit: e19c1d58381fdfba147335743551a781e2a018be
Parents: 56bccb1
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Mar 11 06:43:59 2016 -0500
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 11 06:43:59 2016 -0500
----------------------------------------------------------------------
.../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/e19c1d58/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/e19c1d58/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 7422fe4..a7ad023 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
@@ -255,7 +255,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/e19c1d58/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;