当前位置: 首页>>代码示例>>Java>>正文


Java GraphComputer类代码示例

本文整理汇总了Java中org.apache.tinkerpop.gremlin.process.computer.GraphComputer的典型用法代码示例。如果您正苦于以下问题:Java GraphComputer类的具体用法?Java GraphComputer怎么用?Java GraphComputer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GraphComputer类属于org.apache.tinkerpop.gremlin.process.computer包,在下文中一共展示了GraphComputer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validateStatePriorToExecution

import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; //导入依赖的package包/类
protected void validateStatePriorToExecution() {
    // a graph computer can only be executed one time
    if (this.executed)
        throw Exceptions.computerHasAlreadyBeenSubmittedAVertexProgram();
    else
        this.executed = true;
    // it is not possible execute a computer if it has no vertex program nor mapreducers
    if (null == this.vertexProgram && this.mapReducers.isEmpty())
        throw GraphComputer.Exceptions.computerHasNoVertexProgramNorMapReducers();
    // it is possible to run mapreducers without a vertex program
    if (null != this.vertexProgram) {
        GraphComputerHelper.validateProgramOnComputer(this, vertexProgram);
        this.mapReducers.addAll(this.vertexProgram.getMapReducers());
    }
    // if the user didn't set desired persistence/resultgraph, then get from vertex program or else, no persistence
    this.persist = GraphComputerHelper.getPersistState(Optional.ofNullable(this.vertexProgram), Optional.ofNullable(this.persist));
    this.resultGraph = GraphComputerHelper.getResultGraphState(Optional.ofNullable(this.vertexProgram), Optional.ofNullable(this.resultGraph));
    // determine persistence and result graph options
    if (!this.features().supportsResultGraphPersistCombination(this.resultGraph, this.persist))
        throw GraphComputer.Exceptions.resultGraphPersistCombinationNotSupported(this.resultGraph, this.persist);
    // if too many workers are requested, throw appropriate exception
    if (this.workers > this.features().getMaxWorkers())
        throw GraphComputer.Exceptions.computerRequiresMoreWorkersThanSupported(this.workers, this.features().getMaxWorkers());
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:25,代码来源:AbstractHadoopGraphComputer.java

示例2: shouldWriteToArbitraryRDD

import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; //导入依赖的package包/类
@Test
public void shouldWriteToArbitraryRDD() throws Exception {
    final Configuration configuration = new BaseConfiguration();
    configuration.setProperty("spark.master", "local[4]");
    configuration.setProperty("spark.serializer", GryoSerializer.class.getCanonicalName());
    configuration.setProperty(Graph.GRAPH, HadoopGraph.class.getName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, SparkHadoopGraphProvider.PATHS.get("tinkerpop-modern.kryo"));
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, GryoInputFormat.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, ExampleOutputRDD.class.getCanonicalName());
    configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, TestHelper.makeTestDataDirectory(this.getClass(), "shouldWriteToArbitraryRDD"));
    configuration.setProperty(Constants.GREMLIN_HADOOP_JARS_IN_DISTRIBUTED_CACHE, false);
    ////////
    Graph graph = GraphFactory.open(configuration);
    graph.compute(SparkGraphComputer.class)
            .result(GraphComputer.ResultGraph.NEW)
            .persist(GraphComputer.Persist.EDGES)
            .program(TraversalVertexProgram.build()
                    .traversal(graph.traversal().withComputer(Computer.compute(SparkGraphComputer.class)),
                            "gremlin-groovy",
                            "g.V()").create(graph)).submit().get();
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:22,代码来源:OutputRDDTest.java

示例3: withComputer

import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; //导入依赖的package包/类
/**
 * Add a {@link Function} that will generate a {@link GraphComputer} from the {@link Graph} that will be used to execute the traversal.
 * This adds a {@link VertexProgramStrategy} to the strategies.
 *
 * @param computer a builder to generate a graph computer from the graph
 * @return a new traversal source with updated strategies
 */
