使用 java 远程连接到 rexter

Connect remotely to rexter with java

我正在尝试从本地计算机上的 java 应用程序 运行 连接到 titan 数据库。我的 Titan+Cassandra+Rexter 安装在远程机器上 运行。

我正在尝试这样做

    RexsterClient client = RexsterClientFactory.open("192.168.30.62");
    List<Map<String, Object>> results = client.execute("g.v(1).map");
    Map<String, Object> map = results.get(0);
    System.out.println(map);

但它抛出了这个异常

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.mojo.exec.ExecJavaMojo.run(ExecJavaMojo.java:293)
    at java.lang.Thread.run(Thread.java:744)
Caused by: com.tinkerpop.rexster.client.RexProException: An error occurred while processing the script for language [groovy]. All transactions across all graphs in the session have been concluded with failure: javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: g for class: Script4
    at com.tinkerpop.rexster.client.RexsterClient.execute(RexsterClient.java:220)
    at com.tinkerpop.rexster.client.RexsterClient.execute(RexsterClient.java:148)
    at Titan.Titan.App.main(App.java:27)
    ... 6 more
[WARNING] thread Thread[Grizzly(1) SelectorRunner,5,Titan.Titan.App] was interrupted but is still alive after waiting at least 14993msecs
[WARNING] thread Thread[Grizzly(1) SelectorRunner,5,Titan.Titan.App] will linger despite being asked to die via interruption
[WARNING] thread Thread[Grizzly(2) SelectorRunner,5,Titan.Titan.App] will linger despite being asked to die via interruption
[WARNING] thread Thread[Grizzly(3) SelectorRunner,5,Titan.Titan.App] will linger despite being asked to die via interruption
[WARNING] thread Thread[Grizzly(4) SelectorRunner,5,Titan.Titan.App] will linger despite being asked to die via interruption
[WARNING] thread Thread[Grizzly(1),5,Titan.Titan.App] will linger despite being asked to die via interruption
[WARNING] NOTE: 5 thread(s) did not finish despite being asked to  via interruption. This is not a problem with exec:java, it is a problem with the running code. Although not serious, it should be remedied.
[WARNING] Couldn't destroy threadgroup org.codehaus.mojo.exec.ExecJavaMojo$IsolatedThreadGroup[name=Titan.Titan.App,maxpri=10]
java.lang.IllegalThreadStateException
    at java.lang.ThreadGroup.destroy(ThreadGroup.java:775)
    at org.codehaus.mojo.exec.ExecJavaMojo.execute(ExecJavaMojo.java:328)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

此外,当我尝试在 rexter 控制台中使用 Grimlin 时,它会抛出

An error occurred while processing the script for language [groovy]. All transactions across all graphs in the session have been concluded with failure: java.util.concurrent.ExecutionException: javax.script.ScriptException: javax.script.ScriptExcepion" groovy.lang.MissingpropertyException: No such property: g for class: Script1

我做错了什么?

摘自我在 Gremlin 用户邮件列表中针对此问题的 answer

"g" needs to be bound as a variable in the script engine somehow:

List<Map<String, Object>> results =
client.execute("g=rexster.getGraph(\"tinkergraph\");g.v(1).map");
Map<String, Object> map = results.get(0);
System.out.println(map.get("name"));

You can bind the graph automatically to "g" by passing an additional argument to the RexsterClientFactory:

RexsterClient client = RexsterClientFactory.open("localhost","my-titan-graph")

where in the above case, "g" will be bound to the graph named "my-titan-graph" in rexster.xml.