org.apache.tinkerpop.gremlin.structure.Graph.close()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中org.apache.tinkerpop.gremlin.structure.Graph.close()方法的一些代码示例,展示了Graph.close()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph.close()方法的具体详情如下:
包路径:org.apache.tinkerpop.gremlin.structure.Graph
类名称:Graph
方法名:close

Graph.close介绍

[英]Closing a Graph is equivalent to "shutdown" and implies that no further operations can be executed on the instance. Users should consult the documentation of the underlying graph database implementation for what this "shutdown" will mean in general and, if supported, how open transactions are handled. It will typically be the end user's responsibility to synchronize the thread that calls close() with other threads that are accessing open transactions. In other words, be sure that all work performed on the Graph instance is complete prior to calling this method.

TinkerPop does not enforce any particular semantics with respect to "shutdown". It is up to the graph provider to decide what this method will do.
[中]关闭一个图相当于“shutdown”,意味着不能在实例上执行进一步的操作。用户应查阅底层图形数据库实现的文档,了解“关闭”的一般含义,以及如何处理打开的事务(如果支持)。最终用户通常负责将调用close()的线程与访问打开事务的其他线程同步。换句话说,在调用此方法之前,请确保在图形实例上执行的所有工作都已完成。
TinkerPop不强制执行与“shutdown”相关的任何特定语义。这取决于图形提供程序来决定此方法将执行的操作。

代码示例

代码示例来源:origin: JanusGraph/janusgraph

/**
 * Removes the graph corresponding to the supplied graphName
 * from the {@link JanusGraphManager} graph reference tracker and
 * returns the corresponding Graph, or null if it doesn't exist.
 *
 * @param graphName Graph
 * @return JanusGraph
 */
public static JanusGraph close(String graphName) throws Exception {
  final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance();
  Preconditions.checkState(jgm != null, JANUS_GRAPH_MANAGER_EXPECTED_STATE_MSG);
  final Graph graph = jgm.removeGraph(graphName);
  if (null != graph) graph.close();
  return (JanusGraph) graph;
}

代码示例来源:origin: JanusGraph/janusgraph

/**
 * Removes {@link Graph} from {@link JanusGraphManager} graph reference tracker, if exists
 * there.
 *
 * @param graph Graph
 */
public static void close(Graph graph) throws Exception {
  final JanusGraphManager jgm = JanusGraphManagerUtility.getInstance();
  if (jgm != null) {
    jgm.removeGraph(((StandardJanusGraph) graph).getGraphName());
  }
  graph.close();
}

代码示例来源:origin: JanusGraph/janusgraph

@Override
public void clear(Graph g, final Configuration configuration) throws Exception {
  if (null != g) {
    while (g instanceof WrappedGraph) g = ((WrappedGraph<? extends Graph>) g).getBaseGraph();
    JanusGraph graph = (JanusGraph) g;
    if (graph.isOpen()) {
      if (g.tx().isOpen()) g.tx().rollback();
      try {
        g.close();
      } catch (IOException | IllegalStateException e) {
        logger.warn("Titan graph may not have closed cleanly", e);
      }
    }
  }
  WriteConfiguration config = new CommonsConfiguration(configuration);
  BasicConfiguration readConfig = new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config,
    BasicConfiguration.Restriction.NONE);
  if (readConfig.has(GraphDatabaseConfiguration.STORAGE_BACKEND)) {
    JanusGraphBaseTest.clearGraph(config);
  }
}

代码示例来源:origin: thinkaurelius/titan

@Override
public void clear(Graph g, final Configuration configuration) throws Exception {
  if (null != g) {
    while (g instanceof WrappedGraph) g = ((WrappedGraph<? extends Graph>) g).getBaseGraph();
    TitanGraph graph = (TitanGraph) g;
    if (graph.isOpen()) {
      if (g.tx().isOpen()) g.tx().rollback();
      g.close();
    }
  }
  WriteConfiguration config = new CommonsConfiguration(configuration);
  BasicConfiguration readConfig = new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE);
  if (readConfig.has(GraphDatabaseConfiguration.STORAGE_BACKEND)) {
    TitanGraphBaseTest.clearGraph(config);
  }
}

代码示例来源:origin: apache/tinkerpop

@Override
public void clear(final Graph graph, final Configuration configuration) throws Exception {
  if (graph != null)
    graph.close();
}

代码示例来源:origin: apache/tinkerpop

/**
 * {@inheritDoc}
 */
public final Graph removeGraph(final String graphName) throws Exception {
  Graph graph = graphs.remove(graphName);
  graph.close();
  return graph;
}

代码示例来源:origin: apache/tinkerpop

