2

So prior to gremlin java 3.4 I used the following code to connect to a remote graph:

Cluster.Builder builder = Cluster.build();
builder.addContactPoint(GREMLIN_SERVER);
builder.port(GREMLIN_PORT);
builder.serializer(new GryoMessageSerializerV1d0());
cluster = builder.create();
g = EmptyGraph.instance().traversal().withRemote(DriverRemoteConnection.using(cluster, GRAPH_NAME));
return g;

I've updated JanusGraph to version 0.4.0 and tried to use gremlin java 3.4.3 and I see every withRemote method is now deprecated.

The gremlin server is configured to use the JanusGraphManager with the ConfigurationManagementGraph. And at startup it runs the following script:

def globals = [:]


def getGraph() {
    def graphNames =  ConfiguredGraphFactory.getGraphNames();
    def graphMaps = [:];
    for (graphName in graphNames) {
        def g = ConfiguredGraphFactory.open(graphName);
        graphMaps.put(graphName, g.traversal())
    }
    return graphMaps;
}

globals << getGraph()

I can't seem to find the new correct way to get a traversal source from java.

Pistacchio
  • 445
  • 4
  • 15
  • Ran into same issue. Saw this `Graph graph = EmptyGraph.instance();` come up in the top internet searches for [Janusgraph Docs-2.0 Java](https://docs.janusgraph.org/v0.2/connecting/java/). When searches should really be pointing to [Janusgraph Docs-Latest Java](https://docs.janusgraph.org/interactions/connecting/java/) – Zach Apr 26 '23 at 19:38

1 Answers1

1

It's always helpful to review the TinkerPop Upgrade Documentation when you upgrade your graph database dependencies. TinkerPop usually tries to point out deprecation and revised way to do things. In your case, this point here in the upgrade docs is what you need. Specifically, you need to use the new AnonymousTraversalSource rather than EmptyGraph to spawn your GraphTraversalSource:

GraphTraversalSource g = traversal().withRemote('conf/remote-graph.properties');

Note that the javadoc would also have helped point you in this direction.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • You're helpfull as always Stephen. I did indeed look at an upgrade documentation, but not the one you linked. In the one I found the AnonymousTraversalSource wasn't mentioned, thank you for pointing that out. – Pistacchio Aug 16 '19 at 15:22
  • @stephen I'm also having the same problem. Your suggestion helped me move a bit further but now i only have reference to a graphTraversal object. What if i also need the graph object ? – Krittam Kothari Mar 09 '21 at 18:43
  • you cannot access a `Graph` object from a remote traversal remotely. if you need to do that, then you need to send a Gremlin script rather than bytecode, and that's only if your graph database supports that sort of functionality. – stephen mallette Mar 09 '21 at 21:05