You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by Stephen Mallette <sp...@gmail.com> on 2015/06/09 15:21:29 UTC

Gremlin Server - rebindings

It was brought to my attention that with Rexster you could do this:

RexsterClient client = RexsterClientFactory.open("localhost",
"tinkergraph");
List<Map<String, Object>> results = client.execute("g.v(1).map");

Specifically, you could specify the graph name on open() (in this case,
"tinkergraph") and it would bind that server-side global Graph variable to
"g".

I didn't think we needed that capability with Gremlin Server because
Gremlin Server binds all Graph and TraversalSource instances globally given
the names that you configure them with.  Of course, the downside there is
that you can't always use a nice "g" for the context of your script so now
you're stuck coupling a client side script to some naming configuration
that you have in Gremlin Server.

I've therefore brought back that capability that existed with Rexster
through the new "rebindings" argument in the protocol.  It is completely
optional, so none of the drivers out there should break over this change.
With "rebindings" you send a Map where a value represents some global
binding on the server and the key is name you want to alias it to.

So if you had two TraversalSource instances configured in Gremlin Server
named g1 and g2, you would either do:

def cluster = Cluster.open()
def client = cluster.connect()
client.submit("g1.V()")
client.submit("g2.V()")

or you can do:

def cluster = Cluster.open()
def client = cluster.connect()
def g1Client = client.rebind("g1")
def g2Client = client.rebind("g2")
g1Client.submit("g.V()")
g2Client.submit("g.V()")

Calls to rebind() do not create tons of new resources and re-use existing
ones from the Client they spawn from and are therefore cheap to
create/destroy.  It should be noted that this feature only works with
sessionless requests (doesn't seem to make sense for in-session requests
where the bindings are all tied to the session anyway).

A sessionless request is the nature of the REST API so that too supports
rebinding arguments.

http://localhost:8182?gremlin=g1.V()&rebindings.g1=g

To be consistent, GET based calls with bindings change slightly in relation
to this so that you would do:

http://localhost:8182?gremlin=g1.V(x).count()-y&rebindings.g1=g&bindings.x=1&bindings.y=2

the change being that parameters need to be prefixed with "bindings." to be
recognized now. It was better to stuff these into their own namespace as it
prevented collisions with other arguments on the query string.  POST didn't
have to change - the JSON object you send in just takes a "rebindings" key
which has a value of a Map of the rebindings.

This feature will be available in the GA release.  Hope folks find this
useful - Enjoy!

Stephen