logger.debug("Closing Graph instance [{}]", gName);
try {
  serverGremlinExecutor.getGraphManager().getGraph(gName).close();
} catch (Exception ex) {
  logger.warn(String.format("Exception while closing Graph instance [%s]", gName), ex);

代码示例来源:origin: apache/tinkerpop

@Override
public void workerIterationStart(final Memory memory) {
  if (null == graph) {
    graph = GraphFactory.open(configuration.subset(WRITE_GRAPH_CFG_KEY));
    LOGGER.info("Opened Graph instance: {}", graph);
    try {
      listener = new BulkLoadingListener();
      g = graph.traversal().withStrategies(EventStrategy.build().addListener(listener).create());
    } catch (Exception e) {
      try {
        graph.close();
      } catch (Exception e2) {
        LOGGER.warn("Failed to close Graph instance", e2);
      }
      throw e;
    }
  } else {
    LOGGER.warn("Leaked Graph instance: {}", graph);
  }
}

代码示例来源:origin: apache/tinkerpop

graph.close();
LOGGER.info("Closed Graph instance: {}", graph);
graph = null;

代码示例来源:origin: org.apache.tinkerpop/gremlin-test

@Override
public void clear(final Graph graph, final Configuration configuration) throws Exception {
  if (graph != null)
    graph.close();
}

代码示例来源:origin: org.apache.tinkerpop/gremlin-server

/**
 * {@inheritDoc}
 */
public final Graph removeGraph(final String graphName) throws Exception {
  Graph graph = graphs.remove(graphName);
  graph.close();
  return graph;
}

代码示例来源:origin: dstl/baleen

@Override
protected void doDestroy() {
 try {
  g.close();
 } catch (Exception e) {
  LOGGER.warn("An error occurred whilst closing the database", e);
 }
}

代码示例来源:origin: apache/tinkerpop

@Test
@LoadGraphWith(MODERN)
public void shouldUseOneTimeBulkLoader() throws Exception {
  for (int iteration = 1; iteration <= 2; iteration++) {
    final BulkLoaderVertexProgram blvp = BulkLoaderVertexProgram.build()
        .bulkLoader(OneTimeBulkLoader.class)
        .writeGraph(getWriteGraphConfiguration()).create(graph);
    final BulkLoader loader = getBulkLoader(blvp);
    assertTrue(loader instanceof OneTimeBulkLoader);
    graphProvider.getGraphComputer(graph).workers(1).program(blvp).submit().get();
    final Graph result = getWriteGraph();
    assertEquals(6 * iteration, IteratorUtils.count(result.vertices()));
    assertEquals(6 * iteration, IteratorUtils.count(result.edges()));
    result.close();
  }
}

代码示例来源:origin: apache/tinkerpop

@Test
@LoadGraphWith(MODERN)
public void shouldUseOneTimeBulkLoaderWithUserSuppliedIds() throws Exception {
  final BulkLoaderVertexProgram blvp = BulkLoaderVertexProgram.build()
      .bulkLoader(OneTimeBulkLoader.class)
      .userSuppliedIds(true)
      .writeGraph(getWriteGraphConfiguration()).create(graph);
  final BulkLoader loader = getBulkLoader(blvp);
  assertTrue(loader instanceof OneTimeBulkLoader);
  graphProvider.getGraphComputer(graph).workers(1).program(blvp).submit().get();
  final Graph result = getWriteGraph();
  assertEquals(6, IteratorUtils.count(result.vertices()));
  assertEquals(6, IteratorUtils.count(result.edges()));
  result.close();
}

代码示例来源:origin: fr.inria.corese/tinkerpop

@Override
public void finalize() throws Throwable {
  LOGGER.debug("calling close");
  tGraph.close();
  LOGGER.debug("close called");
  super.finalize();
  LOGGER.debug("after finalize");
}

代码示例来源:origin: apache/tinkerpop

@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_PERSISTENCE)
public void shouldPersistDataOnClose() throws Exception {
  final Vertex v = graph.addVertex();
  final Vertex u = graph.addVertex();
  if (graph.features().vertex().properties().supportsStringValues()) {
    v.property(VertexProperty.Cardinality.single, "name", "marko");
    u.property(VertexProperty.Cardinality.single, "name", "pavel");
  }
  final Edge e = v.addEdge(graphProvider.convertLabel("collaborator"), u);
  if (graph.features().edge().properties().supportsStringValues())
    e.property("location", "internet");
  tryCommit(graph, getAssertVertexEdgeCounts(2, 1));
  graph.close();
  final Graph reopenedGraph = graphProvider.standardTestGraph(this.getClass(), name.getMethodName(), null);
  assertVertexEdgeCounts(reopenedGraph, 2, 1);
  if (graph.features().vertex().properties().supportsStringValues()) {
    reopenedGraph.vertices().forEachRemaining(vertex -> {
      assertTrue(vertex.property("name").value().equals("marko") || vertex.property("name").value().equals("pavel"));
    });
  }
  reopenedGraph.edges().forEachRemaining(edge -> {
    assertEquals(graphProvider.convertLabel("collaborator"), edge.label());
    if (graph.features().edge().properties().supportsStringValues())
      assertEquals("internet", edge.property("location").value());
  });
  graphProvider.clear(reopenedGraph, graphProvider.standardGraphConfiguration(this.getClass(), name.getMethodName(), null));
}

代码示例来源:origin: uk.gov.dstl.baleen/baleen-graph

private void doClose() {
  try {
   g.close();
  } catch (Exception e) {
   getMonitor().warn("Error closing graph " + g.configuration(), e);
  } finally {
   g = null;
  }
 }
}

代码示例来源:origin: uk.gov.dstl.baleen/baleen-graph

private void doClose() {
  try {
   g.close();
  } catch (Exception e) {
   getMonitor().warn("Error closing graph " + g.configuration(), e);
  } finally {
   g = null;
  }
 }
}

代码示例来源:origin: fr.inria.corese/rdf-to-graph-neo4j

@Override
public void closeDatabase() throws Exception {
  LOGGER.entering(getClass().getName(), "closeDatabase");
  try {
    g.tx().commit();
    while (g.tx().isOpen()) {
      g.tx().commit();
    }
  } finally {
    g.close();
  }
}

代码示例来源:origin: ai.grakn/grakn-kb

/**
 * Closes the root session this graph stems from. This will automatically rollback any pending transactions.
 */
public void closeSession() {
  try {
    txCache().closeTx(ErrorMessage.SESSION_CLOSED.getMessage(keyspace()));
    getTinkerPopGraph().close();
  } catch (Exception e) {
    throw GraknTxOperationException.closingFailed(this, e);
  }
}

相关文章