Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies#getStrategy()

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies#getStrategy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VertexProgramStrategy.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
public static Optional<Computer> getComputer(final TraversalStrategies strategies) {
    final Optional<VertexProgramStrategy> optional = strategies.getStrategy(VertexProgramStrategy.class);
    return optional.isPresent() ? Optional.of(optional.get().computer) : Optional.empty();
}
 
Example 2
Source File: GraphContextImpl.java    From windup with Eclipse Public License 1.0 4 votes vote down vote up
private JanusGraph initializeJanusGraph(boolean createMode, boolean enableListeners)
{
    LOG.fine("Initializing graph.");

    Path lucene = graphDir.resolve("graphsearch");
    Path berkeley = graphDir.resolve("titangraph");

    // TODO: Externalize this.
    conf = new BaseConfiguration();

    // Sets a unique id in order to fix WINDUP-697. This causes Titan to not attempt to generate and ID,
    // as the Titan id generation code fails on machines with broken network configurations.
    conf.setProperty("graph.unique-instance-id", "windup_" + System.nanoTime() + "_" + RandomStringUtils.randomAlphabetic(6));
    conf.setProperty("storage.directory", berkeley.toAbsolutePath().toString());
    conf.setProperty("storage.backend", "berkeleyje");

    // Sets the berkeley cache to a relatively small value to reduce the memory footprint.
    // This is actually more important than performance on some of the smaller machines out there, and
    // the performance decrease seems to be minimal.
    conf.setProperty("storage.berkeleydb.cache-percentage", 1);

    // Set READ UNCOMMITTED to improve performance
    conf.setProperty("storage.berkeleydb.lock-mode", LockMode.READ_UNCOMMITTED);
    conf.setProperty("storage.berkeleydb.isolation-level", BerkeleyJEStoreManager.IsolationLevel.READ_UNCOMMITTED);

    // Increase storage write buffer since we basically do a large bulk load during the first phases.
    // See http://s3.thinkaurelius.com/docs/titan/current/bulk-loading.html
    conf.setProperty("storage.buffer-size", "4096");

    // Turn off transactions to improve performance
    conf.setProperty("storage.transactions", false);

    conf.setProperty("ids.block-size", 25000);
    // conf.setProperty("ids.flush", true);
    // conf.setProperty("", false);

    //
    // turn on a db-cache that persists across txn boundaries, but make it relatively small
    conf.setProperty("cache.db-cache", true);
    conf.setProperty("cache.db-cache-clean-wait", 0);
    conf.setProperty("cache.db-cache-size", .09);
    conf.setProperty("cache.db-cache-time", 0);

    conf.setProperty("index.search.backend", "lucene");
    conf.setProperty("index.search.directory", lucene.toAbsolutePath().toString());

    writeToPropertiesFile(conf, graphDir.resolve("TitanConfiguration.properties").toFile());
    JanusGraph janusGraph = JanusGraphFactory.open(conf);

    /*
     * We only need to setup the eventing system when initializing a graph, not when loading it later for
     * reporting.
     */
    if (enableListeners)
    {
        TraversalStrategies graphStrategies = TraversalStrategies.GlobalCache
                .getStrategies(StandardJanusGraph.class)
                .clone();

        // Remove any old listeners
        if (graphStrategies.getStrategy(EventStrategy.class) != null)
            graphStrategies.removeStrategies(EventStrategy.class);

        graphStrategies.addStrategies(EventStrategy.build().addListener(mutationListener).create());
        TraversalStrategies.GlobalCache.registerStrategies(StandardJanusGraph.class, graphStrategies);
        mutationListener.setGraph(this);
    }
    return janusGraph;
}