Skip to content
Zack Maril edited this page Dec 5, 2012 · 9 revisions

To begin working with Titan and Hermes, a graph has to first be opened. Hermes stores references to each graph you open and uses it throughout the library in other namespaces. Normally, you will only ever think about opening a graph when the process first starts up.

In memory

To open a graph in memory, use hermes.core/open. This will create a new instance of a TitanInMemoryBlueprintsGraph that can then be operated on. The graph can be operated on without needing to have each action wrapped in a transaction. Note that this graph and any objects created within will cease to exist as soon as the Clojure process ends.

Persistent graphs

To open a graph that is backed by a database, you must supply a map of options to the open function. This opens a simple graph that depends on hbase running locally:

(hermes.core/open 
    {:storage {:backend "hbase"
               :hostname "127.0.0.1"}})

To open a graph on cassandra running on ec2:

(hermes.core/open 
    {:storage {:backend "cassandra"
               :hostname "ec2-314-159-265-35.compute-1.amazonaws.com"}})

And Hermes should just work after that. To understand how to configure the database further, realize that all open is doing to the map is creating a configuration object and (pseudo) recursively adding properties to that object. Hermes does not supply any extra options. To see a list of all possible options for open, checkout the titan documentaion for configuring each database.

So, for example

(hermes.core/open
    {:storage {:backend "cassandra"
               :hostname "localhost"
               :port 8102
               :replication 3}
     :buffer-size 1024
     :persist-attempts 3
     :attributes {:allow-all true}})

Does something akin to the following:

conf = new BaseConfiguration()

conf.setProperty("storage.backend","cassandra")
conf.setProperty("storage.hostname","localhost")
conf.setProperty("storage.port","8102")
conf.setProperty("storage.replicaton","3")
conf.setProperty("buffer-size",1024)
conf.setProperty("persist-attempts",3)
conf.setProperty("attributes.allow-all",true)

g = TitanFactory.open(conf)

Operating on multiple graphs at once

In the odd case you might need to work with multiple graphs easily, check out hermes.core/with-graph. We store whichever graph you are using inside of a dyanmic var, hermes.core/*graph*. with-graph binds that var to be whichever graph you want it to be and then executes the code inside with that in mind. Check out test-with-graph for an example.