I have two question please, if that's alright?
And then in Gremlin Server script folder, generateModern(final TinkerGraph g)
was use as below:
globals << [hook : [
onStartUp: { ctx ->
ctx.logger.info("Loading 'modern' graph data.")
org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory.generateModern(graph)
}
] as LifeCycleHook]
How to I replace this with my own written java functions please, in a way that gremlin server will understand my java functions and read them at runtime? Do I need to compile my functions into a Jar file and put in the Lib folder?
globals << [g: graph.traversal()]
How do I expose the graph object variable ie graph
so that i can use it in my Java program?
Many thanks
If you have your own Java library that you wish to expose in Gremlin Server just package it into a jar and add it to the Gremlin Server classpath. You can do this manually by just copying the jar to the /lib
directory or add it via gremlin-server.sh install
command. If you go with the latter you may consider building GremlinPlugin
class (it's an interface you implement) which will allow you to set up class imports to the Gremlin Server ScriptEngine. You can see an example of such a simple plugin here . With that jar file in place you can then access your library's classes in your scripts.
How do i reference and use the graph object variable in my java program
You can only access "graph" in a script from your Java program. It is not possible to do that with bytecode requests. That said, you should not use the Graph
object at all really except to spawn "g". Other uses are not recommended as the best practice is to only use Gremlin to access your graph and you can only write Gremlin with "g". Using "graph" will definitely limit code portability and bind you to APIs that might change or not be wholly supported by all graphs.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.