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/17 21:23:51 UTC

[34/50] incubator-tinkerpop git commit: Provided method to do RemoteGraph without needing the native Graph.

Provided method to do RemoteGraph without needing the native Graph.


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

Branch: refs/heads/TINKERPOP-575
Commit: ee0ff74071ac2c6227350629e23c9d817a3bfefc
Parents: dfc73b7
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Mar 16 11:34:55 2016 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Mar 17 14:07:26 2016 -0400

----------------------------------------------------------------------
 .../gremlin/process/remote/RemoteGraph.java     | 45 ++++++++++++++------
 .../remote/traversal/step/map/RemoteStep.java   |  5 ++-
 .../traversal/strategy/RemoteStrategy.java      |  6 +--
 .../op/traversal/TraversalOpProcessor.java      |  7 +++
 4 files changed, 47 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/ee0ff740/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/RemoteGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/RemoteGraph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/RemoteGraph.java
index d32454e..d1499ba 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/RemoteGraph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/RemoteGraph.java
@@ -32,6 +32,7 @@ import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
 import java.lang.reflect.Constructor;
 import java.util.Collections;
 import java.util.Iterator;
+import java.util.Optional;
 
 /**
  * A {@code ServerGraph} represents a proxy by which traversals spawned from this graph are expected over a
@@ -89,14 +90,19 @@ import java.util.Iterator;
 public class RemoteGraph implements Graph {
 
     private final RemoteConnection connection;
-    private final Class<? extends Graph> graphClass;
+    private final Optional<Class<? extends Graph>> graphClass;
 
     public static final String GREMLIN_SERVERGRAPH_SERVER_CONNECTION_CLASS = "gremlin.servergraph.serverConnectionClass";
     public static final String GREMLIN_SERVERGRAPH_GRAPH_CLASS = "gremlin.servergraph.graphClass";
 
+    private RemoteGraph(final RemoteConnection connection) {
+        this(connection, null);
+    }
+
     private RemoteGraph(final RemoteConnection connection, final Class<? extends Graph> graphClass) {
         this.connection = connection;
-        this.graphClass = graphClass;TraversalStrategies.GlobalCache.registerStrategies(
+        this.graphClass = Optional.ofNullable(graphClass);
+        TraversalStrategies.GlobalCache.registerStrategies(
                 RemoteGraph.class, TraversalStrategies.GlobalCache.getStrategies(EmptyGraph.class).clone().addStrategies(RemoteStrategy.instance()));
     }
 
@@ -108,9 +114,6 @@ public class RemoteGraph implements Graph {
      * without change to the creation of the {@link RemoteConnection} instance.
      */
     public static RemoteGraph open(final Configuration conf) {
-        if (!conf.containsKey(GREMLIN_SERVERGRAPH_GRAPH_CLASS))
-            throw new IllegalArgumentException("Configuration must contain the '" + GREMLIN_SERVERGRAPH_GRAPH_CLASS +"' key");
-
         if (!conf.containsKey(GREMLIN_SERVERGRAPH_SERVER_CONNECTION_CLASS))
             throw new IllegalArgumentException("Configuration must contain the '" + GREMLIN_SERVERGRAPH_SERVER_CONNECTION_CLASS +"' key");
 
@@ -123,14 +126,21 @@ public class RemoteGraph implements Graph {
             throw new IllegalStateException(ex);
         }
 
-        final Class<? extends Graph> graphClazz;
-        try {
-            graphClazz = Class.forName(conf.getString(GREMLIN_SERVERGRAPH_GRAPH_CLASS)).asSubclass(Graph.class);
-        } catch (Exception ex) {
-            throw new IllegalStateException(ex);
+        final RemoteGraph remoteGraph;
+        if (conf.containsKey(GREMLIN_SERVERGRAPH_GRAPH_CLASS)) {
+            final Class<? extends Graph> graphClazz;
+            try {
+                graphClazz = Class.forName(conf.getString(GREMLIN_SERVERGRAPH_GRAPH_CLASS)).asSubclass(Graph.class);
+            } catch (Exception ex) {
+                throw new IllegalStateException(ex);
+            }
+
+            remoteGraph = new RemoteGraph(remoteConnection, graphClazz);
+        } else {
+            remoteGraph = new RemoteGraph(remoteConnection);
         }
 
-        return new RemoteGraph(remoteConnection, graphClazz);
+        return remoteGraph;
     }
 
     /**
@@ -145,11 +155,22 @@ public class RemoteGraph implements Graph {
         return new RemoteGraph(connection, graphClass);
     }
 
+    /**
+     * Creates a new {@link RemoteGraph} instance. {@link RemoteGraph} will attempt to call the
+     * {@link RemoteConnection#close()} method when the {@link #close()} method is called on this class.
+     *
+     * @param connection the {@link RemoteConnection} instance to use
+     * {@link RemoteConnection}
+     */
+    public static RemoteGraph open(final RemoteConnection connection) {
+        return new RemoteGraph(connection);
+    }
+
     public RemoteConnection getConnection() {
         return connection;
     }
 
-    public Class<? extends Graph> getGraphClass() {
+    public Optional<Class<? extends Graph>> getGraphClass() {
         return graphClass;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/ee0ff740/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/step/map/RemoteStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/step/map/RemoteStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/step/map/RemoteStep.java
index 2394b94..1f101d9 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/step/map/RemoteStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/step/map/RemoteStep.java
@@ -26,6 +26,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep;
 import org.apache.tinkerpop.gremlin.process.traversal.util.PureTraversal;
+import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
 
 import java.util.Iterator;
@@ -60,10 +61,12 @@ public class RemoteStep<S,E> extends AbstractStep<S, E> {
         if (null == currentIterator) {
             try {
                 final Traversal.Admin temp = pureTraversal.getPure();
-                temp.setStrategies(TraversalStrategies.GlobalCache.getStrategies(((RemoteGraph) traversal.getGraph().get()).getGraphClass()));
+                temp.setStrategies(this.getTraversal().getStrategies().clone());
                 currentIterator = remoteConnection.submit(temp);
             } catch (RemoteConnectionException sce) {
                 throw new IllegalStateException(sce);
+            } catch (IllegalStateException ex) {
+
             }
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/ee0ff740/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/strategy/RemoteStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/strategy/RemoteStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/strategy/RemoteStrategy.java
index 052b784..6961f05 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/strategy/RemoteStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/strategy/RemoteStrategy.java
@@ -61,14 +61,14 @@ public class RemoteStrategy extends AbstractTraversalStrategy<TraversalStrategy.
             return;
 
         if (!traversal.getGraph().isPresent())
-            throw new IllegalStateException("ServerStrategy expects a ServerGraph instance attached to the Traversal");
+            throw new IllegalStateException("RemoteStrategy expects a RemoteGraph instance attached to the Traversal");
 
         if (!(traversal.getGraph().get() instanceof RemoteGraph))
-            throw new IllegalStateException("ServerStrategy expects a ServerGraph instance attached to the Traversal");
+            throw new IllegalStateException("RemoteStrategy expects a RemoteGraph instance attached to the Traversal");
 
         final RemoteGraph remoteGraph = (RemoteGraph) traversal.getGraph().get();
         if (null == remoteGraph.getConnection())
-            throw new IllegalStateException("ServerStrategy expects ServerGraph instance to have a ServerConnection");
+            throw new IllegalStateException("RemoteStrategy expects RemoteGraph instance to have a RemoteConnection");
 
         final Traversal.Admin<?, ?> serverTraversal = new DefaultTraversal<>();
         TraversalHelper.removeToTraversal(traversal.getStartStep(), EmptyStep.instance(), (Traversal.Admin) serverTraversal);

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/ee0ff740/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/traversal/TraversalOpProcessor.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/traversal/TraversalOpProcessor.java b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/traversal/TraversalOpProcessor.java
index 5d9f23e..8e4bd5e 100644
--- a/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/traversal/TraversalOpProcessor.java
+++ b/gremlin-server/src/main/java/org/apache/tinkerpop/gremlin/server/op/traversal/TraversalOpProcessor.java
@@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
 import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage;
 import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode;
 import org.apache.tinkerpop.gremlin.process.computer.util.VertexProgramHelper;
+import org.apache.tinkerpop.gremlin.process.remote.traversal.strategy.RemoteStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
@@ -42,6 +43,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.TimeoutException;
@@ -140,6 +142,11 @@ public class TraversalOpProcessor extends AbstractOpProcessor {
             final boolean supportsTransactions = graph.features().graph().supportsTransactions();
 
             traversal.asAdmin().setGraph(graph);
+            traversal.asAdmin().getStrategies().removeStrategies(RemoteStrategy.class);
+            final List<TraversalStrategy<?>> strategies = TraversalStrategies.GlobalCache.getStrategies(graph.getClass()).toList();
+            final TraversalStrategy[] arrayOfStrategies = new TraversalStrategy[strategies.size()];
+            strategies.toArray(arrayOfStrategies);
+            traversal.asAdmin().getStrategies().addStrategies(arrayOfStrategies);
 
             context.getGremlinExecutor().getExecutorService().submit(() -> {
                 try {