Accessing titan graph from java

269 views
Skip to first unread message

Alina Arm

unread,
Feb 23, 2015, 9:23:59 AM2/23/15
to gremli...@googlegroups.com

I have a java programm running locally on my machine and Titan+Rexter installation on remote machine

I need my program to be able to access titan graph and read/write/delete from it

I found this approach in the tutorials

  1. RexsterClient client = RexsterClientFactory.open("192.168.30.62");
  2. List<Map<String, Object>> results = client.execute("g.v(1).map");
  3. Map<String, Object> map = results.get(0);
  4. System.out.println(map);
But when I run this code it complains about second line

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$1.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: Script1
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

The same message i get when I run "g.v(1).map" in rexter-console

What am I missing?

Stephen Mallette

unread,
Feb 23, 2015, 11:02:00 AM2/23/15
to gremli...@googlegroups.com
"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.


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/6abfcfbb-cdae-4381-9ef2-c2dabd8ec5fa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alina Arm

unread,
Feb 24, 2015, 4:10:32 AM2/24/15
to gremli...@googlegroups.com
Thanks, it looks better now

        RexsterClient client = RexsterClientFactory.open("192.168.30.62");
        List<Map<String, Object>> results = client.execute("g = rexster.getGraph(\"graph\")");
        //Map<String, Object> map = results.get(0);
        System.out.println("TEST "+results);
        client.close();

 but still throws java.lang.IllegalThreadStateException

[WARNING] Warning: killAfter is now deprecated. Do you need it ? Please comment on MEXEC-6.
TEST [titangraph[cassandra:[127.0.0.1]]]
[WARNING] thread Thread[Grizzly(1) SelectorRunner,5,Titan.Titan.App] was interrupted but is still alive after waiting at least 14999msecs
[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)


понедельник, 23 февраля 2015 г., 17:02:00 UTC+1 пользователь Stephen Mallette написал:

Stephen Mallette

unread,
Feb 25, 2015, 8:26:36 AM2/25/15
to gremli...@googlegroups.com
I don't recognize that stacktrace at all.....but this doesn't look right:

> List<Map<String, Object>> results = client.execute("g = rexster.getGraph(\"graph\")");

that would return "g" which i guess would serialize out via toString under rexpro.  does the client actually print anything under that scenario?  is the error you are showing a server side error or a client side error?

Alina Arm

unread,
Feb 25, 2015, 4:04:55 PM2/25/15
to gremli...@googlegroups.com
Yes, it prints TEST [titangraph[cassandra:[127.0.0.1]]].

It is client side error

среда, 25 февраля 2015 г., 14:26:36 UTC+1 пользователь Stephen Mallette написал:

Stephen Mallette

unread,
Feb 28, 2015, 8:41:55 AM2/28/15
to gremli...@googlegroups.com
Is there any more to your code than what you are supplying?  Your stacktrace includes lines i don't recognize.  Is there any more context you can provide that could help provide some reference?

Reply all
Reply to author
Forward
0 new messages