public default TraversalSource withComputer(final Computer computer) {
    Class<? extends GraphComputer> graphComputerClass;
    try {
        graphComputerClass = computer.apply(this.getGraph()).getClass();
    } catch (final Exception e) {
        graphComputerClass = computer.getGraphComputerClass();
    }
    final List<TraversalStrategy<?>> graphComputerStrategies = TraversalStrategies.GlobalCache.getStrategies(graphComputerClass).toList();
    final TraversalStrategy[] traversalStrategies = new TraversalStrategy[graphComputerStrategies.size() + 1];
    traversalStrategies[0] = new VertexProgramStrategy(computer);
    for (int i = 0; i < graphComputerStrategies.size(); i++) {
        traversalStrategies[i + 1] = graphComputerStrategies.get(i);
    }
    return this.withStrategies(traversalStrategies);
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:23,代码来源:TraversalSource.java

示例4: apply

import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; //导入依赖的package包/类
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if (TraversalHelper.getStepsOfAssignableClass(VertexProgramStep.class, traversal).size() > 1)  // do not do if there is an OLAP chain
        return;
    final Graph graph = traversal.getGraph().orElse(EmptyGraph.instance()); // given that this strategy only works for single OLAP jobs, the graph is the traversal graph
    for (final TraversalVertexProgramStep step : TraversalHelper.getStepsOfClass(TraversalVertexProgramStep.class, traversal)) {   // will be zero or one step
        final Traversal.Admin<?, ?> computerTraversal = step.generateProgram(graph, EmptyMemory.instance()).getTraversal().get().clone();
        if (!computerTraversal.isLocked())
            computerTraversal.applyStrategies();
        final Computer computer = step.getComputer();
        if (null == computer.getEdges() && !GraphComputer.Persist.EDGES.equals(computer.getPersist())) {  // if edges() already set, use it
            final Traversal.Admin<Vertex, Edge> edgeFilter = getEdgeFilter(computerTraversal);
            if (null != edgeFilter)  // if no edges can be filtered, then don't set edges()
                step.setComputer(computer.edges(edgeFilter));
        }
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:18,代码来源:GraphFilterStrategy.java

示例5: validateProgramOnComputer

import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; //导入依赖的package包/类
public static void validateProgramOnComputer(final GraphComputer computer, final VertexProgram vertexProgram) {
    if (vertexProgram.getMemoryComputeKeys().contains(null))
        throw Memory.Exceptions.memoryKeyCanNotBeNull();
    if (vertexProgram.getMemoryComputeKeys().contains(""))
        throw Memory.Exceptions.memoryKeyCanNotBeEmpty();

    final GraphComputer.Features graphComputerFeatures = computer.features();
    final VertexProgram.Features vertexProgramFeatures = vertexProgram.getFeatures();

    for (final Method method : VertexProgram.Features.class.getMethods()) {
        if (method.getName().startsWith("requires")) {
            final boolean supports;
            final boolean requires;
            try {
                supports = (boolean) GraphComputer.Features.class.getMethod(method.getName().replace("requires", "supports")).invoke(graphComputerFeatures);
                requires = (boolean) method.invoke(vertexProgramFeatures);
            } catch (final Exception e) {
                throw new IllegalStateException("A reflection exception has occurred: " + e.getMessage(), e);
            }
            if (requires && !supports)
                throw new IllegalStateException("The vertex program can not be executed on the graph computer: " + method.getName());
        }
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:25,代码来源:GraphComputerHelper.java

示例6: addProperty

import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; //导入依赖的package包/类
public <V> Property<V> addProperty(final TinkerVertex vertex, final String key, final V value) {
    ElementHelper.validateProperty(key, value);
    if (isComputeKey(key)) {
        final TinkerVertexProperty<V> property = new TinkerVertexProperty<V>((TinkerVertex) vertex, key, value) {
            @Override
            public void remove() {
                removeProperty(vertex, key, this);
            }
        };
        this.addValue(vertex, key, property);
        return property;
    } else {
        throw GraphComputer.Exceptions.providedKeyIsNotAnElementComputeKey(key);
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:16,代码来源:TinkerGraphComputerView.java

示例7: removeProperty

import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; //导入依赖的package包/类
public void removeProperty(final TinkerVertex vertex, final String key, final VertexProperty property) {
    if (isComputeKey(key)) {
        this.removeValue(vertex, key, property);
    } else {
        throw GraphComputer.Exceptions.providedKeyIsNotAnElementComputeKey(key);
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:8,代码来源:TinkerGraphComputerView.java

示例8: traversal

import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; //导入依赖的package包/类
@Override
public GraphTraversalSource traversal(final Graph graph) {
    return graph.traversal().withStrategies(VertexProgramStrategy.create(new MapConfiguration(new HashMap<String, Object>() {{
        put(VertexProgramStrategy.WORKERS, RANDOM.nextInt(Runtime.getRuntime().availableProcessors()) + 1);
        put(VertexProgramStrategy.GRAPH_COMPUTER, RANDOM.nextBoolean() ?
                GraphComputer.class.getCanonicalName() :
                TinkerGraphComputer.class.getCanonicalName());
    }})));
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:10,代码来源:TinkerGraphComputerProvider.java

示例9: getGraphComputerClass

import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; //导入依赖的package包/类
/**
 * @return A graph compute supported by this grakn graph
 */
@SuppressWarnings("unchecked")
protected Class<? extends GraphComputer> getGraphComputerClass(String graphComputerType) {
    try {
        return (Class<? extends GraphComputer>) Class.forName(graphComputerType);
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException(ErrorMessage.INVALID_COMPUTER.getMessage(graphComputerType));
    }
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:12,代码来源:GraknComputerImpl.java

示例10: compute

import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; //导入依赖的package包/类
@Override
public <C extends GraphComputer> C compute(final Class<C> graphComputerClass) {
    try {
        if (AbstractHadoopGraphComputer.class.isAssignableFrom(graphComputerClass))
            return graphComputerClass.getConstructor(HadoopGraph.class).newInstance(this);
        else
            throw Graph.Exceptions.graphDoesNotSupportProvidedGraphComputer(graphComputerClass);
    } catch (final Exception e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:12,代码来源:HadoopGraph.java

示例11: getOutputGraph

import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; //导入依赖的package包/类
public static HadoopGraph getOutputGraph(final Configuration configuration, final GraphComputer.ResultGraph resultGraph, final GraphComputer.Persist persist) {
    final HadoopConfiguration hadoopConfiguration = new HadoopConfiguration(configuration);
    final BaseConfiguration newConfiguration = new BaseConfiguration();
    newConfiguration.copy(hadoopConfiguration);
    if (resultGraph.equals(GraphComputer.ResultGraph.NEW)) {
        newConfiguration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, hadoopConfiguration.getOutputLocation());
        if (hadoopConfiguration.containsKey(Constants.GREMLIN_HADOOP_GRAPH_WRITER))
            if (null != InputOutputHelper.getInputFormat(hadoopConfiguration.getGraphWriter()))
                newConfiguration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, InputOutputHelper.getInputFormat(hadoopConfiguration.getGraphWriter()).getCanonicalName());
        newConfiguration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER_HAS_EDGES, persist.equals(GraphComputer.Persist.EDGES));
    }
    newConfiguration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, hadoopConfiguration.getOutputLocation() + "_");
    return HadoopGraph.open(newConfiguration);
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:15,代码来源:InputOutputHelper.java

示例12: shouldPersistRDDBasedOnStorageLevel

import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; //导入依赖的package包/类
@Test
public void shouldPersistRDDBasedOnStorageLevel() throws Exception {
    Spark.create("local[4]");
    int counter = 0;
    for (final String storageLevel : Arrays.asList("MEMORY_ONLY", "DISK_ONLY", "MEMORY_ONLY_SER", "MEMORY_AND_DISK_SER")) {
        assertEquals(counter, Spark.getRDDs().size());
        assertEquals(counter, Spark.getContext().getPersistentRDDs().size());
        counter++;
        final String rddName = TestHelper.makeTestDataDirectory(PersistedInputOutputRDDTest.class, UUID.randomUUID().toString());
        final Configuration configuration = super.getBaseConfiguration();
        configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, SparkHadoopGraphProvider.PATHS.get("tinkerpop-modern.kryo"));
        configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, GryoInputFormat.class.getCanonicalName());
        configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_WRITER, PersistedOutputRDD.class.getCanonicalName());
        configuration.setProperty(Constants.GREMLIN_SPARK_PERSIST_STORAGE_LEVEL, storageLevel);
        configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, rddName);
        configuration.setProperty(Constants.GREMLIN_SPARK_PERSIST_CONTEXT, true);
        Graph graph = GraphFactory.open(configuration);
        graph.compute(SparkGraphComputer.class)
                .result(GraphComputer.ResultGraph.NEW)
                .persist(GraphComputer.Persist.EDGES)
                .program(TraversalVertexProgram.build()
                        .traversal(graph.traversal().withComputer(SparkGraphComputer.class),
                                "gremlin-groovy",
                                "g.V().groupCount('m').by('name').out()").create(graph)).submit().get();
        ////////
        assertTrue(Spark.hasRDD(Constants.getGraphLocation(rddName)));
        assertEquals(StorageLevel.fromString(storageLevel), Spark.getRDD(Constants.getGraphLocation(rddName)).getStorageLevel());
        assertEquals(counter, Spark.getRDDs().size());
        assertEquals(counter, Spark.getContext().getPersistentRDDs().size());
    }
    Spark.close();
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:33,代码来源:PersistedInputOutputRDDTest.java

示例13: addEdge

import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; //导入依赖的package包/类
@Override
public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) {
    if (inVertex.equals(starVertex))
        return starVertex.addInEdge(label, this, keyValues);
    else
        throw GraphComputer.Exceptions.adjacentVertexEdgesAndVerticesCanNotBeReadOrUpdated();
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:8,代码来源:StarGraph.java

示例14: getOutputGraph

import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; //导入依赖的package包/类
public static HadoopGraph getOutputGraph(final Configuration configuration, final GraphComputer.ResultGraph resultGraph, final GraphComputer.Persist persist) {
    final HadoopConfiguration hadoopConfiguration = new HadoopConfiguration(configuration);
    final BaseConfiguration newConfiguration = new BaseConfiguration();
    newConfiguration.copy(org.apache.tinkerpop.gremlin.hadoop.structure.io.InputOutputHelper.getOutputGraph(configuration, resultGraph, persist).configuration());
    if (resultGraph.equals(GraphComputer.ResultGraph.NEW) && hadoopConfiguration.containsKey(Constants.GREMLIN_HADOOP_GRAPH_WRITER)) {
        if (null != InputOutputHelper.getInputFormat(hadoopConfiguration.getGraphWriter()))
            newConfiguration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_READER, InputOutputHelper.getInputFormat(hadoopConfiguration.getGraphWriter()).getCanonicalName());
    }
    return HadoopGraph.open(newConfiguration);
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:11,代码来源:InputOutputHelper.java

示例15: create

import org.apache.tinkerpop.gremlin.process.computer.GraphComputer; //导入依赖的package包/类
/**
 * @deprecated As of release 3.2.0. Please use {@link Graph#traversal(Class)}.
 */
@Deprecated
public ComputerTraversalEngine create(final Graph graph) {
    GraphComputer graphComputer = null == this.graphComputerClass ? graph.compute() : graph.compute(this.graphComputerClass);
    if (-1 != this.workers)
        graphComputer = graphComputer.workers(this.workers);
    if (null != this.vertexFilter)
        graphComputer = graphComputer.vertices(this.vertexFilter);
    if (null != this.edgeFilter)
        graphComputer = graphComputer.edges(this.edgeFilter);
    return new ComputerTraversalEngine(graphComputer);
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:15,代码来源:ComputerTraversalEngine.java


注:本文中的org.apache.tinkerpop.gremlin.process.computer.GraphComputer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。