Programmatically add global variables to gremlin server

强颜欢笑 提交于 2019-12-11 06:01:19

问题


How do I add global variables to an embedded Gremlin server instance?

Also, I want to avoid loading the server configuration from a file, although I can load resources from the classpath.


回答1:


getGlobalBindings() on GremlinExecutor is indeed deprecated, but the javadoc explains how you should proceed:

replaced by getScriptEngineManager() to add global scoped bindings directly to that object.

That comes from the 3.2.5 javadoc when it was originally deprecated in preparation for pretty large changes in 3.3.0 when new interfaces were implement to better generalize the GremlinScriptEngine. While these new interfaces were defined for default use in 3.3.0, they are actually present in 3.2.x and may be used there. Note that the getGlobalBindings() method was actually removed completely in 3.3.0 so when you upgrade you will end up with compilation errors.

Where there may be some confusion with respect to that javadoc comment is that to use the getScriptEngineManager() you must also use what is the default 3.3.0 yaml configuration on the 3.2.x line of code...an example is shown here:

https://github.com/apache/tinkerpop/blob/3.3.0/gremlin-server/conf/gremlin-server-classic.yaml#L25

Note that under this new model, you have two other options for adding global bindings...you could also either:

  1. Use the BindingsGremlinPlugin to add global bindings programmatically
  2. Write your own GremlinPlugin instance to add your bindings



回答2:


Looks like we can do it this way, although getGlobalBindings() is deprecated.

    Graph graph = this.createGraph();
    GraphTraversalSource g = graph.traversal();

    this.server = new GremlinServer(getSettings());
    this.server.getServerGremlinExecutor().getGraphManager().putGraph("graph", graph);
    this.server.getServerGremlinExecutor().getGremlinExecutor().getGlobalBindings().put("graph", graph);
    this.server.getServerGremlinExecutor().getGremlinExecutor().getGlobalBindings().put("g", g);

    this.server.start();


来源:https://stackoverflow.com/questions/48726681/programmatically-add-global-variables-to-gremlin-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!