I don't think it takes much to get this working, but that's easy for
me to say. :) Check out the gremlin-groovy script engine:
https://github.com/tinkerpop/gremlin/tree/master/gremlin-groovy/src/main/java/com/tinkerpop/gremlin/groovy/jsr223
and gremlin-js script engine:
https://github.com/entrendipity/gremlin-js/blob/master/src/main/java/com/entrendipity/gremlin/javascript/jsr223/
At a high level, you simply implement ScriptEngine and
ScriptEngineFactory from the jsr223 spec (gremlin-groovy is a little
different in that the ScriptEngine extends from GroovyScriptEngineImpl
and maps to jsr223 but I think the concept isn't so different). Make
sure that you include this:
https://github.com/tinkerpop/gremlin/blob/master/gremlin-groovy/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory
https://github.com/entrendipity/gremlin-js/blob/master/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory
so that the ServiceLoader can find your ScriptEngineFactory
implementation. For Rexster compatibility, make sure you prefix your
engine name with "gremlin-". In other words, your engine name should
be called "gremlin-scala". Build the jar with maven, copy/paste to
the REXSTER_HOME/ext directory and edit rexster.xml to include
"gremlin-scala" here:
https://github.com/tinkerpop/rexster/blob/master/rexster-server/rexster.xml#L49
basically:
<script-engines>gremlin-groovy,gremlin-scala</script-engines>
Then test by opening Rexster Console and do:
?l
that's a lower-case "L", to list the gremlin languages available. you
should see groovy and scala as languages. you can then switch between
the two with:
?scala
?groovy
what's really cool is that the bindings from either language session
are shared, so when you define "g" in groovy, then switch to scala,
"g" is still available to you. I tried it out with gremlin-js.
here's what my session looked like:
rexster[groovy]> ?javascript
rexster[javascript]> g = rexster.getGraph("tinkergraph")
==>mocktinkertransactionalgraph[vertices:6 edges:6
directory:data/graph-example-1]
rexster[javascript]> d = new
com.entrendipity.gremlin.javascript.GremlinJSPipeline(g)
rexster[javascript]> d.V()
==>v[3]
==>v[2]
==>v[1]
==>v[6]
==>v[5]
==>v[4]
rexster[javascript]> d.V().out().groupCount().cap()
==>{v[3]=3, v[2]=1, v[5]=1, v[4]=1}
rexster[javascript]> ?groovy
rexster[groovy]> g.V.out.groupCount().cap
==>{v[3]=3, v[2]=1, v[5]=1, v[4]=1}
again, gremlin-js is a work in progress and Frank and I were just
testing things out to make sure the concepts were sound. Frank is
looking to cut the verbosity in the language and simplifying a bit,
but at least it shows the idea works.
Please let me know if you have any other questions. Thanks again!
Stephen
On Tue, Feb 12, 2013 at 3:04 AM, Michael Pollmeier