【JanusGraph】第九章:ConfiguredGraphFactory

这个概念比较难以理解。

ConfiguredGraphFactory是一个singleton,和JanusGraphFactory一样。

它们提供了一套API(methods,方法)来动态地操作服务器上的图。

在gremlin-console下我们可以直接用这个接口去操作图,如下:

gremlin> :remote connect tinkerpop.server conf/remote.yaml
==>Configured localhost/127.0.0.1:8182
gremlin> :remote console
==>All scripts will now be sent to Gremlin Server - [localhost/127.0.0.1:8182] - type ':remote console' to return to local mode
gremlin> ConfiguredGraphFactory.open("graph1")
==>standardjanusgraph[cassandrathrift:[127.0.0.1]]
gremlin> graph1
==>standardjanusgraph[cassandrathrift:[127.0.0.1]]
gremlin> graph1_traversal
==>graphtraversalsource[standardjanusgraph[cassandrathrift:[127.0.0.1]], standard]

先来谈一谈 JanusGraphFactory,它是我们在gremlin-console里面操作一个图的时候的entry-point,每当我们访问一个图的时候,系统就为我们创建了一个Configuration类的实例。

可以将这个东西和spark-shell里面的sparkSession做类比来方便理解。

ConfiguredGraphFactory不太一样,它也是我们访问、操作一个图的时候的entry-point,但配置是通过另一个singleton来实现的,叫ConfigurationManagementGraph。

ConfigurationManagementGraph 使我们可以很方便地管理图的配置。

就像上面例子一样,我们可以通过下面两种方法来访问一个图:

ConfiguredGraphFactory.create("graphName") 

或者

ConfiguredGraphFactory.open("graphName")

可以通过下面的方法来罗列所有配置好了的图。配置好是指之前有用ConfigurationManagementGraph的API配置过:

ConfiguredGraphFactory.getGraphNames()

用下面的放来来drop一个graph database:

ConfiguredGraphFactory.drop("graphName")

如果想使用ConfiguredGraphFactory这个接口,比如在启动前JanusGraph server前配置好。修改gremlin-server.yaml文件,在graphs这个section下面,添加一行:

graphs: {
  ConfigurationManagementGraph: conf/JanusGraph-configurationmanagement.properties
}

在这个例子中,ConfigurationManagementGraph这个graph便是使用位于onf/JanusGraph-configurationmanagement.properties下的配置文件来配置,下面是配置文件的一个例子:

gremlin.graph=org.janusgraph.core.JanusGraphFactory
storage.backend=cql
graph.graphname=ConfigurationManagementGraph
storage.hostname=127.0.0.1

具体ConfigurationManagementGraph怎么用呢?下面是一个例子(在gremlin-console下):

map = new HashMap();
map.put("storage.backend", "cql");
map.put("storage.hostname", "127.0.0.1");
map.put("graph.graphname", "graph1");
ConfiguredGraphFactory.createConfiguration(new MapConfiguration(map));

// then access the graph
ConfiguredGraphFactory.open("graph1");

graph.graphname这个属性指定了上述配置是针对哪张graph的。

你可能感兴趣的:(图数据库)