本文整理汇总了Java中com.thinkaurelius.titan.core.TitanGraph.openManagement方法的典型用法代码示例。如果您正苦于以下问题:Java TitanGraph.openManagement方法的具体用法?Java TitanGraph.openManagement怎么用?Java TitanGraph.openManagement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.thinkaurelius.titan.core.TitanGraph
的用法示例。
在下文中一共展示了TitanGraph.openManagement方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIndexJobFinisher
import com.thinkaurelius.titan.core.TitanGraph; //导入方法依赖的package包/类
public Consumer<ScanMetrics> getIndexJobFinisher(final TitanGraph graph, final SchemaAction action) {
Preconditions.checkArgument((graph != null && action != null) || (graph == null && action == null));
return metrics -> {
try {
if (metrics.get(ScanMetrics.Metric.FAILURE) == 0) {
if (action != null) {
ManagementSystem mgmt = (ManagementSystem) graph.openManagement();
try {
TitanIndex index = retrieve(mgmt);
mgmt.updateIndex(index, action);
} finally {
mgmt.commit();
}
}
LOGGER.info("Index update job successful for [{}]", IndexIdentifier.this.toString());
} else {
LOGGER.error("Index update job unsuccessful for [{}]. Check logs", IndexIdentifier.this.toString());
}
} catch (Throwable e) {
LOGGER.error("Error encountered when updating index after job finished [" + IndexIdentifier.this.toString() + "]: ", e);
}
};
}
示例2: SchemaContainer
import com.thinkaurelius.titan.core.TitanGraph; //导入方法依赖的package包/类
public SchemaContainer(TitanGraph graph) {
vertexLabels = Maps.newHashMap();
relationTypes = Maps.newHashMap();
TitanManagement mgmt = graph.openManagement();
try {
for (VertexLabel vl : mgmt.getVertexLabels()) {
VertexLabelDefinition vld = new VertexLabelDefinition(vl);
vertexLabels.put(vld.getName(),vld);
}
for (EdgeLabel el : mgmt.getRelationTypes(EdgeLabel.class)) {
EdgeLabelDefinition eld = new EdgeLabelDefinition(el);
relationTypes.put(eld.getName(),eld);
}
for (PropertyKey pk : mgmt.getRelationTypes(PropertyKey.class)) {
PropertyKeyDefinition pkd = new PropertyKeyDefinition(pk);
relationTypes.put(pkd.getName(), pkd);
}
} finally {
mgmt.rollback();
}
}
示例3: workerIterationStart
import com.thinkaurelius.titan.core.TitanGraph; //导入方法依赖的package包/类
public void workerIterationStart(TitanGraph graph, Configuration config, ScanMetrics metrics) {
this.graph = (StandardTitanGraph)graph;
Preconditions.checkArgument(config.has(GraphDatabaseConfiguration.JOB_START_TIME),"Invalid configuration for this job. Start time is required.");
this.jobStartTime = Instant.ofEpochMilli(config.get(GraphDatabaseConfiguration.JOB_START_TIME));
if (indexName == null) {
Preconditions.checkArgument(config.has(INDEX_NAME), "Need to configure the name of the index to be repaired");
indexName = config.get(INDEX_NAME);
indexRelationTypeName = config.get(INDEX_RELATION_TYPE);
log.info("Read index information: name={} type={}", indexName, indexRelationTypeName);
}
try {
this.mgmt = (ManagementSystem)graph.openManagement();
if (isGlobalGraphIndex()) {
index = mgmt.getGraphIndex(indexName);
} else {
indexRelationType = mgmt.getRelationType(indexRelationTypeName);
Preconditions.checkArgument(indexRelationType!=null,"Could not find relation type: %s", indexRelationTypeName);
index = mgmt.getRelationIndex(indexRelationType,indexName);
}
Preconditions.checkArgument(index!=null,"Could not find index: %s [%s]",indexName,indexRelationTypeName);
log.info("Found index {}", indexName);
validateIndexStatus();
StandardTransactionBuilder txb = this.graph.buildTransaction();
txb.commitTime(jobStartTime);
writeTx = (StandardTitanTx)txb.start();
} catch (final Exception e) {
if (null != mgmt && mgmt.isOpen())
mgmt.rollback();
if (writeTx!=null && writeTx.isOpen())
writeTx.rollback();
metrics.incrementCustom(FAILED_TX);
throw new TitanException(e.getMessage(), e);
}
}
示例4: main
import com.thinkaurelius.titan.core.TitanGraph; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Configuration conf = new PropertiesConfiguration( getRelativeResourcePath( "titan-cassandra-es.properties" ) );
// start elastic search on startup
Node node = new NodeBuilder().node();
TitanGraph graph = TitanFactory.open(conf);
/* Comment if you do not want to reload the graph every time */
graph.close();
TitanCleanup.clear(graph);
graph = TitanFactory.open(conf);
GraphOfTheGodsFactory.load(graph);
/* graph loaded */
// create own indexes
TitanManagement mgmt = graph.openManagement();
PropertyKey name = mgmt.getPropertyKey("name");
PropertyKey age = mgmt.getPropertyKey("age");
mgmt.buildIndex( "byNameComposite", Vertex.class ).addKey(name).buildCompositeIndex();
// index consisting of multiple properties
mgmt.buildIndex( "byNameAndAgeComposite", Vertex.class ).addKey(name).addKey(age).buildCompositeIndex();
mgmt.commit();
// wait for the index to become available
ManagementSystem.awaitGraphIndexStatus(graph, "byNameComposite").call();
ManagementSystem.awaitGraphIndexStatus(graph, "byNameAndAgeComposite").call();
// create new vertex
Vertex me = graph.addVertex("theOneAndOnly");
me.property( "name", "me" );
me.property( "age", 1 );
graph.tx().commit();
System.out.println("Created the one and only!");
// re index the existing data (not required, just for demo purposes)
mgmt = graph.openManagement();
mgmt.updateIndex( mgmt.getGraphIndex("byNameComposite"), SchemaAction.REINDEX ).get();
mgmt.updateIndex( mgmt.getGraphIndex("byNameAndAgeComposite"), SchemaAction.REINDEX ).get();
mgmt.commit();
GraphTraversalSource g = graph.traversal();
GremlinPipeline<GraphTraversal<?, ?>, ?> pipe = new GremlinPipeline();
// read our new vertex
pipe.start( g.V().has( "name", "me" ) );
Vertex v = (Vertex)pipe.next();
System.out.println();
System.out.println( "Label: " + v.label() );
System.out.println( "Name: " + v.property("name").value() );
System.out.println( "Age: " + v.property("age").value() );
System.out.println();
// read different vertex
pipe.start( g.V().has( "name", "hercules" ) );
Vertex herclues = (Vertex)pipe.next();
System.out.println( "Label: " + herclues.label() );
System.out.println( "Name: " + herclues.property("name").value() );
System.out.println( "Age: " + herclues.property("age").value() );
// print some edges
Iterator<Edge> it = herclues.edges( Direction.OUT );
while( it.hasNext() ) {
Edge e = it.next();
System.out.println( "Out: " + e.label() + " --> " + e.inVertex().property("name").value() );
}
System.out.println();
// close graph
graph.close();
// close elastic search on shutdown
node.close();
System.exit(0);
}
示例5: setAndCheckGraphOption
import com.thinkaurelius.titan.core.TitanGraph; //导入方法依赖的package包/类
private <T> void setAndCheckGraphOption(ConfigOption<T> opt, ConfigOption.Type requiredType, T firstValue, T secondValue) {
// Sanity check: make sure the Type of the configoption is what we expect
Preconditions.checkState(opt.getType().equals(requiredType));
final EnumSet<ConfigOption.Type> allowedTypes =
EnumSet.of(ConfigOption.Type.GLOBAL,
ConfigOption.Type.GLOBAL_OFFLINE,
ConfigOption.Type.MASKABLE);
Preconditions.checkState(allowedTypes.contains(opt.getType()));
// Sanity check: it's kind of pointless for the first and second values to be identical
Preconditions.checkArgument(!firstValue.equals(secondValue));
// Get full string path of config option
final String path = ConfigElement.getPath(opt);
// Set and check initial value before and after database restart
mgmt.set(path, firstValue);
assertEquals(firstValue.toString(), mgmt.get(path));
// Close open tx first. This is specific to BDB + GLOBAL_OFFLINE.
// Basically: the BDB store manager throws a fit if shutdown is called
// with one or more transactions still open, and GLOBAL_OFFLINE calls
// shutdown on our behalf when we commit this change.
tx.rollback();
mgmt.commit();
clopen();
// Close tx again following clopen
tx.rollback();
assertEquals(firstValue.toString(), mgmt.get(path));
// Set and check updated value before and after database restart
mgmt.set(path, secondValue);
assertEquals(secondValue.toString(), mgmt.get(path));
mgmt.commit();
clopen();
tx.rollback();
assertEquals(secondValue.toString(), mgmt.get(path));
// Open a separate graph "g2"
TitanGraph g2 = TitanFactory.open(config);
TitanManagement m2 = g2.openManagement();
assertEquals(secondValue.toString(), m2.get(path));
// GLOBAL_OFFLINE options should be unmodifiable with g2 open
if (opt.getType().equals(ConfigOption.Type.GLOBAL_OFFLINE)) {
try {
mgmt.set(path, firstValue);
mgmt.commit();
fail("Option " + path + " with type " + ConfigOption.Type.GLOBAL_OFFLINE + " should not be modifiable with concurrent instances");
} catch (RuntimeException e) {
log.debug("Caught expected exception", e);
}
assertEquals(secondValue.toString(), mgmt.get(path));
// GLOBAL and MASKABLE should be modifiable even with g2 open
} else {
mgmt.set(path, firstValue);
assertEquals(firstValue.toString(), mgmt.get(path));
mgmt.commit();
clopen();
assertEquals(firstValue.toString(), mgmt.get(path));
}
m2.rollback();
g2.close();
}